Created
January 28, 2019 01:58
-
-
Save abel30567/7c0e3c065a793cc6450e4010cc25cab4 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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) | |
| } | |
| }) | |
| } | |
| }); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
How are you importing bitcore? I am using
const bitcore = require('../node_modules/bitcore-insight/node_modules/bitcore-lib')and seeingnode_modules/bitcore-insight/node_modules/bitcore-lib/lib/util/preconditions.js:14 throw new errors.InvalidArgument(argumentName, message, docsPath); ^ Invalid Argumentas an error?