helloblock-faucet
v0.0.1
Published
Bitcoin programmatic faucet.
Downloads
7
Maintainers
Readme
helloblock-faucet
Need coins for testing your bitcoin software? Welcome!
API
getUnspents
arguments
number
type Faucet type, could be 1, 2 or 3function
callback Node-style callback
callback arguments
?Error
errorObject
datastring
data.privateKeyWIFstring
data.privateKeyHexstring
data.addressstring
data.hash160number
data.faucetTypeObject[]
data.unspentsnumber
confrimationsnumber
blockHeightstring
txHashnumber
indexstring
scriptPubKeystring
typenumber
valuestring
hash160string
address
withdrawal
arguments
string
toAddress Address for satoshinumber
value Coin size (max: 1,000,000)function
callback Node-style callback
callback arguments
?Error
errorObject
datanumber
data.valuestring
data.fromAddressstring
data.toAddressstring
data.txHash
Examples
Create new transaction
var faucet = require('helloblock-faucet')
var bitcoin = require('bitcoinjs-lib')
var request = require('request')
faucet.getUnspents(1, function (error, data) {
if (error !== null) {
return console.log(error)
}
var privKey = bitcoin.ECKey.fromWIF(data.privateKeyWIF)
var total = 0
var txb = new bitcoin.TransactionBuilder()
data.unspents.forEach(function (unspent) {
total += unspent.value
txb.addInput(unspent.txHash, unspent.index)
})
txb.addOutput('testnet_address', total - 10000)
data.unspents.forEach(function (_, index) {
txb.sign(index, privKey)
})
var opts = {
uri: 'https://testnet.helloblock.io/v1/transactions',
method: 'POST',
json: {rawTxHex: txb.build().toHex()}
}
request(opts, function (error, response) {
if (error !== null) {
return console.log(error)
}
console.log('Create new tx! TxHash: ' + response.body.data.transaction.txHash)
})
})
License
Code released under the MIT license.