0

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!

1

3 Answers 3

1

BIP173 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. 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 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.

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? Most programming languages have very simple to use ASCII to HEX converters as well.

2
  • I think the question is how to create a coinbase txout that pays out to the address he specifies. Feb 22, 2021 at 23:30
  • Oh, looks like XY problem ;)
    – Tony Sanak
    Feb 23, 2021 at 0:05
0

Based on the given Bech32 address and quoting from BIP173

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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