escrow-bitcoin
v0.0.6
Published
A service to make possible escrow transactions using BTC (Bitcoin)
Downloads
16
Maintainers
Readme
escrow-bitcoin
A service to make possible escrow transactions using BTC (Bitcoin)
Create Escrow wallet
const Escrow = require("escrow-bitcoin");
// Will be used soon
var escrow;
/**
* Create a Escrow Wallet
*
* @param {Number} amount - Amount to escrow (in satoshis)
* @param {Networks} [network=bitcore.Networks.testnet] - Network to make transaction
* @returns {Object} (with privateKey, adress and URI to request payment)
*/
Escrow.createEscrowAddress(1200, Escrow.Networks.livenet).then(function(escrowResult){
escrow = escrowResult;
console.log(escrow);
// {
// privateKey: <PrivateKey: 6b5b3c47ea2c0c0dd278f0b667da441176beb31e345284dcb2fe0748cbe85969, network: livenet>,
// address: <Address: myqWz9x2QsQQHKQtV56PyD4Myw34igxdin, type: pubkeyhash, network: testnet>,
// URI: "bitcoin:mkaFycfbM3SuZ4mFJVeNjQv58a4KkYAUPk?amount=0.000012" //can be used to QRCode
// }
});
/* ... */
Save escrow PrivateKey in a secure place, this information is necessary to make a transaction from escrow wallet. Give the address and/or URI to who need to escrow the bitcoins.
When if escrow wallet had the necessary balance (you can verify with blockchain.info API or other services), make a transaction to send Bitcoins to who need receive them.
Send a transaction
/* ... */
//Address to
var addressTo = "mkaFycfbM3SuZ4mFJVeNjQv58a4KkYAUPk"
/**
* Make Escrow wallet send bitcoin
*
* @param {Address} escrowAddress - Address to withdraw
* @param {PrivateKey} escrowPrivateKey - PrivateKey from Address to withdraw to sign transaction
* @param {Address} addressTo - Address to send
* @param {Number} amount - Amount (in satoshis)
* @param {Networks} [network=bitcore.Networks.testnet] - Network to make transaction
* @returns string (transaction id)
*/
new Escrow(escrow.address, escrow.privateKey, addressTo, 1200, Escrow.Networks.livenet).then(function(transactionId){
console.log(transactionId)
// fabb99ef2e45e71cbc8eba3de15bf5729e8b502c22c4b52af04e98c49493d65e
})
Use transactionId to verify in blockchain.info API (or other services) to see the status of the transaction (incoming BTC should appears instantly)
Next steps
Contact
Tiago Marques
Co-Founder & Head of Apps Development