-
Notifications
You must be signed in to change notification settings - Fork 15
/
send-bch.js
60 lines (50 loc) · 1.47 KB
/
send-bch.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
/*
An example for sending BCH with this library.
*/
const SlpWallet = require('../index')
async function sendBch () {
try {
// Replace the values for the constants below to customize for your use.
const MNEMONIC =
'essence appear intact casino neck scatter search post cube fit door margin'
const RECIEVER = ''
const SATS_TO_SEND = 1000
// Instantiate the wallet library.
const slpWallet = new SlpWallet(MNEMONIC)
// Wait for the wallet to be created.
await slpWallet.walletInfoPromise
// Get the balance of the wallet.
const balance = await slpWallet.getBalance()
console.log(`balance: ${balance} satoshis`)
// Exit if the wallet has no balance.
if (balance === 0) {
console.log(
`The balance of your wallet is zero. Send BCH to ${
slpWallet.walletInfo.address
} to run this example.`
)
return
}
// Create the outputs array.
const outputs = []
// If reciever is not specified, send the funds back to the wallet.
if (RECIEVER === '') {
outputs.push({
address: slpWallet.walletInfo.address,
amountSat: SATS_TO_SEND
})
//
// Send the funds to the reciever.
} else {
outputs.push({
address: RECIEVER,
amountSat: SATS_TO_SEND
})
}
const txid = await slpWallet.send(outputs)
console.log(`Success! BCH sent with TXID: ${txid}`)
} catch (err) {
console.error('Error: ', err)
}
}
sendBch()