bitcoinjs / bitcoinjs-lib

A javascript Bitcoin library for node.js and browsers.
MIT License
5.71k stars 2.11k forks source link

[BlockCypher bug] Error validating generated transaction: Error running script for input 0 referencing #1707

Closed bug-hunta closed 3 years ago

bug-hunta commented 3 years ago
Please I need some help to know what I am not doing right

$url ="https://api.blockcypher.com/v1/bcy/test/txs/send?token=$token";

---------------------------------------------
This is my testing  address and keys
-------------------------------------------
{
    "private": "8a2d2db1481e7c45eccab3f635851aee51d15e50188ffe9aa0998e3409b4d73a",
    "public": "024328381dafc02b2ebe1802387b39fda687f17a81a6c35840e5cdd11a3596990b",
    "address": "bcy1qcwnkl592c4a5650cmg4dryr09smry7fdjk238h",
    "wif": "BsxdN9gfTYynvkKsMyrQizyYmTHwnkCWZyYyBzMNQKy2g78YzYse"
}

---------------------------------------------
Request params:
-------------------------------------------

{
    "tx": {
        "block_height": -1,
        "block_index": -1,
        "hash": "6120c224b81b9699c215e189012d9bfd41ea10334fc6f421f86429dc344e14e6",
        "addresses": [
            "bcy1qcwnkl592c4a5650cmg4dryr09smry7fdjk238h",
            "bcy1q0rq97nlz3u0t5mly97q9vull6hn64l9gpr82u0"
        ],
        "total": 1000,
        "fees": 9000,
        "size": 116,
        "vsize": 116,
        "preference": "medium",
        "relayed_by": "154.160.11.118",
        "received": "2021-07-14T22:43:58.272715885Z",
        "ver": 1,
        "double_spend": false,
        "vin_sz": 1,
        "vout_sz": 1,
        "confirmations": 0,
        "inputs": [
            {
                "prev_hash": "a889af495c250d0e0838c0f299f78354e0997289590d1a73e9647fc014a52a7f",
                "output_index": 0,
                "output_value": 10000,
                "sequence": 4294967295,
                "addresses": [
                    "bcy1qcwnkl592c4a5650cmg4dryr09smry7fdjk238h"
                ],
                "script_type": "pay-to-witness-pubkey-hash",
                "age": 3469890
            }
        ],
        "outputs": [
            {
                "value": 1000,
                "script": "001478c05f4fe28f1eba6fe42f805673ffd5e7aafca8",
                "addresses": [
                    "bcy1q0rq97nlz3u0t5mly97q9vull6hn64l9gpr82u0"
                ],
                "script_type": "pay-to-witness-pubkey-hash"
            }
        ]
    },
    "tosign": [
        "631107618da27de89e18d6928ca3cec39cb876fb536ca143fab3497f97c010f9"
    ],
    "signatures": [
        "3045022100c7449a84b76dbcef176be03d26d295962f8c06044106dbfc33280b0f0e9a275e02202124b5949b9c379cec05e0facb65d9e0c52b56987939dd736c12fd80a9986086"
    ],
    "pubkeys": [
        "024328381dafc02b2ebe1802387b39fda687f17a81a6c35840e5cdd11a3596990b"
    ]
}

---------------------------------------------
Responses:
-------------------------------------------

