0

I know I can use ethers.js to generate my ERC20 compatible wallet address(public key) from my twelve words seed phrase. I have been wondering if that is doable with bitcoin addresses too because wallets like trustwallet assign bitcoin addresses to seed phrases and this has had me looking for how to implement it too.

Searching on google did not fully help. Is there a way to do it programmatically ?

1 Answer 1

0

Ethers.js does not directly have the methods to generate a bitcoin address.

You can follow the reference at https://en.bitcoin.it/wiki/Technical_background_of_version_1_Bitcoin_addresses#How_to_create_Bitcoin_Address

Summary:

  1. You take an compressed public key (33 bytes) from the seed.
  2. SHA256 on it (ethers.js has this)
  3. RIPEMD160 on it (you can use https://github.com/browserify/ripemd160)
  4. Add version byte prepend 00, so you have 21 bytes now.
  5. Double SHA256 on the 21 bytes and append the first 4 bytes to our 21 bytes.
  6. Now you have 25 bytes, use base58 encoding to display in common format.

If you also want to sign the transactions, best if you can explore a good bitcoin library e.g. https://github.com/bitcoinjs/bitcoinjs-lib

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.