Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Validate the tosign data returned by BlockCypher
# create the transaction
$ curl -d '{"inputs": [{"addresses": ["mtWg6ccLiZWw2Et7E5UqmHsYgrAi5wqiov"]}],
"outputs":[{"addresses": ["mzUqjgiGc3Mqh5zMiP5vXDNd7Hwx3K1xCU"], "value": 25000}]}' \
https://api.blockcypher.com/v1/btc/test3/txs/new?includeToSignTx=true
{
"tx": {
"block_height": -1,
"hash": "568acff13300b471d384e16a1a6d449be704e97b819f051dc4f1fb246726e471",
"addresses": [
"mzUqjgiGc3Mqh5zMiP5vXDNd7Hwx3K1xCU",
"mtWg6ccLiZWw2Et7E5UqmHsYgrAi5wqiov"
],
"total": 23477984,
"fees": 12000,
"size": 119,
"preference": "high",
"relayed_by": "169.53.156.231",
"received": "2015-04-30T18:22:37.060105514Z",
"ver": 1,
"lock_time": 0,
"double_spend": false,
"vin_sz": 1,
"vout_sz": 2,
"confirmations": 0,
"inputs": [
{
"prev_hash": "911ac2cd4e3c18fdb752a0d59e5ad220722b718cb80d53d5a6cae9c74d026efc",
"output_index": 1,
"script": "",
"output_value": 23489984,
"sequence": 4294967295,
"addresses": [
"mtWg6ccLiZWw2Et7E5UqmHsYgrAi5wqiov"
],
"script_type": "",
"age": 2870
}
],
"outputs": [
{
"value": 25000,
"script": "76a914d004156436b38ef464b01286cdc9c4b36c99c68788ac",
"addresses": [
"mzUqjgiGc3Mqh5zMiP5vXDNd7Hwx3K1xCU"
],
"script_type": "pay-to-pubkey-hash"
},
{
"value": 23452984,
"script": "76a9148e8c1d4adef86c11154fd04b5012306715fd4baf88ac",
"addresses": [
"mtWg6ccLiZWw2Et7E5UqmHsYgrAi5wqiov"
],
"script_type": "pay-to-pubkey-hash"
}
]
},
"tosign_tx": [
"0100000001fc6e024dc7e9caa6d5530db88c712b7220d25a9ed5a052b7fd183c4ecdc21a91010000001976a9148e8c1d4adef86c11154fd04b5012306715fd4baf88acffffffff02a8610000000000001976a914d004156436b38ef464b01286cdc9c4b36c99c68788ac38dd6501000000001976a9148e8c1d4adef86c11154fd04b5012306715fd4baf88ac0000000001000000"
],
"tosign": [
"b365bef9aae17e0d35963217d65915a2a00bc782f1bb1be5061a18d92063309e"
]
}
# decode the tosign_tx data returned to validate the transaction data matches the required inputs and outputs
$ curl -d '{"tx": "0100000001fc6e024dc7e9caa6d5530db88c712b7220d25a9ed5a052b7fd183c4ecdc21a91010000001976a9148e8c1d4adef86c11154fd04b5012306715fd4baf88acffffffff02a8610000000000001976a914d004156436b38ef464b01286cdc9c4b36c99c68788ac38dd6501000000001976a9148e8c1d4adef86c11154fd04b5012306715fd4baf88ac0000000001000000"}' https://api.blockcypher.com/v1/btc/test3/txs/decode
{
"block_height": -1,
"hash": "855d69a6b56bf159d84efd6e0243f8d45d429df482560cae619a6f552ab43a0b",
"addresses": [
"mtWg6ccLiZWw2Et7E5UqmHsYgrAi5wqiov",
"mzUqjgiGc3Mqh5zMiP5vXDNd7Hwx3K1xCU"
],
"total": 23477984,
"fees": 12000,
"size": 144,
"preference": "high",
"relayed_by": "169.53.156.231",
"received": "2015-04-30T18:44:08.591995605Z",
"ver": 1,
"lock_time": 0,
"double_spend": false,
"vin_sz": 1,
"vout_sz": 2,
"confirmations": 0,
"inputs": [
{
"prev_hash": "911ac2cd4e3c18fdb752a0d59e5ad220722b718cb80d53d5a6cae9c74d026efc",
"output_index": 1,
"script": "76a9148e8c1d4adef86c11154fd04b5012306715fd4baf88ac",
"output_value": 23489984,
"sequence": 4294967295,
"addresses": [
"mtWg6ccLiZWw2Et7E5UqmHsYgrAi5wqiov"
],
"script_type": "pay-to-pubkey-hash",
"age": 2893
}
],
"outputs": [
{
"value": 25000,
"script": "76a914d004156436b38ef464b01286cdc9c4b36c99c68788ac",
"addresses": [
"mzUqjgiGc3Mqh5zMiP5vXDNd7Hwx3K1xCU"
],
"script_type": "pay-to-pubkey-hash"
},
{
"value": 23452984,
"script": "76a9148e8c1d4adef86c11154fd04b5012306715fd4baf88ac",
"addresses": [
"mtWg6ccLiZWw2Et7E5UqmHsYgrAi5wqiov"
],
"script_type": "pay-to-pubkey-hash"
}
]
}
# validate that tosign is equal to tosign_tx after 2 rounds of sha256 hashing
$ echo -n "0100000001fc6e024dc7e9caa6d5530db88c712b7220d25a9ed5a052b7fd183c4ecdc21a9101000001976a9148e8c1d4adef86c11154fd04b5012306715fd4baf88acffffffff02a8610000000000001976a914d004156436b38ef464b01286cdc9c4b36c99c68788ac38dd6501000000001976a9148e8c1d4adef86c11154fd04b5012306715fd4baf88ac0000000001000000" | xxd -r -p | sha256sum -b
f80804283c023d50bdf3ba6a4f938dc2e65767b8aa55414ea6aae9ef410a55a6 *-
$ echo -n "f80804283c023d50bdf3ba6a4f938dc2e65767b8aa55414ea6aae9ef410a55a6" | xxd -r -p | sha256sum -b
b365bef9aae17e0d35963217d65915a2a00bc782f1bb1be5061a18d92063309e *-
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.