Jessica,
You are using
insight which is the simple but less secure way because it uses a third party service, and it has nothing to do with your local bitcoin full node. You should start over by introducing bitcoind as a service to bitcore,
For this to happen you need to
1- Install a bitcore
node,
2- Add bitcoind as service to this node,
3- Install bitcore-lib,
3- use extended methods and events that are now available to do what you want. e.g. getting balance for every address and generating / relaying a transaction for spending that balance.
Below I try to present a very simplified and basic approach to your inquiry. I hope it would help:
var bitcoreNode= require('bitcore-node');
var Bitcoin = bitcoreNode.services.Bitcoin;
var Node = bitcoreNode.Node;
var configuration = {
datadir: '/home/user/.bitcoin',
network: 'testnet',
services: [
{
name: 'bitcoind',
module: Bitcoin,
config: {
spawn: {
datadir: '/home/<username>/.bitcoin',
exec: '/home/<username>/bitcore-node/bin/bitcoind'
}
}
}
]
};
var node = new Node(configuration);
node.start(function() {
console.log('Bitcoin Node is starting ...');
});
node.on('ready', function() {
console.log('Bitcoin Node Ready');
});
node.on('error', function(Err) {
console.error(Err);
});
Now you have run bitcoind and connected to it as a service, an extended set of apis are available now and you can use it for your application
For example you can get total satoshi balance of an address by
var total= node.services.bitcoind.getAddressBalance(<some address>, false ) ;
You need to find all UTXOs for a given address as well:
var address =<some address>;
var UTXOs = node.services.bitcoind.getAddressUnspentOutputs(address, options);
var utx0= {"txId" : UTXOs[0].txId,
"outputIndex" : UTXOs[0].outputIndex,
"address" : UTXOs[0].address,
"script" : UTXOs[0].script,
"satoshis" : UTXOs[0].satoshi
};
// I deliberately wrote it foolishly to disclose the object content ;)
// checking last few blocks to use a proper fee:
var numberOfBlocks = 5;
var suggestedFee = node.services.bitcoind.estimateFee(numberOfBlocks);
You also need bitcore-lib installed and required.
var bitcore = require('bitcore-lib');
var privateKey = new bitcore.PrivateKey(<privateKey>);
var transaction = new bitcore.Transaction()
.from(utxo)
.to(<destnation address>, suggestedFee )
.sign(privateKey);
Now it is time to send the transaction:
var hashSent = node.services.bitcoind.sendTransaction(transaction.serialize());
console.log( "transaction sent:"+hash);
Obviously this is not a working code, exception handling and a lot of details are missing here. But you can use the skeleton and classes/methods/events used above as a starting point to navigate through the documentations.
Jessica,
I have been in your situation many times and I know what a headache it is, but as of my experience, eventually you have to elaborate a
bit lot more and you shouldn't rest until you have finished every detail. Unfortunately I'm not a bitcore enthusiast/practitioner that much, just made a review about it long time ago and i afraid I wouldn't be of much more help. Good luck.