0

Attempting to use Blockcypher's /txs/send endpoint using detailed here: https://www.blockcypher.com/dev/bitcoin/#creating-transactions and I'm getting the following error:

Error validating generated transaction: Error running script for input 0 referencing 5bf99cd9191700eb9c324a00dee0ac857b804f63c391490d9c21036e4c78ac73 at 0: Script was NOT verified successfully.

Searched far and wide and can't find a reasonable solution.

I generate the transaction successufully and here's a copy of my TX:

"tx": {
        "block_height": -1,
        "block_index": -1,
        "hash": "d64c7acf354b55c69756c4646b100245fe496633b1a5be9a7cc66f4f46cf797e",
        "addresses": [
            "n3nsT38n7k83FL5p7PPvkHgdwJAzA5QBoi",
            "tb1ql7w62elx9ucw4pj5lgw4l028hmuw80sndtntxt"
        ],
        "total": 81172,
        "fees": 29300,
        "size": 223,
        "vsize": 223,
        "preference": "high",
        "relayed_by": "20.185.53.173",
        "received": "2022-04-19T11:58:00.294345726Z",
        "ver": 1,
        "double_spend": false,
        "vin_sz": 2,
        "vout_sz": 2,
        "confirmations": 0,
        "inputs": [
            {
                "prev_hash": "5bf99cd9191700eb9c324a00dee0ac857b804f63c391490d9c21036e4c78ac73",
                "output_index": 0,
                "output_value": 10000,
                "sequence": 4294967295,
                "addresses": [
                    "n3nsT38n7k83FL5p7PPvkHgdwJAzA5QBoi"
                ],
                "script_type": "pay-to-pubkey-hash",
                "age": 2196309
            },
            {
                "prev_hash": "f21f9e457d61ba4fa5858f3a4ba4c37179c12d1275a1bd799f0c0c91d3f15269",
                "output_index": 1,
                "output_value": 100472,
                "sequence": 4294967295,
                "addresses": [
                    "n3nsT38n7k83FL5p7PPvkHgdwJAzA5QBoi"
                ],
                "script_type": "pay-to-pubkey-hash",
                "age": 2196316
            }
        ],
        "outputs": [
            {
                "value": 500,
                "script": "0014ff9da567e62f30ea8654fa1d5fbd47bef8e3be13",
                "addresses": [
                    "tb1ql7w62elx9ucw4pj5lgw4l028hmuw80sndtntxt"
                ],
                "script_type": "pay-to-witness-pubkey-hash"
            },
            {
                "value": 80672,
                "script": "76a914f45560cd98d9a84d6c568bb845db0cef81ed548288ac",
                "addresses": [
                    "n3nsT38n7k83FL5p7PPvkHgdwJAzA5QBoi"
                ],
                "script_type": "pay-to-pubkey-hash"
            }
        ]
    }

tosign:

"tosign": [
        "7a407b770128fd9cd51f95010904f05fecde80202d2fecd2340020d0994ce582",
        "1d03cbac44034426c236268684bedf169beb38210f9857a46086cdade4a9c910"
    ]

signatures:

"signatures": [
        "30450221009f04eccdc41ec135083110b1dcf2ed0edb4c68aefd627820944f9314020faa4e02202337b880a133e22c03df252cf43114158774173229efe2d2d47df6cdc70a610f",
        "3045022100de59d669e38b669b0a0d4451d7a453269da849a202cd325f4923565897d562e002202db8883506cc8f5cd87b6a61cbcfd793dd6107e3a073debf1b4d2b008fcb002e"
    ]

pubkeys:

"pubkeys": [
        "303231393839646331643236333136303662653139396564333261666531636238313362343034353565326462623232303563613962393336356134626232373330",
        "303231393839646331643236333136303662653139396564333261666531636238313362343034353565326462623232303563613962393336356134626232373330"
    ]

Address information (before hex encoding using bin2hex):

"private": "a76b15c0b931b54141f73f127535ae946d45a52872306f7b5eaf3623290a1518",
    "public": "021989dc1d2631606be199ed32afe1cb813b40455e2dbb2205ca9b9365a4bb2730",
    "address": "n3nsT38n7k83FL5p7PPvkHgdwJAzA5QBoi",
    "wif": "cTC98Ng4DP92Mgi34bJADkcDbc5giMMmmcTiSUHQQkEr92MsxYd2"

For context I use the following signing tool provided by them to do the signing:

https://github.com/blockcypher/btcutils/tree/master/signer

It's a go binary which I complie and run by logging in through SSH using phpseclib in the following manner:

protected function create_new_transaction()
{
    $input = [["wallet_name" => $this->wallet_name, "wallet_token" => self::token]];
    $output = [["addresses" => ["$this->destination"], "value" => (int)$this->value]];

    $api_settings = $this->api_settings('/v1/btc/test3/txs/new?token=' . self::token . '&inputs=' . $input . '&outputs=' . $output, 'POST', TRUE, array('token' => self::token, 'inputs' => $input, 'outputs' => $output));
    $result = \GuzzleHttp\json_decode($api_settings, true);

    $to_sign = $result['tosign'];
    $inputs = $result['tx']['inputs'];


    // hex encoded arrays of values
    $public_keys_hex = $private_keys_hex = $addresses_hex = $signatures = array();

    foreach ($inputs as $value) {
        $profile = new Profile();
        $profile->address = $value['addresses'][0];

        $address_lookup = $profile->single_address_lookup();

        if ($address_lookup['status']) {
            array_push($public_keys_hex, bin2hex($address_lookup['address_data'][0]['public_key']));
            array_push($private_keys_hex, bin2hex($address_lookup['address_data'][0]['private_key']));
            array_push($addresses_hex, bin2hex($address_lookup['address_data'][0]['address']));

        } else return [
            'status' => false,
            'message' => 'failed to retrieve address data'
        ];
    }


    foreach ($to_sign as $index => $sign) {
        $signature = $this->sign_payload($sign, $private_keys_hex[$index]);
        array_push($signatures, str_replace("\n", "", $signature));
    }

    $result += ['signatures' => $signatures];
    $result += ['pubkeys' => $public_keys_hex];

    return empty($result) ? [
        'status' => false,
        'message' => "invalid response"
    ] : [
        'status' => true,
        'message' => $result
    ];
}

The actual sign_payload function:

private function sign_payload($to_sign, $private_key)
{
    $ssh = new Net_SSH2('[ip_address]');
    if (!$ssh->login('root', '[password]')) {
        exit('ssh connect failure');
    }

    return $ssh->exec("cd /var/www/vhosts/[domain_name]/httpdocs/btcutils/signer\n./signer " . $to_sign . " " . $private_key);
}

I'm completely lost and I'd appreciate some help regarding this. PS: Tried reaching Blockcypher but they never reply emails, and there's very limited information regarding this online.

On the Blockcypher docs there's this comment:

One of the most common errors we see are users who use uncompressed public keys when compressed public keys were used to generate the address; remember to be careful to use the right keys!

I don't know what that means, and I would like some clarification. Would also like to know if that is causing my issue.

Thanks a lot.

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.