Bitcoin Forum
May 02, 2024, 01:47:23 PM *
News: Latest Bitcoin Core release: 27.0 [Torrent]
 
   Home   Help Search Login Register More  
Pages: [1]
  Print  
Author Topic: Trying to create a raw transaction - noob troubles  (Read 155 times)
DonnyBoy (OP)
Newbie
*
Offline Offline

Activity: 10
Merit: 11


View Profile
November 24, 2019, 01:44:36 PM
 #1

Hi, I've been working on improving my computer skills and thought bitcoin would be a good avenue to learn.

After a long battle, I finally managed to achieve synchronization of my node and have been trying some commands. I tried sending the simplest transaction I could, and much to my amazement, it worked:

bitcoin-cli createrawtransaction "[{\"txid\":\"5894211487d94fs5484a0f64cb56edf8a4fea5a82s1848782e7d55b45cd12472\",\"vout\":0}]" "[{\"1KNt61bXLPTvs5PhL3m4fp71ndqJWBSQ14\":0.0002}]"

The transaction above was easy because it was a single input and required no change. However, I am trying to spice things up first by including a transaction with change, and then one involving multiple inputs. However, I've run into some minor issues when I tried to make things more interesting.

However when I tried to add a change address and value into a similar transaction.

bitcoin-cli createrawtransaction "[{\"txid\":\"37d53f65g0568e3fd1e4auu7f30b4i0758e69o257f649de62b352931e402g7654\",\"vout\":0}]" "[{\"1EmGo9SAoYpoXmYH3Hm4LX8mMsyDxyDCkH \":0.0003, \"3L4kHNBgRPf5u875UhTd6N57sw4gc7vLa \":0.00005}]"

This returned an error:

error code: -8
error message:
Invalid parameter, key-value pair must contain exactly one key


Not sure where I am going wrong because it doesn't seem like a substantial leap from the first transaction to the second...? If anyone can see where I might be going wrong here I would appreciate the input! Also can anyone recommend where I might find some examples of some raw transactions? Doesn't seem to be too many around that I can find :-/

Thanks in advance everyone. I appreciate the community's help as always!
1714657643
Hero Member
*
Offline Offline

Posts: 1714657643

View Profile Personal Message (Offline)

Ignore
1714657643
Reply with quote  #2

1714657643
Report to moderator
Advertised sites are not endorsed by the Bitcoin Forum. They may be unsafe, untrustworthy, or illegal in your jurisdiction.
1714657643
Hero Member
*
Offline Offline

Posts: 1714657643

View Profile Personal Message (Offline)

Ignore
1714657643
Reply with quote  #2

1714657643
Report to moderator
Coding Enthusiast
Legendary
*
Offline Offline

Activity: 1039
Merit: 2783


Bitcoin and C♯ Enthusiast


View Profile WWW
November 24, 2019, 02:17:54 PM
 #2

It seems like a JSON parsing problem to me. You are giving the interpreter a JSON array (an array of outputs) so it should look like:
Code:
[
    {"FooKey": FooValue},
    {"BarKey": BarValue}
]
where keys are addresses and values are decimal amounts.

Projects List+Suggestion box
Donate: 1Q9s or bc1q
|
|
|
FinderOuter(0.19.1)Ann-git
Denovo(0.7.0)Ann-git
Bitcoin.Net(0.26.0)Ann-git
|
|
|
BitcoinTransactionTool(0.11.0)Ann-git
WatchOnlyBitcoinWallet(3.2.1)Ann-git
SharpPusher(0.12.0)Ann-git
Carlton Banks
Legendary
*
Offline Offline

Activity: 3430
Merit: 3071



View Profile
November 24, 2019, 02:18:11 PM
Last edit: November 24, 2019, 02:31:18 PM by Carlton Banks
 #3

"[{\"1EmGo9SAoYpoXmYH3Hm4LX8mMsyDxyDCkH \":0.0003,
there's a space character here                          ^

\":0.0003, \"3L4kHNBgRPf5u875UhTd6N57sw4gc7vLa \":0.00005}]"
and here ^

\"3L4kHNBgRPf5u875UhTd6N57sw4gc7vLa \":0.00005}]"
and here                                                   ^

"[{\"txid\":\"37d53f65g0568e3fd1e4auu7f30b4i0758e69o257f649de62b352931e402g7654\",\"vout\":0}]" "[{\"1EmGo9SAoYpoXmYH3Hm4LX8mMsyDxyDCkH \":0.0003,
not to mention                                                                                                                   here ^  Smiley

try removing those spaces, see whether the errors can be exorcised.

or try putting single quotes '  ' around all of the JSON data.



my true advice would be: stop doing it like this

the actual direct use of the CLI combined with the JSON data is not a user-friendly way to use the bitcoin-cli tool. If you prepare some files containing the JSON data, the CLI (probably bash in this case) will not directly interpret the space characters, and you can happily leave them in where they're needed. You can also make the JSON slightly more readable, as the \ escape isn't necessary for the " character.

so you'd do bitcoin-cli createrawtransaction $(cat json.data) for your command.

and json.data would look like
Code:
[{"txid":"37d53f65g0568e3fd1e4auu7f30b4i0758e69o257f649de62b352931e402g7654","vout":0}] [{"1EmGo9SAoYpoXmYH3Hm4LX8mMsyDxyDCkH":0.0003,"3L4kHNBgRPf5u875UhTd6N57sw4gc7vLa":0.00005}]

