-
-
Save abel30567/7c0e3c065a793cc6450e4010cc25cab4 to your computer and use it in GitHub Desktop.
const bitcore = require('bitcore-lib'); | |
const Insight = require('bitcore-insight').Insight; | |
let insight = new Insight('testnet'); | |
// Our private key and address | |
const wif = 'xBtatQED9H44gCmp6HAdmemAzU3n84H3dGkuWTKvE23JgHMW8gct'; | |
const privateKey = new bitcore.PrivateKey(wif); | |
const myAddress = privateKey.toAddress(); | |
// Address we are sending Bitcoin to | |
const addressTo = 'moCEHE5fJgb6yHtF9eLNnS52UQVUkHjnNm'; | |
// Start the creating our transaction | |
const amount = 50000; // Sending amount must be in satoshis | |
const fee = 50000; // Fee is in satoshis | |
// Get the UTXOs of your Bitcoin address | |
insight.getUtxos(myAddress, (err, utxos) => { | |
if(err){ | |
//Handle errors | |
return err; | |
}else { | |
// use the UTXOs to create transaction with bitcore Transaction object | |
let tx = bitcore.Transaction(); | |
tx.from(utxos); | |
tx.to(addressTo, amount); | |
tx.change(myAddress); | |
tx.fee(fee); | |
tx.sign(privateKey); | |
tx.serialize(); | |
// Broadcast your transaction to the Bitcoin network | |
insight.broadcast(tx.toString(), (error, txid) => { | |
if (error) { | |
return error; | |
} else { | |
// Your Transaction Id | |
console.log(txid) | |
} | |
}) | |
} | |
}); |
thx a lot it worked, though it seems like bitpay is down or not accepting the request, any alternative?
Can you please tell how to convert it to mainnet?
@aman-singal It is not working for me either. Have you found any bitcoin node lightclient alternatives? I keep seeing Error: Cannot find module 'bitcore-lib'
after installing bitcore-insight. Let's get this working
@johnworthley as told by @abel30567 in order to fix the error you have to use bitcore-lib which is configured with bitcore-insight. As fas as alternative is concerned i havent found any. The only way i can think of broadcasting a btc transacion rn is by running a full node
How are you importing bitcore? I am using const bitcore = require('../node_modules/bitcore-insight/node_modules/bitcore-lib')
and seeing node_modules/bitcore-insight/node_modules/bitcore-lib/lib/util/preconditions.js:14 throw new errors.InvalidArgument(argumentName, message, docsPath); ^ Invalid Argument
as an error?
Hi in order for this to work you will need to uninstall bitcore-lib and use the bitcore-lib that is configured in the bitcore-insight.
Your package.json file should only include bitcore-insight