Raw Transaction on Bitcoin-core lets you create and broadcast transaction through its Application Programming Interface and Command Line Interface (or on a shell for nix users). In this short post… we will be using few bitcoin-core commands such as, listunpent, createrawtransaction, signrawtransaction and signrawtransaction. But before we start, make sure your blockchain is fully synced and you have enough bitcoin to play with.
In this example, we will send all spendable amount of bitcoins to wallet address 1ZXsXWvnGHey8Dv7dCYtfBAaeipP2QEBY with 0.00001 of bitcoin reward to miners for processing our transaction.
Step 1: Pick which set of Bitcoins you want to send. Use listunpsent command to get the transaction ID and vout index number.
Step 2: Create raw transaction using createrawtransaction command in this format:
createrawtransaction '<source of bitcoins>' '<to wallet address and amount>'
createrawtransaction '[{"txid":"a510483803920726be537a241d9014221ae78ce5e888e23f88c37a0343f4be8b","vout":1}]' '{"1ZXsXWvnGHey8Dv7dCYtfBAaeipP2QEBY":0.00099}'
EYES HERE!!! EXTREMELY IMPORTANT!!! EYES HERE!!! EXTREMELY IMPORTANT!!!EYES HERE!!! EXTREMELY IMPORTANT!!!EYES HERE!!! EXTREMELY IMPORTANT!!!EYES HERE!!! EXTREMELY IMPORTANT!!!
My spendable amount from previous transactions is 0.001 BTC and I’m sending 0.00099 to wallet address “1ZXsXWvnGHey8Dv7dCYtfBAaeipP2QEBY“. The rest of bitcoins (0.00001) will be the “transaction fee” or the miners reward for processing our transaction.
BUT! WHAT IF your spendable amount is 1 .0 BTC and you’re just sending 0.5 BTC? All remaining 0.5 BTC will be considered as “transaction fee”… so say goodbye 0.5 BTC!!! If you don’t like this to happen…. you have to specify your “change” wallet address.
createrawtransaction ‘[{“txid”:”<past transaction ID>“,”vout”:<output index number>}]’ ‘{“<recipient wallet address>“:0.5, “<your change wallet address>“:0.4999}’
Now, it will sent back 0.4999 BTC to your change wallet address and the remaining bitcoins (0.0001 ) will be the “transaction fee”.
Once you run createrawtransaction with no errors, it will return a hex encoded transaction string that we will use in Step 3.
Step 3: Sign the transaction. Sign the transaction using the hex encoded string from Step 2 to create the signed hex encoded transaction string.
In this stage, sending 0.00099 to “1ZXsXWvnGHey8Dv7dCYtfBAaeipP2QEBY” wallet address transaction is now signed but we have to let anyone know using sendrawtransaction command for Step 4
Step 4: Broadcast the transaction using sendrawtransaction command. It will return a Transaction ID that can be tracked using blockr.io website like this https://btc.blockr.io/tx/info/8dc566740b634f702f48cdd5b9ca36de53001df1b5943ad94b92e554e68447eb
That’s all it! We sent a bitcoin raw transaction in four easy steps. With this, it gives us a low-level access for creating and broadcasting bitcoin transaction. It allows us pick which bitcoin to spent, create multiple recipient or specify change wallet address, adjust miners fee each transactions and defer or push a transaction to the network.
Also checkout the following links:
- https://en.bitcoin.it/wiki/Raw_Transactions
- https://bitcointalk.org/index.php?topic=101525.0
- https://en.bitcoin.it/wiki/Original_Bitcoin_client/API_calls_list
If you find this useful, send a tip: 1ZXsXWvnGHey8Dv7dCYtfBAaeipP2QEBY
You must be logged in to post a comment.