🪙 Decodes a Base58 string using the Bitcoin alphabet.

Warning

Base58 is case-sensitive, and 0, O, I and l are not part of the alphabet, so they are rejected rather than silently corrected to their look-alikes.

Syntax

TypeScript
import { decodeBase58 } from '@opentf/std';

decodeBase58(str: string): Uint8Array;

Parameters

NameTypeDescription
strstringThe Base58 string to decode.

Returns

The decoded bytes as a Uint8Array.

Throws if the string holds a character outside the alphabet.

Examples

TypeScript
decodeBase58('9Ajdvzr')         //=> Uint8Array [72, 101, 108, 108, 111]
bytesToString(decodeBase58('StV1DL6CwTryKyV')) //=> 'hello world'

Leading 1s decode back to leading zero bytes:

TypeScript
decodeBase58('112') //=> Uint8Array [0, 0, 1]
Last updated on
Edit this page