在 Blockcypher 上广播原始交易,在 POST 请求时出现错误
Broadcasting Raw Transaction on Blockcypher, getting a error on POST request
我有一个原始比特币交易,我想用 Blockcypher API 广播,我正在使用 axios 发送 POST 请求:
var axios = require('axios')
axios.post('https://api.blockcypher.com/v1/bcy/test/txs/send', {
"tx": "010000000174770a05466c28df24425ac50dba86ead47af31778f01fa1069bf01816810a2b010000008b48304502210090c86f59c8df34979ccb485c524803e9ba1290cc4448cdbfdcc8f3cf3337102302202357e77439354acf7b178392720f433cfeac952d34098addb2eea7edcf7884c20141048520397beff2fe111c7af8aa42c99b317453b1595ec5c3b3cf9eb2059dd06b9b956165419d51a48d885aacb4df1004d7c93b30e2e53c6d4f64f9668c9fd7e92fffffffff02cd0d0000000000001976a914243170728a9278ed24b4ac7ba9df33bdadf7afd488ac00000000000000004d6a4b77723335322d33316472342d4e42412d33323132322d333435352d363933352d323334392d323334302d31323333322d39392d30322d31362d323031352d32336f6c2d313030303030303000000000"
})
.then(function (response) {
console.log(response);
})
.catch(function (response) {
console.log(response);
});
我在终端中 运行 时收到错误消息:
{ data: { error: 'Couldn\'t deserialize request: json: cannot unmarshal string into Go value of type pooch.JSONTx' }
知道我的 POST 出了什么问题吗?我尝试 post 与 tx 而不是 "tx" 但它仍然不起作用。在文档中,他们建议这样做:
var pushtx = {
tx: "01000000011935b41d12936df99d322ac8972b74ecff7b79408bbccaf1b2eb8015228beac8000000006b483045022100921fc36b911094280f07d8504a80fbab9b823a25f102e2bc69b14bcd369dfc7902200d07067d47f040e724b556e5bc3061af132d5a47bd96e901429d53c41e0f8cca012102152e2bb5b273561ece7bbe8b1df51a4c44f5ab0bc940c105045e2cc77e618044ffffffff0240420f00000000001976a9145fb1af31edd2aa5a2bbaa24f6043d6ec31f7e63288ac20da3c00000000001976a914efec6de6c253e657a9d5506a78ee48d89762fb3188ac00000000"
};
$.post('https://api.blockcypher.com/v1/bcy/test/txs/push', JSON.stringify(pushtx))
.then(function(d) {console.log(d)});
但是当我这样做时,我得到了错误:
TypeError: undefined is not a function
所以我认为使用 axios 更容易,因为我至少从 Blockcypher 那里得到了回复。任何帮助将不胜感激!
全面披露:BlockCypher 的开发倡导者在这里。首先,根据文档的 Greg's advice in the comments, in the first case, using the /txs/send
endpoint we expect a TX Skeleton. This is outlined more clearly in the Creating Transactions section。
使用 /txs/push
应该适用于你的情况,尽管我也遇到了错误。为了进行调查,我首先检查了我们的 /txs/decode
端点,这是调试的良好开端,因为它将向您展示我们的服务器如何反序列化原始事务。你可以 read more about it here.
var decodetx = {
tx: "01000000011935b41d12936df99d322ac8972b74ecff7b79408bbccaf1b2eb8015228beac8000000006b483045022100921fc36b911094280f07d8504a80fbab9b823a25f102e2bc69b14bcd369dfc7902200d07067d47f040e724b556e5bc3061af132d5a47bd96e901429d53c41e0f8cca012102152e2bb5b273561ece7bbe8b1df51a4c44f5ab0bc940c105045e2cc77e618044ffffffff0240420f00000000001976a9145fb1af31edd2aa5a2bbaa24f6043d6ec31f7e63288ac20da3c00000000001976a914efec6de6c253e657a9d5506a78ee48d89762fb3188ac00000000"
};
$.post('https://api.blockcypher.com/v1/bcy/test/txs/decode', JSON.stringify(decode))
.then(function(d) {console.log(d)});
这对我有用,return解码(但未推送!)事务:
{
"block_height": -1,
"block_index": -1,
"hash": "4e6dfb1415b4fba5bd257c129847c70fbd4e45e41828079c4a282680528f3a50",
"addresses": [
"CEztKBAYNoUEEaPYbkyFeXC5v8Jz9RoZH9",
"C1rGdt7QEPGiwPMFhNKNhHmyoWpa5X92pn"
],
"total": 4988000,
"fees": 12000,
"size": 226,
"preference": "high",
"relayed_by": "54.213.170.147, 127.0.0.1",
"received": "2016-02-17T20:16:43.124983132Z",
"ver": 1,
"lock_time": 0,
"double_spend": false,
"vin_sz": 1,
"vout_sz": 2,
"confirmations": 0,
"inputs": [
{
"prev_hash": "c8ea8b221580ebb2f1cabc8b40797bffec742b97c82a329df96d93121db43519",
"output_index": 0,
"script": "483045022100921fc36b911094280f07d8504a80fbab9b823a25f102e2bc69b14bcd369dfc7902200d07067d47f040e724b556e5bc3061af132d5a47bd96e901429d53c41e0f8cca012102152e2bb5b273561ece7bbe8b1df51a4c44f5ab0bc940c105045e2cc77e618044",
"output_value": 5000000,
"sequence": 4294967295,
"addresses": [
"CEztKBAYNoUEEaPYbkyFeXC5v8Jz9RoZH9"
],
"script_type": "pay-to-pubkey-hash",
"age": 386562
}
],
"outputs": [
{
"value": 1000000,
"script": "76a9145fb1af31edd2aa5a2bbaa24f6043d6ec31f7e63288ac",
"addresses": [
"C1rGdt7QEPGiwPMFhNKNhHmyoWpa5X92pn"
],
"script_type": "pay-to-pubkey-hash"
},
{
"value": 3988000,
"script": "76a914efec6de6c253e657a9d5506a78ee48d89762fb3188ac",
"spent_by": "892fd7b36c1c3a2e5edb9b4a5d4ffd9ba74d78d3acf3b249991bd8d10a287dbd",
"addresses": [
"CEztKBAYNoUEEaPYbkyFeXC5v8Jz9RoZH9"
],
"script_type": "pay-to-pubkey-hash"
}
]
}
这里一切看起来都不错。所以我尝试使用 /txs/push
,这次,通过 cURL 收集 return 中的错误消息:
curl -d '{"tx":"01000000011935b41d12936df99d322ac8972b74ecff7b79408bbccaf1b2eb8015228beac8000000006b483045022100921fc36b911094
280f07d8504a80fbab9b823a25f102e2bc69b14bcd369dfc7902200d07067d47f040e724b556e5bc3061af132d5a47bd96e901429d53c41e0f8cca012102152e2bb5b273561ece7bbe8b1d
f51a4c44f5ab0bc940c105045e2cc77e618044ffffffff0240420f00000000001976a9145fb1af31edd2aa5a2bbaa24f6043d6ec31f7e63288ac20da3c00000000001976a914efec6de6c2
53e657a9d5506a78ee48d89762fb3188ac00000000"}' https://api.blockcypher.com/v1/bcy/test/txs/push
{"error": "Error validating transaction: Transaction with hash 4e6dfb1415b4fba5bd257c129847c70fbd4e45e41828079c4a282680528f3a50 already exists.."}
果然,根据该错误消息,该交易已经存在于我们的内部测试网上,如下所示:
我认为您正在尝试推送一个已推送的原始交易。如果您想测试交易创建,我建议您在我们的测试网上生成您自己的地址:
http://dev.blockcypher.com/#generate-address-endpoint
您可以使用我们的水龙头将一些硬币发送到这些地址:
http://dev.blockcypher.com/#testing
(或通过此处的 Web 界面:https://accounts.blockcypher.com/blockcypher-faucet)。
然后按照 "Creating Transactions" 中列出的步骤进行操作:
http://dev.blockcypher.com/#creating-transactions
希望对您有所帮助!
我有一个原始比特币交易,我想用 Blockcypher API 广播,我正在使用 axios 发送 POST 请求:
var axios = require('axios')
axios.post('https://api.blockcypher.com/v1/bcy/test/txs/send', {
"tx": "010000000174770a05466c28df24425ac50dba86ead47af31778f01fa1069bf01816810a2b010000008b48304502210090c86f59c8df34979ccb485c524803e9ba1290cc4448cdbfdcc8f3cf3337102302202357e77439354acf7b178392720f433cfeac952d34098addb2eea7edcf7884c20141048520397beff2fe111c7af8aa42c99b317453b1595ec5c3b3cf9eb2059dd06b9b956165419d51a48d885aacb4df1004d7c93b30e2e53c6d4f64f9668c9fd7e92fffffffff02cd0d0000000000001976a914243170728a9278ed24b4ac7ba9df33bdadf7afd488ac00000000000000004d6a4b77723335322d33316472342d4e42412d33323132322d333435352d363933352d323334392d323334302d31323333322d39392d30322d31362d323031352d32336f6c2d313030303030303000000000"
})
.then(function (response) {
console.log(response);
})
.catch(function (response) {
console.log(response);
});
我在终端中 运行 时收到错误消息:
{ data: { error: 'Couldn\'t deserialize request: json: cannot unmarshal string into Go value of type pooch.JSONTx' }
知道我的 POST 出了什么问题吗?我尝试 post 与 tx 而不是 "tx" 但它仍然不起作用。在文档中,他们建议这样做:
var pushtx = {
tx: "01000000011935b41d12936df99d322ac8972b74ecff7b79408bbccaf1b2eb8015228beac8000000006b483045022100921fc36b911094280f07d8504a80fbab9b823a25f102e2bc69b14bcd369dfc7902200d07067d47f040e724b556e5bc3061af132d5a47bd96e901429d53c41e0f8cca012102152e2bb5b273561ece7bbe8b1df51a4c44f5ab0bc940c105045e2cc77e618044ffffffff0240420f00000000001976a9145fb1af31edd2aa5a2bbaa24f6043d6ec31f7e63288ac20da3c00000000001976a914efec6de6c253e657a9d5506a78ee48d89762fb3188ac00000000"
};
$.post('https://api.blockcypher.com/v1/bcy/test/txs/push', JSON.stringify(pushtx))
.then(function(d) {console.log(d)});
但是当我这样做时,我得到了错误:
TypeError: undefined is not a function
所以我认为使用 axios 更容易,因为我至少从 Blockcypher 那里得到了回复。任何帮助将不胜感激!
全面披露:BlockCypher 的开发倡导者在这里。首先,根据文档的 Greg's advice in the comments, in the first case, using the /txs/send
endpoint we expect a TX Skeleton. This is outlined more clearly in the Creating Transactions section。
使用 /txs/push
应该适用于你的情况,尽管我也遇到了错误。为了进行调查,我首先检查了我们的 /txs/decode
端点,这是调试的良好开端,因为它将向您展示我们的服务器如何反序列化原始事务。你可以 read more about it here.
var decodetx = {
tx: "01000000011935b41d12936df99d322ac8972b74ecff7b79408bbccaf1b2eb8015228beac8000000006b483045022100921fc36b911094280f07d8504a80fbab9b823a25f102e2bc69b14bcd369dfc7902200d07067d47f040e724b556e5bc3061af132d5a47bd96e901429d53c41e0f8cca012102152e2bb5b273561ece7bbe8b1df51a4c44f5ab0bc940c105045e2cc77e618044ffffffff0240420f00000000001976a9145fb1af31edd2aa5a2bbaa24f6043d6ec31f7e63288ac20da3c00000000001976a914efec6de6c253e657a9d5506a78ee48d89762fb3188ac00000000"
};
$.post('https://api.blockcypher.com/v1/bcy/test/txs/decode', JSON.stringify(decode))
.then(function(d) {console.log(d)});
这对我有用,return解码(但未推送!)事务:
{
"block_height": -1,
"block_index": -1,
"hash": "4e6dfb1415b4fba5bd257c129847c70fbd4e45e41828079c4a282680528f3a50",
"addresses": [
"CEztKBAYNoUEEaPYbkyFeXC5v8Jz9RoZH9",
"C1rGdt7QEPGiwPMFhNKNhHmyoWpa5X92pn"
],
"total": 4988000,
"fees": 12000,
"size": 226,
"preference": "high",
"relayed_by": "54.213.170.147, 127.0.0.1",
"received": "2016-02-17T20:16:43.124983132Z",
"ver": 1,
"lock_time": 0,
"double_spend": false,
"vin_sz": 1,
"vout_sz": 2,
"confirmations": 0,
"inputs": [
{
"prev_hash": "c8ea8b221580ebb2f1cabc8b40797bffec742b97c82a329df96d93121db43519",
"output_index": 0,
"script": "483045022100921fc36b911094280f07d8504a80fbab9b823a25f102e2bc69b14bcd369dfc7902200d07067d47f040e724b556e5bc3061af132d5a47bd96e901429d53c41e0f8cca012102152e2bb5b273561ece7bbe8b1df51a4c44f5ab0bc940c105045e2cc77e618044",
"output_value": 5000000,
"sequence": 4294967295,
"addresses": [
"CEztKBAYNoUEEaPYbkyFeXC5v8Jz9RoZH9"
],
"script_type": "pay-to-pubkey-hash",
"age": 386562
}
],
"outputs": [
{
"value": 1000000,
"script": "76a9145fb1af31edd2aa5a2bbaa24f6043d6ec31f7e63288ac",
"addresses": [
"C1rGdt7QEPGiwPMFhNKNhHmyoWpa5X92pn"
],
"script_type": "pay-to-pubkey-hash"
},
{
"value": 3988000,
"script": "76a914efec6de6c253e657a9d5506a78ee48d89762fb3188ac",
"spent_by": "892fd7b36c1c3a2e5edb9b4a5d4ffd9ba74d78d3acf3b249991bd8d10a287dbd",
"addresses": [
"CEztKBAYNoUEEaPYbkyFeXC5v8Jz9RoZH9"
],
"script_type": "pay-to-pubkey-hash"
}
]
}
这里一切看起来都不错。所以我尝试使用 /txs/push
,这次,通过 cURL 收集 return 中的错误消息:
curl -d '{"tx":"01000000011935b41d12936df99d322ac8972b74ecff7b79408bbccaf1b2eb8015228beac8000000006b483045022100921fc36b911094
280f07d8504a80fbab9b823a25f102e2bc69b14bcd369dfc7902200d07067d47f040e724b556e5bc3061af132d5a47bd96e901429d53c41e0f8cca012102152e2bb5b273561ece7bbe8b1d
f51a4c44f5ab0bc940c105045e2cc77e618044ffffffff0240420f00000000001976a9145fb1af31edd2aa5a2bbaa24f6043d6ec31f7e63288ac20da3c00000000001976a914efec6de6c2
53e657a9d5506a78ee48d89762fb3188ac00000000"}' https://api.blockcypher.com/v1/bcy/test/txs/push
{"error": "Error validating transaction: Transaction with hash 4e6dfb1415b4fba5bd257c129847c70fbd4e45e41828079c4a282680528f3a50 already exists.."}
果然,根据该错误消息,该交易已经存在于我们的内部测试网上,如下所示:
我认为您正在尝试推送一个已推送的原始交易。如果您想测试交易创建,我建议您在我们的测试网上生成您自己的地址:
http://dev.blockcypher.com/#generate-address-endpoint
您可以使用我们的水龙头将一些硬币发送到这些地址:
http://dev.blockcypher.com/#testing (或通过此处的 Web 界面:https://accounts.blockcypher.com/blockcypher-faucet)。
然后按照 "Creating Transactions" 中列出的步骤进行操作:
http://dev.blockcypher.com/#creating-transactions
希望对您有所帮助!