<p><a href="https://github.com/bitcoin/bips/blob/master/bip-0173.mediawiki" rel="nofollow noreferrer">BIP173</a> specifies the conversion from Bech32 segwit addresses to scriptPubKey. You probably want to use some reference software to do the decoding (there are several links in the BIP). If you need the details, it is approximately:</p>
<ul>
<li>Split the address in a &quot;human readable part&quot; and a &quot;data part&quot;; the last '1' character in the address separates the two.</li>
<li>Convert the data part from characters to symbols (integers in range 0-31) using the character map in the BIP.</li>
<li>Verify the checksum (last 6 characters of the data part). I'll refer to the BIP for the details.</li>
<li>Interpret the symbols of the data part as follows:
<ul>
<li>One symbol: Witness version (number 0-16)</li>
<li>Variable number of symbol: witness program</li>
<li>The last 6 symbols: the checksum</li>
</ul>
</li>
<li>Perform various sanity checks on the data sizes and ranges, also illustrated in the BIP.</li>
</ul>
<p>The retrieved information (witness version and program) can the be converted to a scriptPubKey, as specified in <a href="https://github.com/bitcoin/bips/blob/master/bip-0141.mediawiki" rel="nofollow noreferrer">BIP141</a>. Namely, OP_n (where n is the witness version), followed by a push of the witness program. Note that OP_0 is 0x00, while OP_1-OP_16 are 0x51..0x60.</p>
<p>There is a proposed amendment called <a href="https://github.com/bitcoin/bips/blob/master/bip-0350.mediawiki" rel="nofollow noreferrer">BIP350</a> which improves the checksum for witness versions higher than 0 (which are currently not in use, but may become in use following the activation of Taproot (BIP340-342).</p>
<p>This is how conversion from addresses to scriptPubKeys works for all transaction outputs, FWIW. It is entirely unrelated to coinbases.</p>
<p>Disclaimer: I'm a co-author of all the BIPs mentioned in this answer.</p>

CC BY-SA 4.0
2021-02-23T00:41:28.490Z
2021-02-23T00:41:28.490Z
Pieter Wuille
<p>Based on the given Bech32 address and quoting from <a href="https://github.com/bitcoin/bips/blob/master/bip-0173.mediawiki" rel="nofollow noreferrer">BIP173</a></p>
<p><code>bc1quukrk3u6cgpjhyqvehcj0ruyk8990dpev0zn6h</code></p>
<p>Broad level, Bech32 splits into two parts, <strong>human-readable</strong> and <strong>data</strong> with <code>1</code> as a separator.</p>
<p><code>bc</code> <code>1</code>
<code>quukrk3u6cgpjhyqvehcj0ruyk8990dpev0zn6h</code></p>
<p><strong>Human readable part:</strong></p>
<blockquote>
<p>The <strong>human-readable part</strong>, which is intended to convey the type of data,
or anything else that is relevant to the reader. This part MUST
contain 1 to 83 US-ASCII characters...</p>
</blockquote>
<p><code>bc</code> segwit bitcoin network indicator:  &quot;bc&quot; for mainnet, and &quot;tb&quot; for testnet.</p>
<p><strong>The data part</strong></p>
<blockquote>
<p><strong>The data part</strong>, which is at least 6 characters long and only consists of alphanumeric characters excluding &quot;1&quot;, &quot;b&quot;, &quot;i&quot;, and
&quot;o&quot;.</p>
</blockquote>
<p><code>q</code> the witness version</p>
<p><code>uukrk3u6cgpjhyqvehcj0ruyk8990dpev0zn6h</code></p>
<blockquote>
<p>A conversion of the 2-to-40-byte witness program (as defined by
BIP141) to base32:
Start with the bits of the witness program, most significant bit per byte first.
Re-arrange those bits into groups of 5, and pad with zeroes at the end if needed.
Translate those bits to characters using the table.</p>
</blockquote>
<pre><code>    0   1   2   3   4   5   6   7
+0  q   p   z   r   y   9   x   8
+8  g   f   2   t   v   d   w   0
+16 s   3   j   n   5   4   k   h
+24 c   e   6   m   u   a   7   l
</code></pre>
<p>An online converter:</p>
<p><a href="https://bitcoin.sipa.be/bech32/demo/demo.html" rel="nofollow noreferrer">bitcoin.sipa.be/bech32/demo/demo.html</a></p>

CC BY-SA 4.0
2023-08-24T11:15:16.487Z
2023-08-24T11:15:16.487Z
Lee
<p>I assume you want to post it in the coinbase transaction in the form of hex-represented ASCII data (like encoding text in OP_RETURN) for some sort of signaling/&quot;bragging rights&quot;.</p>
<p>You haven't mentioned any specific programming language you want to use so I'd suggest using online ASCII to HEX converter? Like <a href="https://www.rapidtables.com/convert/number/ascii-to-hex.html" rel="nofollow noreferrer">this one</a>? Most programming languages have very simple to use ASCII to HEX converters as well.</p>

CC BY-SA 4.0
2021-02-22T23:30:52.480Z
I think the question is how to create a coinbase txout that pays out to the address he specifies.
Pieter Wuille
CC BY-SA 4.0
2021-02-23T00:05:36.093Z
Oh, looks like XY problem ;)
Tony Sanak
CC BY-SA 4.0
2021-02-22T22:53:50.027Z
2021-02-22T22:53:50.027Z
Tony Sanak
<p>Im trying to create a coinbase transaction so that I can do some mining.</p>
<p>I have a bech32 bitcoin address, how do I convert that to hex so that I can include it in the coinbase transaction data?</p>
<p>example&gt; <code>bc1quukrk3u6cgpjhyqvehcj0ruyk8990dpev0zn6h</code></p>
<p>Also, where are the parts of the address? network type, checksum.</p>
<p>And how would I do it with the other address types?</p>
<p>Thanks in advance!</p>

