Skip to content

Commit 7795853

Browse files
authored
Create example-generate-address.js
1 parent 13aea8c commit 7795853

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

src/example-generate-address.js

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
/**
2+
* Example: Generate a new Bitcoin address using bitcoinjs-lib.
3+
* This simple script creates a random key pair and logs
4+
* the corresponding P2WPKH (SegWit) address.
5+
*/
6+
7+
import * as bitcoin from 'bitcoinjs-lib';
8+
9+
export function generateSegWitAddress() {
10+
const keyPair = bitcoin.ECPair.makeRandom();
11+
const { address } = bitcoin.payments.p2wpkh({ pubkey: keyPair.publicKey });
12+
console.log('Your new Bitcoin address:', address);
13+
return address;
14+
}
15+
16+
// Uncomment below line for direct execution
17+
// generateSegWitAddress();

0 commit comments

Comments
 (0)