Closed aitorjs closed 3 years ago
Your address is a p2sh-p2wpkh, not a p2pkh.
Please see the integration tests for an example.
Thanks for the fast reply :-)
¿Are you speaking about this [0] integration test?
I try to use the code but I have ended up breaking my head, especially with regtestUtils, without any result.
Next. I try with TransactionBuilder instead of PSBT because the tests are much more clear there. I use this tests [1]. Same validation error trying to broadcast the transaction with this hex : 02000000000101c37f8d95a75bd9c36c5e71f7a9eac6806099ae85eb806009a92bec9fce3d99580000000017160014d0563341a19c68839cc560a647f84583218842feffffffff01204e00000000000017a91468568c8e852f81ccc8503abe3d140e0aaba506328702473044022007dd261b865d2e0c92e9e420e997061f878e4b40458564e7ce8d1313742027d102201bc92583f826f2b0094e18356dfeb15e26907bac8bc98bc1917845f1456439080121022761f7b06edd78c2c0aaf6f222da02b5b7668269f42467fcd4cff7cfb26eb64000000000
and this code:
const unspent = {
"txId": "58993dce9fec2ba9096080eb85ae996080c6eaa9f7715e6cc3d95ba7958d7fc3",
"vout": 0
}
const keyPair = ECPair.fromWIF(
'cQVWFq9CMaFtUPrYat4by6JQuWDoiSB2uzJR84nzDmdUBkkY6YTM',
TESTNET
)
const p2wpkh = payments.p2wpkh({ pubkey: keyPair.publicKey, network: TESTNET })
const p2sh = payments.p2sh({ redeem: p2wpkh, network: TESTNET })
const txb = new TransactionBuilder(TESTNET)
txb.addInput(unspent.txId, unspent.vout)
txb.addOutput('2N2kuwmUqaYm3iifDrrxXQW6oW2uGX46Pf6', 2e4)
txb.sign(0, keyPair, p2sh.redeem.output, null, 10000)
const tx = txb.build().toHex()
Meanwhile, I try this with bitcoin-cli and I get the valid hex mainly using this command: bitcoin-cli -named createrawtransaction inputs='''[ { "txid": "'$utxo_txid'", "vout": '$utxo_vout' } ]''' outputs='''{ "data": "'$op_return_data'", "'$changeaddress'": 0.09123014 }'''
[2]
Thank you very much! :-D
[0] https://github.com/bitcoinjs/bitcoinjs-lib/blob/master/test/integration/transactions.spec.ts#L241 [1] https://github.com/bitcoinjs/bitcoinjs-lib/blob/582727f6de251441c75027a6292699b6f1e1b8f2/test/integration/transactions.js#L136 [2] https://live.blockcypher.com/btc-testnet/tx/e8cd0001a0e91e49fcb9490170401700aa73558b9e8bebdb84561fa8be7d2042/
Hello!
Having this code:
I get this hexadecimal,
0200000001c37f8d95a75bd9c36c5e71f7a9eac6806099ae85eb806009a92bec9fce3d9958000000006b48304502210085b7074689d0ce164a65a8d2d23ed3a194dad8d549ba4f8625869a4f9778281a02201237b0ebe2e0ee11d6abdf8ae1dc71a23b2f9c92cbdbc1fe7cb4b7f1ab39d8ff0121022761f7b06edd78c2c0aaf6f222da02b5b7668269f42467fcd4cff7cfb26eb640ffffffff0120a107000000000017a91468568c8e852f81ccc8503abe3d140e0aaba506328700000000
When I send using blockcypher to the network, I get this validation error:
Error validating transaction: Error running script for input 0 referencing 58993dce9fec2ba9096080eb85ae996080c6eaa9f7715e6cc3d95ba7958d7fc3 at 0: Script was NOT verified successfully..
If I try to get the address of the WIF private key I'm using, I get a different address:
I dont know if the WIF is the problem to get the validation error I get, the type of UTXO or something else.
¿Any ideas please?
Thank you very much :)
UTXOs for "2N8K8uf9ND1fQGxZdBUb9whd73Ukwi8ZEJu" :