🪙 Encodes bytes to a Base58 string using the Bitcoin alphabet.
Info
Base58 drops the characters that are easy to confuse when read or typed by a human (0, O, I and l) and uses no punctuation, so the result survives double-click selection and goes into URLs unescaped. It is the encoding behind Bitcoin and Solana addresses, IPFS CIDv0 hashes and short public identifiers.
Syntax
TypeScript
import { encodeBase58 } from '@opentf/std'; encodeBase58(bytes: Uint8Array | ArrayBuffer): string;
Parameters
| Name | Type | Description |
|---|---|---|
| bytes | Uint8Array | ArrayBuffer | The bytes to encode. |
Returns
The Base58 string.
Unlike Base64, Base58 is a whole-number base conversion rather than a bit regrouping, so it has no fixed block size and no padding. Leading zero bytes carry no numeric weight, so they are preserved separately as leading 1s.
Examples
TypeScript
encodeBase58(new Uint8Array([72, 101, 108, 108, 111])) //=> '9Ajdvzr' encodeBase58(stringToBytes('hello world')) //=> 'StV1DL6CwTryKyV'
Leading zero bytes become leading 1s:
TypeScript
encodeBase58(new Uint8Array([0, 0, 1])) //=> '112'
A random 32-byte public identifier:
TypeScript
encodeBase58(randomBytes(32)) //=> '6dRUYs1PkJmpM6bLYLvSCEyKk1zqPr...'