Bitcoin Forum
May 04, 2024, 03:10:20 AM *
News: Latest Bitcoin Core release: 27.0 [Torrent]
 
   Home   Help Search Login Register More  
Pages: [1]
  Print  
Author Topic: BTC Testnet Raw Transaction Errors  (Read 215 times)
copyleft (OP)
Newbie
*
Offline Offline

Activity: 13
Merit: 9


View Profile
August 14, 2019, 01:51:59 AM
Merited by LoyceV (2), bones261 (2), ABCbits (1)
 #1

I'll share all relevant info, since it's all worthless testnet coins:

payment_inputs=[#<OpenStruct transaction_id="7bb973e66038b376d8b5b64a891db03b85d9f4978a24186395ec2643a137668f">], payment_outputs=[#<OpenStruct amount="0.05494782", address="bc1qh2wlcrg7rmqrd8nj5et42xh9klys98d2r0p7j0">], raw_transaction="01000000018f6637a14326ec956318248a97f4d9853bb01d894ab6b5d876b33860e673b97b00000 00000ffffffff01fed7530000000000160014ba9dfc0d1e1ec0369e72a657551ae5b7c9029daa00 000000"

receiver: seg_wit_address="bc1qh2wlcrg7rmqrd8nj5et42xh9klys98d2r0p7j0", balance="0", redeem_script="ba9dfc0d1e1ec0369e72a657551ae5b7c9029daa", private_key="54cb6d244094962be43a9aab3ebbfb14d73bb5757b4ff15fe21cbb846a58202b", public_key="0299e5048b940577eec52b298c8d91381c664e4db73d84d6780ee9f239fc0de19c", wif="cQRXmeFjXGHYVpbVV1Fu2xBev8bWu3TVzE7yYUPfVNZHrRZVyLLD", address="

sender wif: cVP1vgAKueUBEgDhbE9zS3yMP6ut4fqAFyCjmGsbZYeNjzR6Yxs5

signed_hex: 01000000018f6637a14326ec956318248a97f4d9853bb01d894ab6b5d876b33860e673b97b00000 0006a47304402203f376cc09a99e4653fc42125b3795aa7dbd7a4c71d4c43c2a77003db1cc192ef 0220084016363f9aef29072a098607d679d7525b8bf51828ef47ecba1b3e3bdcfe870121022f5d9 6fa55a9edc93f0a4080c992272a6e086930937018be3534289914ff37d4ffffffff01fed7530000 000000160014ba9dfc0d1e1ec0369e72a657551ae5b7c9029daa00000000

Tried pushing on blockcypher via API & GUI with no luck. Also tried manually inputting these values into coinb.in (which is where the code for generating these ids, etc is even from). No luck there either (plus no broadcasting to BTC testnet on coinbin).


on blockcypher: Error validating transaction: Transaction 9d0225db198a6470663e3f26653e215ea7eb773db1efe42fe6f213a6baf15ec5 orphaned, missing reference 0d764dc6312ff23808d23b5b7422a6d05999fd99b7b8b7b7f7624239940da2b8.

on bitpay: An error occured: Missing inputs. Code:-25

I stocked both addresses with some testnet BTC, you can check the balances on blockcypher.


Any tips of what I'm missing here?
1714792220
Hero Member
*
Offline Offline

Posts: 1714792220

View Profile Personal Message (Offline)

Ignore
1714792220
Reply with quote  #2

1714792220
Report to moderator
1714792220
Hero Member
*
Offline Offline

Posts: 1714792220

View Profile Personal Message (Offline)

Ignore
1714792220
Reply with quote  #2

1714792220
Report to moderator
1714792220
Hero Member
*
Offline Offline

Posts: 1714792220

View Profile Personal Message (Offline)

Ignore
1714792220
Reply with quote  #2

1714792220
Report to moderator
Bitcoin mining is now a specialized and very risky industry, just like gold mining. Amateur miners are unlikely to make much money, and may even lose money. Bitcoin is much more than just mining, though!
Advertised sites are not endorsed by the Bitcoin Forum. They may be unsafe, untrustworthy, or illegal in your jurisdiction.
achow101
Moderator
Legendary
*
Offline Offline

Activity: 3388
Merit: 6578


Just writing some code


View Profile WWW
August 14, 2019, 03:01:01 AM
Merited by dbshck (4), bones261 (2), ABCbits (1)
 #2

The transaction that you are trying to spend from does not exist. I tried to look up the transaction 7bb973e66038b376d8b5b64a891db03b85d9f4978a24186395ec2643a137668f and it's byteswapped form (8f6637a14326ec956318248a97f4d9853bb01d894ab6b5d876b33860e673b97b) and neither gave any results in my testnet node. That transaction doesn't exist, so your transaction is invalid.

copyleft (OP)
Newbie
*
Offline Offline

Activity: 13
Merit: 9


View Profile
August 14, 2019, 03:19:47 AM
 #3

Thanks for the information.

Currently, I'm genearting a random SHA256 ID for the transaction ID part of coinb.in... is that not he way to go

How would I go about "creating" the transaction?

sorry for the super noob query
nc50lc
Legendary
*
Offline Offline

Activity: 2408
Merit: 5583


Self-proclaimed Genius


View Profile
August 14, 2019, 03:27:41 AM
Merited by lighpulsar07 (16), dbshck (4), bones261 (2), ABCbits (1)
 #4

If the sender's WIF private key is: cVP1vgAKueUBEgDhbE9zS3yMP6ut4fqAFyCjmGsbZYeNjzR6Yxs5, the address must be: mwz7WAKZLZZQJYANfRX6zN2AQ7fvewU81z with a balance of 0.25893246 BTC from this TXID: 1b461714a9255b4b4529823b6a5c9e42accb8aadf740869b0ad23c8fc517bfb6<- use this TXID instead.

Aside from the above, you're trying to send to a non-testnet Bitcoin SegWit address: bc1qh2wlcrg7rmqrd8nj5et42xh9klys98d2r0p7j0
which resulted on your signed transaction having a "null" output:

Did you created that TX using a tool that creates Bitcoin transactions?
If yes, use the one designed for testnet and use the correct input(s).

Your signed hex (Decoded):
Code:
{
    "addresses": [],
    "block_height": -1,
    "block_index": -1,
    "confirmations": 0,
    "double_spend": false,
    "fees": 0,
    "hash": "5c9bf0e773612c625f97e011e70b4aafbd88576d6f6c4dfb74435df288d8e33b",
    "inputs": [
        {
            "age": 0,
            "output_index": 0,
            "prev_hash": "7bb973e66038b376d8b5b64a891db03b85d9f4978a24186395ec2643a137668f",
            "script": -snip-
            "script_type": "empty",
            "sequence": 4294967295
        }
    ],
    "outputs": [
        {
            "addresses": null,
            "script": "0014ba9dfc0d1e1ec0369e72a657551ae5b7c9029daa",
            "script_type": "pay-to-witness-pubkey-hash",
            "value": 5494782
-snip-

.
.HUGE.
▄██████████▄▄
▄█████████████████▄
▄█████████████████████▄
▄███████████████████████▄
▄█████████████████████████▄
███████▌██▌▐██▐██▐████▄███
████▐██▐████▌██▌██▌██▌██
█████▀███▀███▀▐██▐██▐█████

▀█████████████████████████▀

▀███████████████████████▀

▀█████████████████████▀

▀█████████████████▀

▀██████████▀▀
█▀▀▀▀











█▄▄▄▄
▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀
.
CASINSPORTSBOOK
▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄
▀▀▀▀█











▄▄▄▄█
copyleft (OP)
Newbie
*
Offline Offline

Activity: 13
Merit: 9


View Profile
August 14, 2019, 03:58:48 AM
 #5

Ahhh, so as a rule of thumb, should I use the last prior transaction ID of a given address, when generating new transactions?

say, even if it was once where the address was the sender?

& yeah, I'm using coinbin's js code on a node api server.  the normal address for that segwit address is mxXhEhGuZj3NXDaRGqcF1hNr4WrXHwkZWr, also with some testnet coins on it.
pooya87
Legendary
*
Offline Offline

Activity: 3444
Merit: 10537



View Profile
August 14, 2019, 04:01:22 AM
 #6

Currently, I'm genearting a random SHA256 ID for the transaction ID part of coinb.in... is that not he way to go

you can't go to the bank's safety deposit box room, select a random box and try to open that with your key.
it is similar in bitcoin too. think of the blockchain as that room and these transaction outputs as your "box". and the key is your private key. your key can only unlock the transaction that belongs to it not something else.

in fact the output script (aka scriptpub) is also called the "locking script" because what you do when spending that output is that you provide the "unlocking script" which is usually your signature and public key in your scriptsig script. the transaction ID you include in your TX_In is like the pointer to that previous transaction that created that locking script. so you have to provide the correct one.

.
.BLACKJACK ♠ FUN.
█████████
██████████████
████████████
█████████████████
████████████████▄▄
░█████████████▀░▀▀
██████████████████
░██████████████
████████████████
░██████████████
████████████
███████████████░██
██████████
CRYPTO CASINO &
SPORTS BETTING
▄▄███████▄▄
▄███████████████▄
███████████████████
█████████████████████
███████████████████████
█████████████████████████
█████████████████████████
█████████████████████████
███████████████████████
█████████████████████
███████████████████
▀███████████████▀
█████████
.
copyleft (OP)
Newbie
*
Offline Offline

Activity: 13
Merit: 9


View Profile
August 14, 2019, 04:07:43 AM
 #7

I see, great explanation.

I tried using the coinb.in GUI again, following you guys' advice to use the last transaction ID and the proper testnet address:

0100000001b6bf17c58f3cd20a9b8640f7ad8acbac429e5c6a3b8229454b5b25a91417461b00000 0006a473044022052c612a87add0b0aa0fdc4f6a49e24c021e03e91d15fc15c523b6f7ea51f0eb3 0220660fb3de7def0be95e3b923eeacec61c1530a95b33e17c1623cb8ec653bd53240121022f5d9 6fa55a9edc93f0a4080c992272a6e086930937018be3534289914ff37d4ffffffff01002d310100 0000001976a914ba9dfc0d1e1ec0369e72a657551ae5b7c9029daa88ac00000000

doesn't work for me on blockcypher, which is what I'm trying to use to broadcast the signed hex
copyleft (OP)
Newbie
*
Offline Offline

Activity: 13
Merit: 9


View Profile
August 14, 2019, 04:25:18 AM
 #8

Okay, how would I go about finding this key for a given transaction id?

is there an api or tool that does this? or even a bitcoind command?

if I understand correctly, I'm supposed to give that ID + this unlock script: 76a914b4a4ee3ae0d7816333efa3c12c14e345501b0bc588ac?

how would  retrieve the unlock script from a given tx_id?

Gotta wrap my head around this
pooya87
Legendary
*
Offline Offline

Activity: 3444
Merit: 10537



View Profile
August 14, 2019, 04:50:18 AM
Merited by bones261 (2)
 #9

sorry, in my previous post i made the mistake of hashing the wrong thing as public key (forgot to remove the push data OP code). i removed the post right away but it seems i wasn't fast enough.
your public key is indeed correct and the hash is "b4a4ee3ae0d7816333efa3c12c14e345501b0bc5" but your signature is not valid.
broadcasting it with Electrum also gives the same error on OP_CHECKSIG operation step.

in order to sign with bitcoin core, the console method i know of is to use the signrawtransactionwithkey command in your console. you should provide your transaction that needs signing:
Code:
0100000001b6bf17c58f3cd20a9b8640f7ad8acbac429e5c6a3b8229454b5b25a91417461b000000001976a914b4a4ee3ae0d7816333efa3c12c14e345501b0bc588acffffffff01002d3101000000001976a914ba9dfc0d1e1ec0369e72a657551ae5b7c9029daa88ac0000000001000000
your private key
Code:
cVP1vgAKueUBEgDhbE9zS3yMP6ut4fqAFyCjmGsbZYeNjzR6Yxs5
your previous tranasction you are spending in this format:
Code:
'[{"txid":"1b461714a9255b4b4529823b6a5c9e42accb8aadf740869b0ad23c8fc517bfb6","vout":0, "scriptPubKey":"76a914b4a4ee3ae0d7816333efa3c12c14e345501b0bc588ac"}]' 

.
.BLACKJACK ♠ FUN.
█████████
██████████████
████████████
█████████████████
████████████████▄▄
░█████████████▀░▀▀
██████████████████
░██████████████
████████████████
░██████████████
████████████
███████████████░██
██████████
CRYPTO CASINO &
SPORTS BETTING
▄▄███████▄▄
▄███████████████▄
███████████████████
█████████████████████
███████████████████████
█████████████████████████
█████████████████████████
█████████████████████████
███████████████████████
█████████████████████
███████████████████
▀███████████████▀
█████████
.
copyleft (OP)
Newbie
*
Offline Offline

Activity: 13
Merit: 9


View Profile
August 14, 2019, 03:02:02 PM
Last edit: August 14, 2019, 03:43:06 PM by copyleft
 #10

sorry, in my previous post i made the mistake of hashing the wrong thing as public key (forgot to remove the push data OP code). i removed the post right away but it seems i wasn't fast enough.
your public key is indeed correct and the hash is "b4a4ee3ae0d7816333efa3c12c14e345501b0bc5" but your signature is not valid.
broadcasting it with Electrum also gives the same error on OP_CHECKSIG operation step.

in order to sign with bitcoin core, the console method i know of is to use the signrawtransactionwithkey command in your console. you should provide your transaction that needs signing:
Code:
0100000001b6bf17c58f3cd20a9b8640f7ad8acbac429e5c6a3b8229454b5b25a91417461b000000001976a914b4a4ee3ae0d7816333efa3c12c14e345501b0bc588acffffffff01002d3101000000001976a914ba9dfc0d1e1ec0369e72a657551ae5b7c9029daa88ac0000000001000000
your private key
Code:
cVP1vgAKueUBEgDhbE9zS3yMP6ut4fqAFyCjmGsbZYeNjzR6Yxs5
your previous tranasction you are spending in this format:
Code:
'[{"txid":"1b461714a9255b4b4529823b6a5c9e42accb8aadf740869b0ad23c8fc517bfb6","vout":0, "scriptPubKey":"76a914b4a4ee3ae0d7816333efa3c12c14e345501b0bc588ac"}]' 

I was able to figure it out, final question: https://api.blockcypher.com/v1/btc/test3/txs/372f6c0ce5f54d64675f79d58916d492e691507f655d0a1765ce6ed9b90ee9c6

I got the decoded tx_hex from chain.so: 0100000001b6bf17c58f3cd20a9b8640f7ad8acbac429e5c6a3b8229454b5b25a91417461b00000 0006b48304502210091e338c62140e64f8a9786f2fff4ae5dce4c9f9a20f117585f19e382628f80 7d022012ef082eb8e8dcb85b39ea4fba65c6724e24cd45457b29bac52d528b9b7668b40121022f5 d96fa55a9edc93f0a4080c992272a6e086930937018be3534289914ff37d4ffffffff0218293101 000000001976a914ba9dfc0d1e1ec0369e72a657551ae5b7c9029daa88ac7eec590000000000197 6a914b4a4ee3ae0d7816333efa3c12c14e345501b0bc588ac00000000

any programmatic way to extract the scriptPubKey for this transaction?

How can I find the scriptPubKey to use for a given transaction? So i can get the current balance and needed txout & scriptPubKey to unlock it?
pooya87
Legendary
*
Offline Offline

Activity: 3444
Merit: 10537



View Profile
August 14, 2019, 04:27:00 PM
 #11

any programmatic way to extract the scriptPubKey for this transaction?

How can I find the scriptPubKey to use for a given transaction? So i can get the current balance and needed txout & scriptPubKey to unlock it?

"programmatically" you have to first deserialize this transaction (the bytes) into a transaction object then get whatever fields you want. to do that, you basically start from first byte and read on, how many bytes you read depends on what you are reading or the first byte usually tells you how many more bytes you should read afterwards. for example staring at the beginning we always have 4 bytes that is the tx version (as a contract we already know the length is 4):
"01000000" then we have a variable length integer that will tell us the number of inputs to read (read more about CompactInt from the link below): "01" which is 1, then that number of inputs should be read. each input starts with 32 byte tx_hash (again we know hashes are 32 bytes) of the transaction that is being spent (in actual byte order which is the reverse of TX_ID) "b6bf17c58f3cd20a9b8640f7ad8acbac429e5c6a3b8229454b5b25a91417461b" then the index of it "0000000"
<and so on....>
read the rest of the parts i didn't mention here: https://bitcoin.org/en/developer-reference#raw-transaction-format

after you deserialized it, to get the ScriptPubkey from previous transaction you just have to look at your Tx_In: Tx_in[0].Outpoint.hash and Tx_in[0].Outpoint.index then simply lookup the hash in the database (local blockchain or using an online block explorer, and remember transaction IDs in hex are in reverse compared hashes in byte!) after finding the transaction you look into their Tx_outs: tx_out[Tx_in[0].Outpoint.index].pk_script and tx_out[Tx_in[0].Outpoint.index].value
the square bracket is indicating array index access arr[0] is first item of array, arr[1] second,...

.
.BLACKJACK ♠ FUN.
█████████
██████████████
████████████
█████████████████
████████████████▄▄
░█████████████▀░▀▀
██████████████████
░██████████████
████████████████
░██████████████
████████████
███████████████░██
██████████
CRYPTO CASINO &
SPORTS BETTING
▄▄███████▄▄
▄███████████████▄
███████████████████
█████████████████████
███████████████████████
█████████████████████████
█████████████████████████
█████████████████████████
███████████████████████
█████████████████████
███████████████████
▀███████████████▀
█████████
.
copyleft (OP)
Newbie
*
Offline Offline

Activity: 13
Merit: 9


View Profile
August 14, 2019, 06:09:03 PM
 #12

Thanks for that explanation.

While coinb.in/crypto.js (from google) has a method to do this, I've decided to use chain.so: https://chain.so/api/v2/get_tx_unspent/BTCTEST/mxXhEhGuZj3NXDaRGqcF1hNr4WrXHwkZWr

but I'll bookmark this (in case the API is down & I need to do it manually)
Pages: [1]
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.19 | SMF © 2006-2009, Simple Machines Valid XHTML 1.0! Valid CSS!