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

Commit ad82b47

Browse files
committed
use getUTXOs function, catch exception, send 0.1mbtc as default amount, sample transaction serializes
1 parent 45d1b31 commit ad82b47

File tree

1 file changed

+21
-14
lines changed

1 file changed

+21
-14
lines changed

index.js

Lines changed: 21 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -12,27 +12,34 @@ console.log("address:", address)
1212

1313
// --- 6 lines
1414

15-
const { utxos } = require('blockchain-api-basic')
15+
// const getUTXOs = require('blockchain-api/get-utxos')
16+
const getUTXOs = require('./blockchain-api/get-utxos')
1617

1718
;(async () => {
18-
const unspent = await utxos(address)
19+
try {
20+
let utxos = await getUTXOs({ address })
1921

20-
console.log("utxos:", unspent)
22+
utxos = [ utxos[0] ]
2123

22-
const amount = 100000 // 100k sats (1mbtc)
24+
console.log("utxos:", utxos)
2325

24-
const tx = new Transaction()
25-
.from(unspent)
26-
.to(address, amount)
27-
.change(address)
28-
.fee(1000)
29-
.sign(pvtKey)
26+
const amount = 10000 // 10k sats (0.1mbtc)
3027

31-
const txHex = tx.serialize()
28+
const tx = new Transaction()
29+
.from(utxos)
30+
.to(address, amount)
31+
.change(address)
32+
.fee(1000)
33+
.sign(pvtKey)
3234

33-
console.log("tx:", txHex)
35+
const txHex = tx.serialize()
3436

35-
const { success, txHash } = pushTx(txHex)
36-
console.log("success:", success, "txHash:", txHash)
37+
console.log("tx:", txHex)
3738

39+
const { success, txHash } = pushTx(txHex)
40+
console.log("success:", success, "txHash:", txHash)
41+
42+
} catch (err) {
43+
console.error(err)
44+
}
3845
})()

0 commit comments

Comments
 (0)