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

Commit 7792c79

Browse files
committed
add readme
1 parent ad82b47 commit 7792c79

File tree

1 file changed

+61
-0
lines changed

1 file changed

+61
-0
lines changed

Readme.md

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
# EPISODE 03
2+
3+
(maybe delete 01 and 02 and just publish this)
4+
5+
code for the episode:
6+
7+
```js
8+
9+
const { readFileSync } = require('fs')
10+
const bitcoin = require('bitcore-lib')
11+
const { PrivateKey, Transaction } = bitcoin
12+
13+
const pvtKeyString = readFileSync('./private-key.txt').toString().trim()
14+
const pvtKey = new PrivateKey(pvtKeyString)
15+
16+
const address = pvtKey.toAddress().toString()
17+
18+
console.log("private key:", pvtKey.toString())
19+
console.log("address:", address)
20+
21+
// --- 6 lines
22+
23+
// const getUTXOs = require('blockchain-api/get-utxos')
24+
const getUTXOs = require('./blockchain-api/get-utxos')
25+
26+
;(async () => {
27+
try {
28+
let utxos = await getUTXOs({ address })
29+
30+
utxos = [ utxos[0] ]
31+
32+
console.log("utxos:", utxos)
33+
34+
const amount = 10000 // 10k sats (0.1mbtc)
35+
36+
const tx = new Transaction()
37+
.from(utxos)
38+
.to(address, amount)
39+
.change(address)
40+
.fee(1000)
41+
.sign(pvtKey)
42+
43+
const txHex = tx.serialize()
44+
45+
console.log("tx:", txHex)
46+
47+
const { success, txHash } = pushTx(txHex)
48+
console.log("success:", success, "txHash:", txHash)
49+
50+
} catch (err) {
51+
console.error(err)
52+
}
53+
})()
54+
55+
```
56+
57+
That's it - creating a private key and sending a bitcoin transaction in 30 lines of code - youtube video explainer #coding #bitcoin #tx #utxo #bitcoin-tx #bitcoin-utxo
58+
59+
---
60+
61+
@makevoid

0 commit comments

Comments
 (0)