<ol>
<li><p>The <strong>rawtransaction</strong> interface accepts and returns "raw" hex encoded p2p compatible transactions. Using the non-rawtransaction methods (like <code>sendtoaddres</code>, will not give you the possibility to inspect or alter the created bytearray.</p></li>
<li><p>The <strong><code>getrawchangeaddress</code></strong> method will retrieve a key from the keypool and return its pubkey (encoded into an p2pkh address). Unlike <strong><code>getrawchangeaddress</code></strong>, <strong><code>gewnewaddress</code></strong> will create an address book entry that will allow you better ways to inspect/distinct what funds you have received with that address and therefore increases the chance of a reused address.</p></li>
<li><p>You should use <strong><code>getrawchangeaddress</code></strong> if you like to use the given address as a change output for your rawtransaction.</p></li>
</ol>

CC BY-SA 3.0
2016-07-13T16:00:13.673Z
Thank you! Cool, so when people talk about a raw transaction they mean any custom-built transaction, as opposed to a fixed kind as suggested by APIs like [this one](https://godoc.org/github.com/btcsuite/btcrpcclient#Client.CreateRawTransaction). Did you mean to write "unlike" instead of "unless then"?
Alin Tomescu
CC BY-SA 3.0
2016-07-13T16:03:34.317Z
**Question:** If I use `getrawchangeaddress` to send the change, the change UTXO of the raw `OP_RETURN` TX I created doesn't show up in my `listunspent` query. Why is that? I would like to continue spending that change, by easily finding the UTXO for it. Should I use `getnewaddress` instead? Is there something wrong with that? This is where I am confused about the two.
Alin Tomescu
CC BY-SA 3.0
2016-07-13T16:09:20.880Z
(This is in _regtest_ mode and I've generated a new block for the raw TX, plus another 10 blocks after it.)
Alin Tomescu
CC BY-SA 3.0
2016-07-13T18:26:54.167Z
_Answer:_ Actually, I just realized the raw TX was not being included in a block because I set the transaction's fee to zero. I was able to mine it in a block and send the change to a `getnewaddress` PK. I am seeing the change in `listunspent` now. _Will check if_ `getrawchangeaddress` _works as well..._
Alin Tomescu
CC BY-SA 3.0
2016-07-14T22:09:46.703Z
Both `getnewaddress` and `getrawchangeaddress` work except `getnewaddress` can associate the PK with an 'account.' However, since accounts are deprecated, I will stay away from them. **Still unclear why both calls exist, especially if accounts are being deprecated:** the corresponding SK needs to be added to the wallet by both of them, so what's the difference between them?
Alin Tomescu
CC BY-SA 3.0
2016-07-13T10:31:02.887Z
2016-07-14T09:25:08.630Z
2016-07-14T09:25:08.630Z
Jonas Schnelli
<p>I'm using the Golang btcsuite/btcd library to write a Bitcoin app that creates custom <code>OP_RETURN</code> TXs in the blockchain.</p>

<p>I understand Bitcoin at a high-level (proof-of-work consensus, Merkle trees, membership, signatures, etc.), but I'm getting lost in the (unnecessarily?) complicated details of its RPC interface.</p>

<p>I was writing code in Go for creating a custom transaction with 1 input and 2 outputs (an OP_RETURN output and a change output). Here are my questions:</p>

<ol>
<li>Is this considered a <em>raw</em> transaction? (If so, what exactly constitutes a raw transaction? Is it all transactions that don't get created via the <code>sendfrom/sendmany/sendtoaddress</code> RPC?)</li>
<li>What's the difference between <code>getnewaddress</code> and <code>getrawchangeaddress</code> at a semantic level? It seems that both generate a key-pair, but why is there a need for two different calls?</li>
<li>If I'm creating a <em>raw</em> transaction as described above, should I send the change to a <code>getnewaddress</code> key or a <code>getrawchangeaddress</code> key?</li>
</ol>

<p>Thank you,<br>
Alin</p>

<raw-transaction>
getnewaddress vs. getrawchangeaddress
Alin Tomescu
# getnewaddress vs. getrawchangeaddress

(Asked by: username_0 on 2016-07-13)

I'm using the Golang btcsuite/btcd library to write a Bitcoin app that creates custom `OP_RETURN` TXs in the blockchain.

I understand Bitcoin at a high-level (proof-of-work consensus, Merkle trees, membership, signatures, etc.), but I'm getting lost in the (unnecessarily?) complicated details of its RPC interface.

I was writing code in Go for creating a custom transaction with 1 input and 2 outputs (an OP\_RETURN output and a change output). Here are my questions:

1. Is this considered a *raw* transaction? (If so, what exactly constitutes a raw transaction? Is it all transactions that don't get created via the `sendfrom/sendmany/sendtoaddress` RPC?)
2. What's the difference between `getnewaddress` and `getrawchangeaddress` at a semantic level? It seems that both generate a key-pair, but why is there a need for two different calls?
3. If I'm creating a *raw* transaction as described above, should I send the change to a `getnewaddress` key or a `getrawchangeaddress` key?

Thank you,  
Alin

**Tags:** raw-transaction


---

## 1 answers

### Answer by username_1 on 2016-07-13. Score: 1 | Accepted answer

1. The **rawtransaction** interface accepts and returns "raw" hex encoded p2p compatible transactions. Using the non-rawtransaction methods (like `sendtoaddres`, will not give you the possibility to inspect or alter the created bytearray.
2. The **`getrawchangeaddress`** method will retrieve a key from the keypool and return its pubkey (encoded into an p2pkh address). Unlike **`getrawchangeaddress`**, **`gewnewaddress`** will create an address book entry that will allow you better ways to inspect/distinct what funds you have received with that address and therefore increases the chance of a reused address.
3. You should use **`getrawchangeaddress`** if you like to use the given address as a change output for your rawtransaction.

> **Comments:**
> **username_0**: Thank you! Cool, so when people talk about a raw transaction they mean any custom-built transaction, as opposed to a fixed kind as suggested by APIs like [this one](https://godoc.org/github.com/btcsuite/btcrpcclient#Client.CreateRawTransaction). Did you mean to write "unlike" instead of "unless then"?  
> **username_0**: **Question:** If I use `getrawchangeaddress` to send the change, the change UTXO of the raw `OP_RETURN` TX I created doesn't show up in my `listunspent` query. Why is that? I would like to continue spending that change, by easily finding the UTXO for it. Should I use `getnewaddress` instead? Is there something wrong with that? This is where I am confused about the two.  
> **username_0**: (This is in _regtest_ mode and I've generated a new block for the raw TX, plus another 10 blocks after it.)  
> **username_0**: _Answer:_ Actually, I just realized the raw TX was not being included in a block because I set the transaction's fee to zero. I was able to mine it in a block and send the change to a `getnewaddress` PK. I am seeing the change in `listunspent` now. _Will check if_ `getrawchangeaddress` _works as well..._  
> **username_0**: Both `getnewaddress` and `getrawchangeaddress` work except `getnewaddress` can associate the PK with an 'account.' However, since accounts are deprecated, I will stay away from them. **Still unclear why both calls exist, especially if accounts are being deprecated:** the corresponding SK needs to be added to the wallet by both of them, so what's the difference between them?  

---