CC BY-SA 4.0
2023-08-24T10:49:53.390Z
On-line converter: https://bitcoin.sipa.be/bech32/demo/demo.html
Lee
<coinbase-transaction><bech32-address>
how do i convert bc1 address to hex? for coinbase transaction
Martin Bradley
# how do i convert bc1 address to hex? for coinbase transaction

(Asked by: username_0 on 2021-02-20)

Im trying to create a coinbase transaction so that I can do some mining.

I have a bech32 bitcoin address, how do I convert that to hex so that I can include it in the coinbase transaction data?

example> `bc1quukrk3u6cgpjhyqvehcj0ruyk8990dpev0zn6h`

Also, where are the parts of the address? network type, checksum.

And how would I do it with the other address types?

Thanks in advance!

**Tags:** coinbase-transaction, bech32-address

> **Comments:**
> **username_1**: On-line converter: https://bitcoin.sipa.be/bech32/demo/demo.html  

---

## 3 answers

### Answer by username_2 on 2021-02-23. Score: 1

[BIP173](https://github.com/bitcoin/bips/blob/master/bip-0173.mediawiki) specifies the conversion from Bech32 segwit addresses to scriptPubKey. You probably want to use some reference software to do the decoding (there are several links in the BIP). If you need the details, it is approximately:

* Split the address in a "human readable part" and a "data part"; the last '1' character in the address separates the two.
* Convert the data part from characters to symbols (integers in range 0-31) using the character map in the BIP.
* Verify the checksum (last 6 characters of the data part). I'll refer to the BIP for the details.
* Interpret the symbols of the data part as follows:
  + One symbol: Witness version (number 0-16)
  + Variable number of symbol: witness program
  + The last 6 symbols: the checksum
* Perform various sanity checks on the data sizes and ranges, also illustrated in the BIP.

The retrieved information (witness version and program) can the be converted to a scriptPubKey, as specified in [BIP141](https://github.com/bitcoin/bips/blob/master/bip-0141.mediawiki). Namely, OP\_n (where n is the witness version), followed by a push of the witness program. Note that OP\_0 is 0x00, while OP\_1-OP\_16 are 0x51..0x60.

There is a proposed amendment called [BIP350](https://github.com/bitcoin/bips/blob/master/bip-0350.mediawiki) which improves the checksum for witness versions higher than 0 (which are currently not in use, but may become in use following the activation of Taproot (BIP340-342).

This is how conversion from addresses to scriptPubKeys works for all transaction outputs, FWIW. It is entirely unrelated to coinbases.

Disclaimer: I'm a co-author of all the BIPs mentioned in this answer.


---

### Answer by username_1 on 2023-08-24. Score: 0

Based on the given Bech32 address and quoting from [BIP173](https://github.com/bitcoin/bips/blob/master/bip-0173.mediawiki)

`bc1quukrk3u6cgpjhyqvehcj0ruyk8990dpev0zn6h`

Broad level, Bech32 splits into two parts, **human-readable** and **data** with `1` as a separator.

`bc` `1`
`quukrk3u6cgpjhyqvehcj0ruyk8990dpev0zn6h`

**Human readable part:**

> The **human-readable part**, which is intended to convey the type of data,
> or anything else that is relevant to the reader. This part MUST
> contain 1 to 83 US-ASCII characters...

`bc` segwit bitcoin network indicator: "bc" for mainnet, and "tb" for testnet.

**The data part**

> **The data part**, which is at least 6 characters long and only consists of alphanumeric characters excluding "1", "b", "i", and
> "o".

`q` the witness version

`uukrk3u6cgpjhyqvehcj0ruyk8990dpev0zn6h`

> A conversion of the 2-to-40-byte witness program (as defined by
> BIP141) to base32:
> Start with the bits of the witness program, most significant bit per byte first.
> Re-arrange those bits into groups of 5, and pad with zeroes at the end if needed.
> Translate those bits to characters using the table.

```
    0   1   2   3   4   5   6   7
+0  q   p   z   r   y   9   x   8
+8  g   f   2   t   v   d   w   0
+16 s   3   j   n   5   4   k   h
+24 c   e   6   m   u   a   7   l

```

An online converter:

[bitcoin.sipa.be/bech32/demo/demo.html](https://bitcoin.sipa.be/bech32/demo/demo.html)


---

### Answer by username_3 on 2021-02-22. Score: 0

I assume you want to post it in the coinbase transaction in the form of hex-represented ASCII data (like encoding text in OP\_RETURN) for some sort of signaling/"bragging rights".

You haven't mentioned any specific programming language you want to use so I'd suggest using online ASCII to HEX converter? Like [this one](https://www.rapidtables.com/convert/number/ascii-to-hex.html)? Most programming languages have very simple to use ASCII to HEX converters as well.

> **Comments:**
> **username_2**: I think the question is how to create a coinbase txout that pays out to the address he specifies.  
> **username_3**: Oh, looks like XY problem ;)  

---

