Created
November 24, 2021 14:12
-
-
Save rlaace423/b6e0cb39db40f6538bcd6e6dddbbf0c2 to your computer and use it in GitHub Desktop.
create bitcoin address (native nodejs)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { createECDH } from 'crypto'; | |
import { p2wpkh } from 'bitcoinjs-lib/src/payments'; | |
import { bitcoin } from 'bitcoinjs-lib/src/networks'; | |
import { Buffer } from 'buffer'; | |
import { encode } from 'wif'; | |
const network = bitcoin; | |
const ecdh = createECDH('secp256k1'); | |
ecdh.generateKeys(); | |
const payment = p2wpkh({ pubkey: Buffer.from(ecdh.getPublicKey('hex', 'compressed'), 'hex'), network }); | |
console.log(`address: ${payment.address}`); | |
console.log(`privateKey: ${encode(network.wif, ecdh.getPrivateKey(), true)}`); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment