const bsv = require('bsv')
// Random key produced each time...
const newKey = bsv.PrivateKey()
console.log(`Private key: ${newKey.toString()}`)
console.log(`Mainnet address: ${newKey.toAddress('mainnet').toString()}`)
1. Create a funding transaction by sending 1000 satoshis (0.00001 BSV) to ${newKey.toAddress('mainnet').toString()}.
2. Add your Taal apiKey, and funding transaction txid and vout to 'generated.js'.
3. Execute the generated code:
fs.writeFileSync('generated.js', `
const bsv = require('bsv')
var request = require('request')
const privKey = bsv.PrivateKey('${newKey}')
const apiKey = "" // Add Taal mainnet API Key
const fundingTxid = "" // Add the funding transaction txid
const fundingVout = -1 // Replace with funding transaction vout
const returnAddress = "" // The address to return the 1000 satoshis (less fees)
if (apiKey === "" || fundingTxid === "" || fundingVout === -1 || returnAddress === "") {
console.log('This generated file needs an apiKey, a fundingTxid, a fundingVout and a returnAddress')
outputIndex: fundingVout,
address: privKey.toAddress('mainnet').toString(),
script: bsv.Script.buildPublicKeyHashOut(privKey.publicKey).toHex(),
const tx1 = bsv.Transaction()
.to(privKey.toAddress('mainnet').toString(), 800)
address: privKey.toAddress('mainnet').toString(),
script: bsv.Script.buildPublicKeyHashOut(privKey.publicKey).toHex(),
const tx2 = bsv.Transaction()
const txBuffer = Buffer.concat([
// Send the transaction to Taal API...
url: 'https://api.taal.com/api/v1/batchBroadcast',
'Content-Type': 'application/octet-stream'
}, function(error, response, body) {
console.log(error, response.statusCode, body)