blockcypher / php-client

PHP wrapper for the BlockCypher APIs
Apache License 2.0
51 stars 85 forks source link

Can't Send Transaction [Script was NOT verified successfully] #35

Closed gomesandre closed 4 years ago

gomesandre commented 7 years ago

I'm having trouble to send a Transaction. I can create and sign it, but I keep getting errors. I believe I'm using the right format:

{ "tx":{...}, "tosign":[""], "pubkeys":[""], "signatures":[""] }

I'm using Laravel and when I try to send it on my locally I keep getting this error:

Error validating transaction: Error running script for input 0 referencing 673b22837a967de87489e60de0bc3477eeb63ae54b65b2f9fca414e5c3111e39 at 0: Script was NOT verified successfully.

When I try in production I get this error:

Not enough signatures: 1 for 4 inputs

But I'm passing the data exactly like in the docs. The strange thing in all of this is that the same code was working perfectly before. Suddenly I've started to get this error.

Please help me. Grateful.

josecelano commented 7 years ago

Hi @gomesandre could you please try to reproduce the problem with BlockCyher Tesnet addresses and paste here the request/reponse to the API? And also the sample code you are using. You can use one of the samples provided in the sample https://github.com/blockcypher/php-client/tree/master/sample folder.

The problem could be: uncompressed keys or missing private keys for some inputs.

suneelkumar91 commented 6 years ago

@josecelano below find the response i have got using blockcypher api.. Kindly look into this and help me out of this problem:

BlockCypher::Api::Error: https://api.blockcypher.com/v1/btc/test3/txs/send?token=db62a181113d4acd9d50b1234f216b39 Response:{ "errors": [ { "error": "Error validating generated transaction: Error running script for input 0 referencing 36c6f9bbcd13a87bb37dfb2841005aa8c770496103e76b0f24bb2ebc74d44a10 at 0: Script was NOT verified successfully." } ], "tx": { "block_height": -1, "block_index": -1, "hash": "121f0be56a15a1217eb25180b9adbd72b07167c8445ab99c52d9f84494d6a00c", "addresses": [ "mte4zRKEcvqUzZPfH9hrM4BbwdShQrF8Wb", "mip7Wd2CvNjFsDAHwusEGJLWc7hUKKxPHc" ], "total": 129895900, "fees": 104100, "size": 225, "preference": "high", "relayed_by": "117.20.16.30", "received": "2017-12-19T13:28:44.829077264Z", "ver": 1, "double_spend": false, "vin_sz": 1, "vout_sz": 2, "confirmations": 0, "inputs": [ { "prev_hash": "36c6f9bbcd13a87bb37dfb2841005aa8c770496103e76b0f24bb2ebc74d44a10", "output_index": 0, "script": "473044022010d6cad4fe3c788b1aa89c8b4a9c3a2a948606022e42aa4bfc1e1d7e4bace6b1022077aa0194b2d687aa24e50518c1bf9a74fb3ade39da9fba0fd084685f07d433700121020b2156f192916dc681b6573dfba7c4af95a2b0a043d20c1be0e0379d8d59d6b8", "output_value": 130000000, "sequence": 4294967295, "addresses": [ "mte4zRKEcvqUzZPfH9hrM4BbwdShQrF8Wb" ], "script_type": "pay-to-pubkey-hash", "age": 1255372 } ], "outputs": [ { "value": 1000, "script": "76a91424272474a0438978e9d36d9f5a358689592d849088ac", "addresses": [ "mip7Wd2CvNjFsDAHwusEGJLWc7hUKKxPHc" ], "script_type": "pay-to-pubkey-hash" }, { "value": 129894900, "script": "76a9148ff222ed3a193f8abfc532f9ec65a35e1a25371888ac", "addresses": [ "mte4zRKEcvqUzZPfH9hrM4BbwdShQrF8Wb" ], "script_type": "pay-to-pubkey-hash" } ] }, "tosign": [ "" ] } from /home/suneel/rails_projects/crypto-apis/vendor/gems/ruby-client/lib/blockcypher/api.rb:385:inapi_http_call' from /home/suneel/rails_projects/crypto-apis/vendor/gems/ruby-client/lib/blockcypher/api.rb:404:in api_http_post' from /home/suneel/rails_projects/crypto-apis/vendor/gems/ruby-client/lib/blockcypher/api.rb:107:intransaction_sign_and_send' from /home/suneel/rails_projects/crypto-apis/vendor/gems/ruby-client/lib/blockcypher/api.rb:78:in send_money' from (irb):26 from /var/lib/gems/2.3.0/gems/railties-5.0.6/lib/rails/commands/console.rb:65:instart' from /var/lib/gems/2.3.0/gems/railties-5.0.6/lib/rails/commands/console_helper.rb:9:in start' from /var/lib/gems/2.3.0/gems/railties-5.0.6/lib/rails/commands/commands_tasks.rb:78:inconsole' from /var/lib/gems/2.3.0/gems/railties-5.0.6/lib/rails/commands/commands_tasks.rb:49:in run_command!' from /var/lib/gems/2.3.0/gems/railties-5.0.6/lib/rails/commands.rb:18:in<top (required)>' from /var/lib/gems/2.3.0/gems/activesupport-5.0.6/lib/active_support/dependencies.rb:293:in require' from /var/lib/gems/2.3.0/gems/activesupport-5.0.6/lib/active_support/dependencies.rb:293:inblock in require' from /var/lib/gems/2.3.0/gems/activesupport-5.0.6/lib/active_support/dependencies.rb:259:in load_dependency' from /var/lib/gems/2.3.0/gems/activesupport-5.0.6/lib/active_support/dependencies.rb:293:inrequire' from /home/suneel/rails_projects/crypto-apis/bin/rails:9:in <top (required)>' from /var/lib/gems/2.3.0/gems/activesupport-5.0.6/lib/active_support/dependencies.rb:287:inload' from /var/lib/gems/2.3.0/gems/activesupport-5.0.6/lib/active_support/dependencies.rb:287:in block in load' from /var/lib/gems/2.3.0/gems/activesupport-5.0.6/lib/active_support/dependencies.rb:259:inload_dependency' from /var/lib/gems/2.3.0/gems/activesupport-5.0.6/lib/active_support/dependencies.rb:287:in load' from /usr/lib/ruby/2.3.0/rubygems/core_ext/kernel_require.rb:55:inrequire' from /usr/lib/ruby/2.3.0/rubygems/core_ext/kernel_require.rb:55:in require' from -e:1:in

