DEV Community

opensource-crypto
opensource-crypto

Posted on

How to Encode and Decode Base58 in TypeScript (Zero Dependencies)

Base58 is everywhere in crypto — Solana addresses, Bitcoin wallets, IPFS CIDs. Here's how to work with it in TypeScript without pulling in a dependency tree.

Why Base58?

Base58 is like Base64 but without characters that look similar: no 0, O, I, or l. This makes it perfect for addresses and keys that humans need to read or type.

Quick Start

npm install base58-core

import { encode, decode } from 'base58-core';

const encoded = encode(new Uint8Array([72, 101, 108, 108, 111]));
console.log(encoded); // "9Ajdvzr"

const decoded = decode(encoded);
console.log(decoded); // Uint8Array

Enter fullscreen mode Exit fullscreen mode




With Checksum (Base58Check)

Bitcoin and Solana addresses use Base58Check — base58 with a 4-byte SHA-256 checksum:

import { encodeChecked, decodeChecked } from 'base58-core';

const address = encodeChecked(publicKeyBytes);
const verified = decodeChecked(address);

Enter fullscreen mode Exit fullscreen mode




CLI Usage


npx base58-cli encode "hello"
// 9Ajdvzr
Enter fullscreen mode Exit fullscreen mode




Why Not bs58?

bs58 is the most popular option, but it depends on base-x. If you want something with zero dependencies, native TypeScript types, and ESM/CJS dual builds, base58-core covers the same API.

GitHub: https://github.com/opensource-crypto/base58-core

Top comments (0)