Skip to content
This repository was archived by the owner on Mar 18, 2025. It is now read-only.

Commit 4d33fbb

Browse files
committed
initial commit
0 parents  commit 4d33fbb

6 files changed

Lines changed: 4469 additions & 0 deletions

File tree

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
private-key.txt

Readme.md

Whitespace-only changes.

create-key.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
const { writeFileSync } = require('fs')
2+
const bitcoin = require('bitcore-lib')
3+
const { PrivateKey, Transaction } = bitcoin
4+
5+
const pvtKey = new PrivateKey()
6+
writeFileSync('./private-key.txt', pvtKey.toString())
7+
8+
const address = pvtKey.toAddress().toString()
9+
10+
console.log("private key:", pvtKey.toString())
11+
console.log("address:", address)

index.js

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
const { readFileSync } = require('fs')
2+
const bitcoin = require('bitcore-lib')
3+
const { PrivateKey, Transaction } = bitcoin
4+
5+
const pvtKeyString = readFileSync('./private-key.txt').toString().trim()
6+
const pvtKey = new PrivateKey(pvtKeyString)
7+
8+
const address = pvtKey.toAddress().toString()
9+
10+
console.log("private key:", pvtKey.toString())
11+
console.log("address:", address)
12+
13+
// --- 6 lines
14+
15+
const { utxos } = require('blockchain-api-basic')
16+
17+
;(async () => {
18+
const unspent = await utxos(address)
19+
20+
console.log("utxos:", unspent)
21+
22+
const amount = 100000 // 100k sats (1mbtc)
23+
24+
const tx = new Transaction()
25+
.from(unspent)
26+
.to(address, amount)
27+
.change(address)
28+
.fee(1000)
29+
.sign(pvtKey)
30+
31+
const txHex = tx.serialize()
32+
33+
console.log("tx:", txHex)
34+
35+
const { success, txHash } = pushTx(txHex)
36+
console.log("success:", success, "txHash:", txHash)
37+
38+
})()

0 commit comments

Comments
 (0)