{
    "errors": [
        {
            "error": "`Error validating generated transaction: Error running script for input 0 referencing` a889af495c250d0e0838c0f299f78354e0997289590d1a73e9647fc014a52a7f at 0: Script was NOT verified successfully."
        }
    ],
    "tx": {
        "block_height": -1,
        "block_index": -1,
        "hash": "6120c224b81b9699c215e189012d9bfd41ea10334fc6f421f86429dc344e14e6",
        "addresses": [
            "bcy1qcwnkl592c4a5650cmg4dryr09smry7fdjk238h",
            "bcy1q0rq97nlz3u0t5mly97q9vull6hn64l9gpr82u0"
        ],
        "total": 1000,
        "fees": 9000,
        "size": 191,
        "vsize": 110,
        "preference": "medium",
        "relayed_by": "154.160.11.118",
        "received": "2021-07-14T22:43:59.196339381Z",
        "ver": 1,
        "double_spend": false,
        "vin_sz": 1,
        "vout_sz": 1,
        "confirmations": 0,
        "inputs": [
            {
                "prev_hash": "a889af495c250d0e0838c0f299f78354e0997289590d1a73e9647fc014a52a7f",
                "output_index": 0,
                "output_value": 10000,
                "sequence": 4294967295,
                "addresses": [
                    "bcy1qcwnkl592c4a5650cmg4dryr09smry7fdjk238h"
                ],
                "script_type": "pay-to-witness-pubkey-hash",
                "age": 3469890,
                "witness": [
                    "3045022100c7449a84b76dbcef176be03d26d295962f8c06044106dbfc33280b0f0e9a275e02202124b5949b9c379cec05e0facb65d9e0c52b56987939dd736c12fd80a9986086",
                    "024328381dafc02b2ebe1802387b39fda687f17a81a6c35840e5cdd11a3596990b"
                ]
            }
        ],
        "outputs": [
            {
                "value": 1000,
                "script": "001478c05f4fe28f1eba6fe42f805673ffd5e7aafca8",
                "addresses": [
                    "bcy1q0rq97nlz3u0t5mly97q9vull6hn64l9gpr82u0"
                ],
                "script_type": "pay-to-witness-pubkey-hash"
            }
        ]
    },
    "tosign": [
        ""
    ]
}
bug-hunta commented 3 years ago

I have ressolved the issue.

Solution:

I was using bech32 address, So all I needed to do was to append "01" or it's defined constant "SIGHASH_ALL" to the end of the signature

"signatures":["304502210092f180db9348d8ba99d76628a61b43fe5ab0d5797334670615c1e1cd9ad9799e022049227e343174dfaa5ff215955128a0b23255c59b284268ee22a520d52162bd6601"]

If you are using a bech32 address (starting with bc1) be sure to add "01 (SIGHASH_ALL) " at the end of the signature.

BEFORE ( ERROR: didn't add "01" to the end of the signatures array value(s) ) "signatures": [ "3045022100c7449a84b76dbcef176be03d26d295962f8c06044106dbfc33280b0f0e9a275e02202124b5949b9c379cec05e0facb65d9e0c52b56987939dd736c12fd80a9986086" ],

AFTER ( SOLUTION : adding "01" to the end of the signatures array value(s) ) "signatures": [ "3045022100c7449a84b76dbcef176be03d26d295962f8c06044106dbfc33280b0f0e9a275e02202124b5949b9c379cec05e0facb65d9e0c52b56987939dd736c12fd80a998608601" ],

skullpunks commented 1 year ago

I am using bech32 address and my signature have 01 at the end but still same error. { error: 'Error validating generated transaction: Error running script for input 0 referencing f58c711f9fce2b1417503d0f21d356c637961515a0b32838bfeacccec629 5a25 at 14: Script was NOT verified successfully.' } Any help appreciated.

tosign: [ '5f7bfb0fc5c32c68a4545ea914a8d621f02d3b6b42e2d168afaa293474d3d393', '0f5ed66f6c029738ab0ee6ef38770d8d953b2cd3a246f73f8daad8987a1f46d7' ], pubkeys: [ '027531438e9f3aaa5263f909bd5648258b3aaeea8edfe1e5f6cacb5a359a97401c', '027531438e9f3aaa5263f909bd5648258b3aaeea8edfe1e5f6cacb5a359a97401c' ], signatures: [ '304402206c0a4b61c823ec777f39ba7c7ce4f48b048b8273bca5fcc6ea52efeffeb8791a02201ae94f4a9e4949d111153d0bf93c440bb4d5236182169540bf16259e0db09eab01', '3044022064044d560424cae7486c374c6e2e2f2c566fa7cd47aaf5a87eaefef80b88264c02203c5068eb828be41c0014756578b946aa0f6845cdb9fa9f1965d54f34c3f34ba201' ]

bug-hunta commented 1 year ago

@skullpunks Sorry for the late reply. I would appreciate it if you contact me privately so we can schedule a google or zoom c all to help you with your issue. Contact me on prncfoli@gmail.com.

meokashif commented 5 months ago

@skullpunks is your issue resolved? I'm facing the same issue, have added 01 at the end of the signature but still facing the same issue?