<p>If you haven't had the answer yet, this helped resolved mine
<a href="https://github.com/bitcoinjs/bitcoinjs-lib/issues/1707" rel="nofollow noreferrer">https://github.com/bitcoinjs/bitcoinjs-lib/issues/1707</a></p>

CC BY-SA 4.0
2023-01-29T22:05:00.827Z
2023-01-29T22:05:00.827Z
Effa Amponsh
<p>Attempting to use Blockcypher's <code>/txs/send</code> endpoint using detailed here: <code>https://www.blockcypher.com/dev/bitcoin/#creating-transactions</code> and I'm getting the following error:</p>
<pre><code>Error validating generated transaction: Error running script for input 0 referencing 5bf99cd9191700eb9c324a00dee0ac857b804f63c391490d9c21036e4c78ac73 at 0: Script was NOT verified successfully.
</code></pre>
<p>Searched far and wide and can't find a reasonable solution.</p>
<p>I generate the transaction successufully and here's a copy of my TX:</p>
<pre><code>&quot;tx&quot;: {
        &quot;block_height&quot;: -1,
        &quot;block_index&quot;: -1,
        &quot;hash&quot;: &quot;d64c7acf354b55c69756c4646b100245fe496633b1a5be9a7cc66f4f46cf797e&quot;,
        &quot;addresses&quot;: [
            &quot;n3nsT38n7k83FL5p7PPvkHgdwJAzA5QBoi&quot;,
            &quot;tb1ql7w62elx9ucw4pj5lgw4l028hmuw80sndtntxt&quot;
        ],
        &quot;total&quot;: 81172,
        &quot;fees&quot;: 29300,
        &quot;size&quot;: 223,
        &quot;vsize&quot;: 223,
        &quot;preference&quot;: &quot;high&quot;,
        &quot;relayed_by&quot;: &quot;20.185.53.173&quot;,
        &quot;received&quot;: &quot;2022-04-19T11:58:00.294345726Z&quot;,
        &quot;ver&quot;: 1,
        &quot;double_spend&quot;: false,
        &quot;vin_sz&quot;: 2,
        &quot;vout_sz&quot;: 2,
        &quot;confirmations&quot;: 0,
        &quot;inputs&quot;: [
            {
                &quot;prev_hash&quot;: &quot;5bf99cd9191700eb9c324a00dee0ac857b804f63c391490d9c21036e4c78ac73&quot;,
                &quot;output_index&quot;: 0,
                &quot;output_value&quot;: 10000,
                &quot;sequence&quot;: 4294967295,
                &quot;addresses&quot;: [
                    &quot;n3nsT38n7k83FL5p7PPvkHgdwJAzA5QBoi&quot;
                ],
                &quot;script_type&quot;: &quot;pay-to-pubkey-hash&quot;,
                &quot;age&quot;: 2196309
            },
            {
                &quot;prev_hash&quot;: &quot;f21f9e457d61ba4fa5858f3a4ba4c37179c12d1275a1bd799f0c0c91d3f15269&quot;,
                &quot;output_index&quot;: 1,
                &quot;output_value&quot;: 100472,
                &quot;sequence&quot;: 4294967295,
                &quot;addresses&quot;: [
                    &quot;n3nsT38n7k83FL5p7PPvkHgdwJAzA5QBoi&quot;
                ],
                &quot;script_type&quot;: &quot;pay-to-pubkey-hash&quot;,
                &quot;age&quot;: 2196316
            }
        ],
        &quot;outputs&quot;: [
            {
                &quot;value&quot;: 500,
                &quot;script&quot;: &quot;0014ff9da567e62f30ea8654fa1d5fbd47bef8e3be13&quot;,
                &quot;addresses&quot;: [
                    &quot;tb1ql7w62elx9ucw4pj5lgw4l028hmuw80sndtntxt&quot;
                ],
                &quot;script_type&quot;: &quot;pay-to-witness-pubkey-hash&quot;
            },
            {
                &quot;value&quot;: 80672,
                &quot;script&quot;: &quot;76a914f45560cd98d9a84d6c568bb845db0cef81ed548288ac&quot;,
                &quot;addresses&quot;: [
                    &quot;n3nsT38n7k83FL5p7PPvkHgdwJAzA5QBoi&quot;
                ],
                &quot;script_type&quot;: &quot;pay-to-pubkey-hash&quot;
            }
        ]
    }
</code></pre>
<p>tosign:</p>
<pre><code>&quot;tosign&quot;: [
        &quot;7a407b770128fd9cd51f95010904f05fecde80202d2fecd2340020d0994ce582&quot;,
        &quot;1d03cbac44034426c236268684bedf169beb38210f9857a46086cdade4a9c910&quot;
    ]
