<p>The data field is only for when you want to create data-carrying transactions (ones with an OP_RETURN). This is generally not needed in normal transactions (and its usage there is somewhat controversial even). For coinbase transactions, you do need an OP_RETURN output with the witness commitment as specified in BIP141, if you want to include segwit transactions in your block.</p>
<p>However, you shouldn't use <code>createrawtransaction</code> and related RPCs for constructing coinbase transactions, as they will miss the necessary scriptSig contents. Even if you could, it would most likely be so slow as to be useless (a modern miner like an AntMiner S17 needs 13000 coinbases per second). Thus, the miner firmware constructs them using hardcoded logic.</p>
<p>The field is marked as required in the RPC documentation <em>for such outputs</em>. If you don't want a data-carrying output, the object simply wouldn't exist.</p>

CC BY-SA 4.0
2021-12-12T03:32:46.207Z
So the "data" needed is the string "OP_RETURN"?
AncientTides
CC BY-SA 4.0
2021-12-12T03:41:56.170Z
No, the data is whatever you want it to be, and in your case, you don't want it at all. If used, `createrawtransaction` uses an OP_RETURN-based scriptPubKey to encode it in the transaction. But again, this is completely unrelated to anything you're trying to do.
Pieter Wuille
CC BY-SA 4.0
2021-12-12T14:35:09.530Z
Thanks Pieter....... I wish you'd always be online to help me out.....Cheers
AncientTides
CC BY-SA 4.0
2023-11-28T20:03:35.143Z
is there a function similar to `createrawtransaction` that allows you to pass a specific scriptsig? I'm dealing with this because I don't know how to encode the transaction in hex without using `createrawtransaction`
David 天宇 Wong
CC BY-SA 4.0
2021-12-11T22:15:01.603Z
2021-12-11T22:28:06.463Z
2021-12-11T22:28:06.463Z
Pieter Wuille
<p><a href="https://developer.bitcoin.org/reference/rpc/createrawtransaction.html" rel="nofollow noreferrer">This</a> resource states that <a href="https://developer.bitcoin.org/reference/rpc/createrawtransaction.html#:%7E:text=%22data%22%3A%20%22hex%22%2C%20%20%20%20%20%20%20%20(string%2C%20required)%20A%20key%2Dvalue%20pair.%20The%20key%20must%20be%20%22data%22%2C%20the%20value%20is%20hex%2Dencoded%20data" rel="nofollow noreferrer">&quot;data&quot;: &quot;hex&quot;,(string, required) A key-value pair. The key must be &quot;data&quot;, the value is hex-encoded data</a>.</p>
<hr />
<h2>Questions</h2>
<ol>
<li>It says that the field is <strong>&quot;required&quot;</strong> but what exactly should that <strong><code>data</code></strong> be ??</li>
<li>If the <strong><code>data</code></strong> isn't provided does that invalidate the coinbase transaction (even when block height is encoded into scriptSig)?</li>
</ol>
<p>I asked the question <a href="https://bitcoin.stackexchange.com/q/111184/127251">here</a> but an answer wasn't provided. So I decided to make it a stand-alone question.</p>
<hr />
<h2>Goal</h2>
<ol>
<li>To confirm what <strong><code>data</code></strong> should be inserted within <a href="https://developer.bitcoin.org/reference/rpc/createrawtransaction.html#:%7E:text=%22data%22%3A%20%22hex%22%2C%20%20%20%20%20%20%20%20(string%2C%20required)%20A%20key%2Dvalue%20pair.%20The%20key%20must%20be%20%22data%22%2C%20the%20value%20is%20hex%2Dencoded%20data" rel="nofollow noreferrer">this data field</a></li>
</ol>

<bitcoin-cli><coinbase-transaction><createrawtransaction>
What "Data" should be inserted into the argument field of the "createrawtransaction" rpc command
AncientTides
# What "Data" should be inserted into the argument field of the "createrawtransaction" rpc command

(Asked by: username_0 on 2021-12-11)

[This](https://developer.bitcoin.org/reference/rpc/createrawtransaction.html) resource states that ["data": "hex",(string, required) A key-value pair. The key must be "data", the value is hex-encoded data](https://developer.bitcoin.org/reference/rpc/createrawtransaction.html#:%7E:text=%22data%22%3A%20%22hex%22%2C%20%20%20%20%20%20%20%20(string%2C%20required)%20A%20key%2Dvalue%20pair.%20The%20key%20must%20be%20%22data%22%2C%20the%20value%20is%20hex%2Dencoded%20data).

---

## Questions

1. It says that the field is **"required"** but what exactly should that **`data`** be ??
2. If the **`data`** isn't provided does that invalidate the coinbase transaction (even when block height is encoded into scriptSig)?

I asked the question [here](https://bitcoin.stackexchange.com/q/111184/127251) but an answer wasn't provided. So I decided to make it a stand-alone question.

---

## Goal

1. To confirm what **`data`** should be inserted within [this data field](https://developer.bitcoin.org/reference/rpc/createrawtransaction.html#:%7E:text=%22data%22%3A%20%22hex%22%2C%20%20%20%20%20%20%20%20(string%2C%20required)%20A%20key%2Dvalue%20pair.%20The%20key%20must%20be%20%22data%22%2C%20the%20value%20is%20hex%2Dencoded%20data)

**Tags:** bitcoin-cli, coinbase-transaction, createrawtransaction


---

## 1 answers

### Answer by username_1 on 2021-12-11. Score: 3 | Accepted answer

The data field is only for when you want to create data-carrying transactions (ones with an OP\_RETURN). This is generally not needed in normal transactions (and its usage there is somewhat controversial even). For coinbase transactions, you do need an OP\_RETURN output with the witness commitment as specified in BIP141, if you want to include segwit transactions in your block.

However, you shouldn't use `createrawtransaction` and related RPCs for constructing coinbase transactions, as they will miss the necessary scriptSig contents. Even if you could, it would most likely be so slow as to be useless (a modern miner like an AntMiner S17 needs 13000 coinbases per second). Thus, the miner firmware constructs them using hardcoded logic.

The field is marked as required in the RPC documentation *for such outputs*. If you don't want a data-carrying output, the object simply wouldn't exist.

> **Comments:**
> **username_0**: So the "data" needed is the string "OP_RETURN"?  
> **username_1**: No, the data is whatever you want it to be, and in your case, you don't want it at all. If used, `createrawtransaction` uses an OP_RETURN-based scriptPubKey to encode it in the transaction. But again, this is completely unrelated to anything you're trying to do.  
> **username_0**: Thanks username_1....... I wish you'd always be online to help me out.....Cheers  
> **username_2**: is there a function similar to `createrawtransaction` that allows you to pass a specific scriptsig? I'm dealing with this because I don't know how to encode the transaction in hex without using `createrawtransaction`  

---

