cryptocoinjs / bs58

Base58 encoding/decoding for Bitcoin
http://cryptocoinjs.com/modules/misc/bs58/
MIT License
216 stars 48 forks source link

TypeError: bs58.decode is not a function #50

Closed georgewslee closed 4 months ago

georgewslee commented 4 months ago

const bs58 = require('bs58'); const address = '16UjcYNBG9GTK4uq2f7yYEbuifqCzoLMGS' const bytes = bs58.decode(address) // See uint8array-tools package for helpful hex encoding/decoding/compare tools console.log(Buffer.from(bytes).toString('hex')) // => 003c176e659bea0f29a3e9bf7880c112b1b31b4dc826268187

when i run it, I get the following error: const bytes = bs58.decode(address) ---------------------^ TypeError: bs58.decode is not a function

What am I doing wrong? Anything to do with esm? I need to use it in a commonJs script.

junderw commented 4 months ago

When using an ESM module in commonjs, the default import is called default

const bs58 = require('bs58').default;