Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions src/example-generate-address.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
/**
* Example: Generate a new Bitcoin address using bitcoinjs-lib.
* This simple script creates a random key pair and logs
* the corresponding P2WPKH (SegWit) address.
*/

import * as bitcoin from 'bitcoinjs-lib';

export function generateSegWitAddress() {
const keyPair = bitcoin.ECPair.makeRandom();
const { address } = bitcoin.payments.p2wpkh({ pubkey: keyPair.publicKey });
console.log('Your new Bitcoin address:', address);
return address;
}

// Uncomment below line for direct execution
// generateSegWitAddress();