Created
June 11, 2016 15:50
-
-
Save kobigurk/8d21294f07f43848fd2924e960918f84 to your computer and use it in GitHub Desktop.
puzzle
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var bitcore = require('bitcore'); | |
var request = require('request'); | |
var utxo = { | |
'txId' : '0c5d827a24b0822abbff73f1adbfd2be7efaf4e368b4baac7e280865eb13f497', | |
'outputIndex' : 1, | |
'script' : 'a91431f2ae5b333c56a4f01df6209382ec8f892e4f3687', | |
'satoshis' : 1000000 | |
}; | |
//you can see it here: | |
//https://live.blockcypher.com/btc/tx/0c5d827a24b0822abbff73f1adbfd2be7efaf4e368b4baac7e280865eb13f497 | |
var address = 'YOUR_ADDRESS'; | |
var tx = new bitcore.Transaction().from(utxo).to(address, 900000); | |
var redeemScript = bitcore.Script.fromASM('\ | |
OP_SHA256 \ | |
1bc273366856a5fb0bfd0611f57b7d4ae8e709dbe30fa207729f74716fd4e877\ | |
OP_EQUAL'); | |
//this is your task! what is the total number of Bitcoins that will | |
//ever be created, in hex format (don't forget the leading zero!)? | |
var solutionScript = ''; | |
var scriptSig = bitcore.Script.fromASM(solutionScript + ' ' + redeemScript); | |
tx.inputs[0].setScript(scriptSig); | |
var rawTx = tx.toString('hex'); | |
var pushTx = { | |
tx: rawTx | |
}; | |
//for simplicity, we'll use the awesome BlockCypher API. | |
//You could also submit this raw transaction using Bitcoin Core. | |
request({ | |
url: 'https://api.blockcypher.com/v1/btc/main/txs/push', | |
method: 'POST', | |
json: true, | |
body: pushTx | |
}, function (err, response, body) { | |
if (err) { | |
return console.log('Error: ', err); | |
} | |
console.log(body); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment