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,

up vote 0 down vote accepted
  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.

  • 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. Did you mean to write "unlike" instead of "unless then"? – Alin Tomescu Jul 13 '16 at 16:00
  • 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 Jul 13 '16 at 16:03
  • (This is in regtest mode and I've generated a new block for the raw TX, plus another 10 blocks after it.) – Alin Tomescu Jul 13 '16 at 16:09
  • 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 Jul 13 '16 at 18:26
  • 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 Jul 14 '16 at 22:09

Your Answer


By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.