Vires in numeris
aa7356
Newbie
*
Offline Offline

Activity: 24
Merit: 4


View Profile
November 24, 2019, 02:54:27 PM
 #4

I do some kind of volunteer work at the Computer Science Museum, as a computer science student I think software as a computational abstraction representation of a real machinery state in a given moment.

Turns out that this post reminds me of "punch cards" ( Hollerith cards ) so I decided to find out when the "space/blank" character was mentioned in the ISO C standard ...
googling on that I end up at stackoverflow comment on '/0'

Quote
' '      space
'\t'     horizontal tab
'\n'     newline
'\v'     vertical tab
'\f'     feed
'\r'     carriage return   

Quote
Use isspace standard library function from ctype.h if you want to check for any of these white-spaces.

https://pubs.opengroup.org/onlinepubs/9699919799/basedefs/ctype.h.html

I'm still curious
HCP
Legendary
*
Offline Offline

Activity: 2086
Merit: 4316

<insert witty quote here>


View Profile
November 27, 2019, 03:47:55 AM
 #5

However when I tried to add a change address and value into a similar transaction.

bitcoin-cli createrawtransaction "[{\"txid\":\"37d53f65g0568e3fd1e4auu7f30b4i0758e69o257f649de62b352931e402g7654\",\"vout\":0}]" "[{\"1EmGo9SAoYpoXmYH3Hm4LX8mMsyDxyDCkH \":0.0003, \"3L4kHNBgRPf5u875UhTd6N57sw4gc7vLa \":0.00005}]"

This returned an error:

error code: -8
error message:
Invalid parameter, key-value pair must contain exactly one key
You seem to have the exact same issue as this: https://bitcoin.stackexchange.com/questions/80905/bitcoin-cli-createrawtransaction-with-3-outputs-example


Also can anyone recommend where I might find some examples of some raw transactions? Doesn't seem to be too many around that I can find :-/
Coincidentally... I found that above StackExchange question while searching for: "bitcoin cli examples" Tongue

█████████████████████████
████▐██▄█████████████████
████▐██████▄▄▄███████████
████▐████▄█████▄▄████████
████▐█████▀▀▀▀▀███▄██████
████▐███▀████████████████
████▐█████████▄█████▌████
████▐██▌█████▀██████▌████
████▐██████████▀████▌████
█████▀███▄█████▄███▀█████
███████▀█████████▀███████
██████████▀███▀██████████
█████████████████████████
.
BC.GAME
▄▄░░░▄▀▀▄████████
▄▄▄
██████████████
█████░░▄▄▄▄████████
▄▄▄▄▄▄▄▄▄██▄██████▄▄▄▄████
▄███▄█▄▄██████████▄████▄████
███████████████████████████▀███
▀████▄██▄██▄░░░░▄████████████
▀▀▀█████▄▄▄███████████▀██
███████████████████▀██
███████████████████▄██
▄███████████████████▄██
█████████████████████▀██
██████████████████████▄
.
..CASINO....SPORTS....RACING..
█░░░░░░█░░░░░░█
▀███▀░░▀███▀░░▀███▀
▀░▀░░░░▀░▀░░░░▀░▀
░░░░░░░░░░░░
▀██████████
░░░░░███░░░░
░░█░░░███▄█░░░
░░██▌░░███░▀░░██▌
░█░██░░███░░░█░██
░█▀▀▀█▌░███░░█▀▀▀█▌
▄█▄░░░██▄███▄█▄░░▄██▄
▄███▄
░░░░▀██▄▀


▄▄████▄▄
▄███▀▀███▄
██████████
▀███▄░▄██▀
▄▄████▄▄░▀█▀▄██▀▄▄████▄▄
▄███▀▀▀████▄▄██▀▄███▀▀███▄
███████▄▄▀▀████▄▄▀▀███████
▀███▄▄███▀░░░▀▀████▄▄▄███▀
▀▀████▀▀████████▀▀████▀▀
pooya87
Legendary
*
Offline Offline

Activity: 3444
Merit: 10524



View Profile
November 27, 2019, 04:38:40 AM
 #6

Also can anyone recommend where I might find some examples of some raw transactions? Doesn't seem to be too many around that I can find :-/

you can look at the blockchain itself! there are millions of transactions from genesis block up to the current height. for that you could use a block explorer that lets you see the raw transaction hex, usually they all do but blockcypher may be the most convenient as it has a clickable button on each tx called "API call" that shows you  both the hex and deserialized format.
example:
https://live.blockcypher.com/btc-testnet/tx/0e6931173d6bc63457b63d90fd8fc470d9b06c0bae79e354110466e47a062428/
=>
https://api.blockcypher.com/v1/btc/test3/txs/0e6931173d6bc63457b63d90fd8fc470d9b06c0bae79e354110466e47a062428?limit=50&includeHex=true

also i'd recommend using testnet, the coins don't have value so you can create transactions more freely without worry. and it is for "testing"!

.
.BLACKJACK ♠ FUN.
█████████
██████████████
████████████
█████████████████
████████████████▄▄
░█████████████▀░▀▀
██████████████████
░██████████████
████████████████
░██████████████
████████████
███████████████░██
██████████
CRYPTO CASINO &
SPORTS BETTING
▄▄███████▄▄
▄███████████████▄
███████████████████
█████████████████████
███████████████████████
█████████████████████████
█████████████████████████
█████████████████████████
███████████████████████
█████████████████████
███████████████████
▀███████████████▀
█████████
.
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!