</code></pre>
<p>signatures:</p>
<pre><code>&quot;signatures&quot;: [
        &quot;30450221009f04eccdc41ec135083110b1dcf2ed0edb4c68aefd627820944f9314020faa4e02202337b880a133e22c03df252cf43114158774173229efe2d2d47df6cdc70a610f&quot;,
        &quot;3045022100de59d669e38b669b0a0d4451d7a453269da849a202cd325f4923565897d562e002202db8883506cc8f5cd87b6a61cbcfd793dd6107e3a073debf1b4d2b008fcb002e&quot;
    ]
</code></pre>
<p>pubkeys:</p>
<pre><code>&quot;pubkeys&quot;: [
        &quot;303231393839646331643236333136303662653139396564333261666531636238313362343034353565326462623232303563613962393336356134626232373330&quot;,
        &quot;303231393839646331643236333136303662653139396564333261666531636238313362343034353565326462623232303563613962393336356134626232373330&quot;
    ]
</code></pre>
<p>Address information (before hex encoding using <code>bin2hex</code>):</p>
<pre><code>&quot;private&quot;: &quot;a76b15c0b931b54141f73f127535ae946d45a52872306f7b5eaf3623290a1518&quot;,
    &quot;public&quot;: &quot;021989dc1d2631606be199ed32afe1cb813b40455e2dbb2205ca9b9365a4bb2730&quot;,
    &quot;address&quot;: &quot;n3nsT38n7k83FL5p7PPvkHgdwJAzA5QBoi&quot;,
    &quot;wif&quot;: &quot;cTC98Ng4DP92Mgi34bJADkcDbc5giMMmmcTiSUHQQkEr92MsxYd2&quot;
</code></pre>
<p>For context I use the following signing tool provided by them to do the signing:</p>
<pre><code>https://github.com/blockcypher/btcutils/tree/master/signer
</code></pre>
<p>It's a go binary which I complie and run by logging in through SSH using <code>phpseclib</code> in the following manner:</p>
<pre><code>protected function create_new_transaction()
{
    $input = [[&quot;wallet_name&quot; =&gt; $this-&gt;wallet_name, &quot;wallet_token&quot; =&gt; self::token]];
    $output = [[&quot;addresses&quot; =&gt; [&quot;$this-&gt;destination&quot;], &quot;value&quot; =&gt; (int)$this-&gt;value]];

    $api_settings = $this-&gt;api_settings('/v1/btc/test3/txs/new?token=' . self::token . '&amp;inputs=' . $input . '&amp;outputs=' . $output, 'POST', TRUE, array('token' =&gt; self::token, 'inputs' =&gt; $input, 'outputs' =&gt; $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-&gt;address = $value['addresses'][0];

        $address_lookup = $profile-&gt;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' =&gt; false,
            'message' =&gt; 'failed to retrieve address data'
        ];
    }


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

    $result += ['signatures' =&gt; $signatures];
    $result += ['pubkeys' =&gt; $public_keys_hex];

    return empty($result) ? [
        'status' =&gt; false,
        'message' =&gt; &quot;invalid response&quot;
    ] : [
        'status' =&gt; true,
        'message' =&gt; $result
    ];
}
</code></pre>
<p>The actual sign_payload function:</p>
<pre><code>private function sign_payload($to_sign, $private_key)
{
    $ssh = new Net_SSH2('[ip_address]');
    if (!$ssh-&gt;login('root', '[password]')) {
        exit('ssh connect failure');
    }

    return $ssh-&gt;exec(&quot;cd /var/www/vhosts/[domain_name]/httpdocs/btcutils/signer\n./signer &quot; . $to_sign . &quot; &quot; . $private_key);
}
</code></pre>
<p>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.</p>
<p>On the Blockcypher docs there's this comment:</p>
<pre><code>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!
</code></pre>
<p>I don't know what that means, and I would like some clarification. Would also like to know if that is causing my issue.</p>
<p>Thanks a lot.</p>

<bitcoin-core><blockchain><public-key><php><blockcypher>
PHP Blockcypher error validating generated transaction: Error running script for input 0
user627341
# PHP Blockcypher error validating generated transaction: Error running script for input 0

(Asked by: username_0 on 2022-04-19)

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.

**Tags:** bitcoin-core, blockchain, public-key, php, blockcypher


---

## 1 answers

### Answer by username_1 on 2023-01-29. Score: -1

If you haven't had the answer yet, this helped resolved mine
<https://github.com/bitcoinjs/bitcoinjs-lib/issues/1707>


---

