Skip to content

Instantly share code, notes, and snippets.

@rlaace423
Created November 24, 2021 14:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rlaace423/b6e0cb39db40f6538bcd6e6dddbbf0c2 to your computer and use it in GitHub Desktop.
Save rlaace423/b6e0cb39db40f6538bcd6e6dddbbf0c2 to your computer and use it in GitHub Desktop.
create bitcoin address (native nodejs)
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