In our examples we're going to use the bitcoinjs-lib and the helloblock-js test faucet to get and process our private key, public address and unspent outputs.
var Bitcoin =require("bitcoinjs-lib");
var helloblock =require("helloblock-js")({
network:'testnet'
});
helloblock.faucet.get(1,function(err,res,body){
var privateKeyWIF =body.privateKeyWIF;
var address =body.address;
var unspentOutputs =body.unspents;
// ...
});
We'll need to provide a few of your own functions.
Signing a transaction:
varsignFromPrivateKeyWIF=function(privateKeyWIF){
returnfunction(tx,callback){
var key =Bitcoin.ECKey.fromWIF(privateKeyWIF);
tx.sign(0, key);
callback(false, tx);
}
};
var signTransaction =signFromPrivateKeyWIF(privateKeyWIF);