<h2>Background</h2>

<p>So after reading these two articles (<a href="https://github.com/ChristopherA/Learning-Bitcoin-from-the-Command-Line" rel="nofollow noreferrer">Learning Bitcoin from the Command Line</a> and <a href="https://www.oreilly.com/library/view/mastering-bitcoin/9781491902639/ch03.html" rel="nofollow noreferrer">Mastering Bitcoin</a>), I am trying to piece together how I can get my first transaction with <code>OP_RETURN</code> data passed along to store in the blockchain.</p>

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

<pre><code>$ bitcoin-cli encryptwallet "my_pass_phrase"
</code></pre>

<p>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. <em>I don't have any other bitcoin available other than this new Coinbase bitcoin</em>.</p>

<p>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 <code>OP_RETURN</code> 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 <code>""</code> account?</p>

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

<pre><code>$ bitcoin-cli backupwallet wallet.backup
</code></pre>

<p><em>(Not sure where I should put this, but anyways...)</em></p>

<p>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.</p>

<p>Anyways, in the "Learning Bitcoin from the Command Line" they <a href="https://github.com/ChristopherA/Learning-Bitcoin-from-the-Command-Line/blob/master/06_5_Sending_a_Transaction_with_Data.md" rel="nofollow noreferrer">say</a>:</p>

<blockquote>
  <p>Sign your raw transaction and send it, and soon that <code>OP_RETURN</code> will be embedded in the blockchain!</p>
</blockquote>

<p>So I would like to, for this post, to create a "<a href="https://github.com/ChristopherA/Learning-Bitcoin-from-the-Command-Line/blob/master/04_2_Creating_a_Raw_Transaction.md" rel="nofollow noreferrer">raw transaction</a>", rather than <a href="https://github.com/ChristopherA/Learning-Bitcoin-from-the-Command-Line/blob/master/04_1_Sending_Coins_The_Easy_Way.md" rel="nofollow noreferrer">doing it the easy way</a>. Some commands that seem relevant are:</p>

<pre><code>$ bitcoin-cli getnewaddress "" legacy
n4cqjJE6fqcmeWpftygwPoKMMDva6BpyHf
$ bitcoin-cli getbalance
0.00000000
$ bitcoin-cli getunconfirmedbalance
0.47000000
$ 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
</code></pre>

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

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

<pre><code>$ bitcoin-cli signmessage "n4cqjJE6fqcmeWpftygwPoKMMDva6BpyHf" "Hello, World"
</code></pre>

<h2>Goal</h2>

<p>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 <strong>who the recipient is</strong> in this case as well. I am also not sure how I figure out the amount I should be sending.</p>

<p>The sequence of commands I am considering to run are these:</p>

<pre><code># 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 
</code></pre>

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

CC BY-SA 4.0
2019-10-27T16:42:52.287Z
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.
Nate Eldredge
CC BY-SA 4.0
2019-10-28T08:08:01.690Z
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).
Pieter Wuille
CC BY-SA 4.0
2019-10-28T08:10:27.370Z
@PieterWuille I want to store data with `OP_RETURN`, so how do I send some data with that?
Lance Pollard
<bitcoin-core><raw-transaction><bitcoin-cli><op-return><receiving>
How to add money to my Bitcoin Wallet and send my first Raw Transaction with OP_RETURN using bitcoin-cli
Lance Pollard
# How to add money to my Bitcoin Wallet and send my first Raw Transaction with OP_RETURN using bitcoin-cli

(Asked by: username_0 on 2019-10-27)

## Background

So after reading these two articles ([Learning Bitcoin from the Command Line](https://github.com/ChristopherA/Learning-Bitcoin-from-the-Command-Line) and [Mastering Bitcoin](https://www.oreilly.com/library/view/mastering-bitcoin/9781491902639/ch03.html)), 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](https://github.com/ChristopherA/Learning-Bitcoin-from-the-Command-Line/blob/master/06_5_Sending_a_Transaction_with_Data.md):

> 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](https://github.com/ChristopherA/Learning-Bitcoin-from-the-Command-Line/blob/master/04_2_Creating_a_Raw_Transaction.md)", rather than [doing it the easy way](https://github.com/ChristopherA/Learning-Bitcoin-from-the-Command-Line/blob/master/04_1_Sending_Coins_The_Easy_Way.md). Some commands that seem relevant are:

```
$ bitcoin-cli getnewaddress "" legacy
n4cqjJE6fqcmeWpftygwPoKMMDva6BpyHf
$ bitcoin-cli getbalance
0.00000000
$ bitcoin-cli getunconfirmedbalance
0.47000000
$ 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"

```

## Goal

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.

**Tags:** bitcoin-core, raw-transaction, bitcoin-cli, op-return, receiving

> **Comments:**
> **username_1**: 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.  
> **username_2**: 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).  
> **username_0**: @username_2 I want to store data with `OP_RETURN`, so how do I send some data with that?  

---

## 0 answers

