UNPKG

escrow-bitcoin

Version:

A service to make possible escrow transactions using BTC (Bitcoin)

89 lines (64 loc) 3.39 kB
# escrow-bitcoin ![travis-ci.org](https://api.travis-ci.org/letsfair/escrow-bitcoin.svg?branch=master) [![Coverage Status](https://coveralls.io/repos/github/letsfair/escrow-bitcoin/badge.svg?branch=master)](https://coveralls.io/github/letsfair/escrow-bitcoin?branch=master) [![NPM](https://nodei.co/npm/escrow-bitcoin.png)](https://nodei.co/npm/escrow-bitcoin/) ## A service to make possible escrow transactions using BTC (Bitcoin) ### Create Escrow wallet ```javascript 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. [Testnet Blockchain](https://testnet.blockchain.info/) [Livenet Blockchain](https://blockchain.info/) ### Send a transaction ```javascript /* ... */ //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) [Testnet Blockchain](https://testnet.blockchain.info/) [Livenet Blockchain](https://blockchain.info/) ## Next steps * [Include fee](https://github.com/letsfair/escrow-bitcoin/issues/3) * [Improve tests](https://github.com/letsfair/escrow-bitcoin/issues/2) * [Create a custom escrow address with JSON parameter](https://github.com/letsfair/escrow-bitcoin/issues/1) ## Contact ![logo](https://gist.githubusercontent.com/tiago-marques/c803bb7ff4a7136573dfafe5e223c8c8/raw/cff8dee7f20b16db8fbf19e0c7910d2da5a11f70/letsfair.png) #### Tiago Marques Co-Founder & Head of Apps Development [tiago@letsfair.org](mailto:tiago@letsfair.org)