So after reading these two articles (Learning Bitcoin from the Command Line and Mastering Bitcoin), I am trying to piece together how I can get my first transaction with OP_RETURN data passed along to store in the blockchain.

I have a full node environment working using bitcoind. Now what I did was encrypt my wallet which came with installing Bitcoin Core.

$ bitcoin-cli encryptwallet "my_pass_phrase"

At this point I'm lost and not sure what to do next. I've purchased $10 worth of bitcoin from Coinbase and it's sitting there in my Coinbase "BTC" wallet I guess. I don't have any other bitcoin available other than this new Coinbase bitcoin.

From what I understand so far, I need to create an address first? Why do I create an address if I don't have anyone specific I am sending money to? I just want to append some 80-bytes of OP_RETURN data to the blockchain. So who do I create the transaction with, what address? And oh, also, what account should I be using, just the default "" account?

So even though I haven't done anything yet, for best-practices sake I've created a backup of my wallet.

$ bitcoin-cli backupwallet wallet.backup

(Not sure where I should put this, but anyways...)

I didn't need to install any external third party wallet system like Electrum which everyone seems to recommend, maybe nowadays Bitcoin Core has all the functionality you need. Not sure.

Anyways, in the "Learning Bitcoin from the Command Line" they say:

Sign your raw transaction and send it, and soon that OP_RETURN will be embedded in the blockchain!

So I would like to, for this post, to create a "raw transaction", rather than doing it the easy way. Some commands that seem relevant are:

$ bitcoin-cli getnewaddress "" legacy
$ bitcoin-cli getbalance
$ bitcoin-cli getunconfirmedbalance
$ bitcoin-cli getwalletinfo
$ bitcoin-cli listtransactions
$ bitcoin-cli listunspent
$ bitcoin-cli getrawchangeaddress
$ bitcoin-cli -named createrawtransaction inputs='''[ { "txid": "'$utxo_txid'", "vout": '$utxo_vout' } ]''' outputs='''{ "data": "'$op_return_data'", "'$changeaddress'": 0.8995 }'''
$ bitcoin-cli signrawtransaction 0100000001e34ac1e2baac09c366fce1c2245536bda8f7db0f6685862aecf53ebd69f9a89c0000000000ffffffff02a0252600000000001976a914d90d36e98f62968d2bc9bbd68107564a156a9bcf88ac50622500000000001976a91407bdb518fa2e6089fd810235cf1100c9c13d1fd288ac00000000
$ bitcoin-cli sendrawtransaction0100000001e34ac1e2baac09c366fce1c2245536bda8f7db0f6685862aecf53ebd69f9a89c000000006a47304402203e8a16522da80cef66bacfbc0c800c6d52c4a26d1d86a54e0a1b76d661f020c9022010397f00149f2a8fb2bc5bca52f2d7a7f87e3897a273ef54b277e4af52051a06012103c9700559f690c4a9182faa8bed88ad8a0c563777ac1d3f00fd44ea6c71dc5127ffffffff02a0252600000000001976a914d90d36e98f62968d2bc9bbd68107564a156a9bcf88ac50622500000000001976a91407bdb518fa2e6089fd810235cf1100c9c13d1fd288ac00000000ae74538baa914f3799081ba78429d5d84f36a0127438e9f721dff584ac17b346
$ # Then verify the transaction visually:
$ bitcoin-cli gettransaction ae74538baa914f3799081ba78429d5d84f36a0127438e9f721dff584ac17b346
$ bitcoin-cli decoderawtransaction $rawtxhex

I don't want to have to mess with the testing testnet addresses and such, I just want this to work on the main system (mainnet?).

Not sure if at any point I will be needing to "sign" anything, as in:

$ bitcoin-cli signmessage "n4cqjJE6fqcmeWpftygwPoKMMDva6BpyHf" "Hello, World"


My goal is to (1) get funds from my Coinbase account into my full node system, and (2) create the transaction somewhere with the OP_RETURN data of an 80-byte string I have. I am not sure who the recipient is in this case as well. I am also not sure how I figure out the amount I should be sending.

The sequence of commands I am considering to run are these:

# Find out where the money is coming from when I send to my wallet from Coinbase
$ bitcoin-cli listtransactions
$ bitcoin-cli listunspent
# Start a new transaction
$ bitcoin-cli getrawchangeaddress
$ bitcoin-cli -named createrawtransaction inputs='''[ { "txid": "'$utxo_txid'", "vout": '$utxo_vout' } ]''' outputs='''{ "data": "'$op_return_data'", "'$changeaddress'": 0.8995 }'''
$ bitcoin-cli signrawtransaction
$ bitcoin-cli sendrawtransaction
$ bitcoin-cli gettransaction 

I'm just not exactly sure what should be plugged into what, or if this is correct. Please help.

  • 4
    It might be wise to gain some general familiarity with using Bitcoin Core (especially on testnet) before working with raw transactions, which is sort of an "advanced" topic. With raw transactions, it is very easy to lose all your money by making simple mistakes. Oct 27, 2019 at 16:42
  • If you don't know who the recipient is, you presumably don't intend to transfer any money, as you shouldn't be creating a transaction at all (unless it's for testing/learning purposes, in which case testnet is the right choice). Oct 28, 2019 at 8:08
  • @PieterWuille I want to store data with OP_RETURN, so how do I send some data with that?
    – Lance
    Oct 28, 2019 at 8:10


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.