я пытаюсь сделать
sendrawtransaction <transaction_hex>
от nodejs
использования пакета биткойн-ядро, который я сделал
npm install bitcoin-core --save
у меня уже есть последняя bitcoind
установка и работа, rpcusername
и rpcpassword
я настроенbitcoin.conf
мой текущий код выглядит так.
const Client = require('bitcoin-core');
const client = new Client({ username: 'adminuser', password : 'adminpassword'});
client.getInfo((error, help) => console.log(help));
мне удалось получить ответ только отgetInfo
все остальное дает или empty output
или undefined
илиnull
до сих пор я пробовал много вариантов, подобных этим
tx_hex = "0200000001949e0e3ac02fef76dffa8e2191ee0041f71a90c5ec9bbcba77db5f57e49fe6dd010000006b483045022100d6ac8520a1cfe80f6f3c2fbe6c3f903894203715928382e77c3c7ad0de74112502203c14601e5195dde88c9cc16c45dc273af168bd4fd03b6c045f832b7ba0134f8c012102183e719a510ff322fcb0dbfa279ef2500dd87c0b8c6184480846262e1949fbebfeffffff028bec0900000000001976a9141b0c5cb82d59cb2e07e8d5e343167fda48a9d60e88ace2920f00000000001976a9148108670170211830be2c3c557afe6bc2205d27de88ac864a0700"
client.sendRawTransaction((tx_hex,response) => console.log(response));
client.sendRawTransaction((tx_hex) => console.log());
client.sendRawTransaction((tx_hex), function(){console.log()});
но ничего из вышеперечисленного не дает подтверждения или не дает правильного вывода.
что мне здесь не хватает?
я имею в виду, если бы я сделал это, используя bitcoin-cli
терминал, он возвращает txhash
.
например
[root@localhost deploy]# bitcoin-cli sendrawtransaction 0200000001949e0e3ac02fef76dffa8e2191ee0041f71a90c5ec9bbcba77db5f57e49fe6dd010000006b483045022100d6ac8520a1cfe80f6f3c2fbe6c3f903894203715928382e77c3c7ad0de74112502203c14601e5195dde88c9cc16c45dc273af168bd4fd03b6c045f832b7ba0134f8c012102183e719a510ff322fcb0dbfa279ef2500dd87c0b8c6184480846262e1949fbebfeffffff028bec0900000000001976a9141b0c5cb82d59cb2e07e8d5e343167fda48a9d60e88ace2920f00000000001976a9148108670170211830be2c3c557afe6bc2205d27de88ac864a0700
b9ceb300bc4a94dad591d8ecca7e840e7cfafa47c029488424e07666c1e1778b
обновление1:
tx_hex = "0200000001949e0e3ac02fef76dffa8e2191ee0041f71a90c5ec9bbcba77db5f57e49fe6dd010000006b483045022100d6ac8520a1cfe80f6f3c2fbe6c3f903894203715928382e77c3c7ad0de74112502203c14601e5195dde88c9cc16c45dc273af168bd4fd03b6c045f832b7ba0134f8c012102183e719a510ff322fcb0dbfa279ef2500dd87c0b8c6184480846262e1949fbebfeffffff028bec0900000000001976a9141b0c5cb82d59cb2e07e8d5e343167fda48a9d60e88ace2920f00000000001976a9148108670170211830be2c3c557afe6bc2205d27de88ac864a0700"
client.sendRawTransaction((tx_hex,response) => console.log(tx_hex + ':' + response));
возвращается
RpcError: -1 sendrawtransaction "hexstring" ( allowhighfees )
Submits raw transaction (serialized, hex-encoded) to local node and network.
Also see createrawtransaction and signrawtransaction calls.
Arguments:
1. "hexstring" (string, required) The hex string of the raw transaction)
2. allowhighfees (boolean, optional, default=false) Allow high fees
Result:
"hex" (string) The transaction hash in hex
Examples:
Create a transaction
> bitcoin-cli createrawtransaction "[{\"txid\" : \"mytxid\",\"vout\":0}]" "{\"myaddress\":0.01}"
Sign the transaction, and get back the hex
> bitcoin-cli signrawtransaction "myhex"
Send the transaction (signed hex)
> bitcoin-cli sendrawtransaction "signedhex"
As a json rpc call
> curl --user myusername --data-binary '{"jsonrpc": "1.0", "id":"curltest", "method": "sendrawtransaction", "params": ["signedhex"] }' -H 'content-type: text/plain;' http://127.0.0.1:8332/
:undefined
То, как вы передаете параметры, неверно. Я использую код ниже, получил правильный ответ:
const Client = require('bitcoin-core');
const client = new Client({username: 'admin', password: 'password', network: 'testnet'})
const txHex = '0200000001999539009d0d02f2332d257716faa75cc4c9a8318c153ba6a084c719fa33103b000000006a4730440220032470b6b45825fc37d08e1985c7ad2044272edacfa2c76cf49c6b70c09a0dac02202466ede3e660c6d57f65b7ed21f2c1f778116ef92bef9ed2f9b18fcb1881a7b9012103b91ff254ae3bb3861e4a6c16ab356d6c52ccfd2b58bedf0dda84657dfd9d9afcffffffff0130750000000000001976a914ba05ece7632d78336848214b525cfdbd1c4b06a188ac00000000'
client.sendRawTransaction(txHex, (error, response) => {
if (error) console.log(error);
console.log(response);
});