`

soniadao commented 6 years ago

At the last step, when I send the JSON to the blockchain I get this error :

"error": "Error validating generated transaction: Error running script for input 0 referencing 4a9aa1189c6a5d0f770c7a43bf46dc87f0c08ec35c68468212c7e8445900623c at 1: Script was NOT verified successfully."

Can someone help me please ?

jrazer commented 6 years ago

@soniadao something happened? similar error

macsj200 commented 6 years ago

I'm also getting a similar error, but I'm using a request library with NodeJS.

Edit: I was signing with the wrong key. It'd be great if they could make better error messages.

SchulerSimon commented 5 years ago

Same problem, I was referencing the uncompressed key instead of the compressed key, @macsj200 thanks for updating, that helped alot

Quant-Network commented 4 years ago

I'm also getting a similar error, but I'm using a request library with NodeJS.

Edit: I was signing with the wrong key. It'd be great if they could make better error messages.

Hi @macsj200, struggling on this one. The node js example that BlockCypher has is old and no longer working with the newest bitcoinjs-lib version. But I even used the old version of this module and it still does not work... I guess I messed something, but not sure what... Maybe you can spot what's the problem...

keys = bitcoin.ECPair.fromWIF(wif, bitcoin.networks.bitcoin);

tmptx.pubkeys = [];
tmptx.signatures = tmptx.tosign.map(tosign => {
  tmptx.pubkeys.push(keys.getPublicKeyBuffer().toString('hex'));
  return keys.sign(new buffer.Buffer(tosign, 'hex')).toDER().toString('hex');
});

BlockCypher returns an error Script was NOT verified successfully...

quentinlesceller commented 4 years ago

Most of the library are now up to date. Try using v2.0.0-beta.1 and please report back. Thank you!