BitcoinCash, unlike the old Bitcoin transaction signature, uses the BIP143 protocol similar to BitcoinSW, but without SW functionality. Old bitcoins signed deals with the structure of a: klmoney.wordpress.com/bitcoin-dis… BIP143 Protocol: github.com/bitcoin/bip… BitcoinCash trade signature: github.com/Bitcoin-ABC…

If you have never done BTC signature or SW, then congratulations, like me, don’t read the above information, below I will teach you how to buy a BitcoinCash most commonly used P2PKH (pay-to-public-key-hash) transaction, and sign.

You need some knowledge of UTXO to understand the structure of the BCH deal.

To analyze txid for e1583427ce0b2ad9e4adc1621aada387f5d7b7fc105d7f0ea3d5d1339714cc88 trading, bch.btc.com/e1583427ce0…

The deal from address qzv8nyncjruxvwvq92zes6amtuj6cxrfp5creydtnm roll-out 0.00027317 BCH, to own (change) 0.00022090, To address qz88qqxctlqkppds353wpx92ajxpc8x4lccgpz7lmf is 0.00005000 a, miners spent 0.00000227 BCH fee.

Take a look at the raw transaction data for this transaction:

0100000001892f8ddd7b54bb79278a3859ba4474a68eb28956d549e09aa5e121423e0c5cb6000000006b483045022100fac3c23687a75f23038d104a 8545932db9815afdb6436daf2f52507a3a62da58022020ec3941165cfb6c054efd9f4cac757adab9d8c378953ed621d118106a1779c34121023839c7 18238a1795a12aa2f7af43816a7ca51dee1b45576d6c81bb7eed710f19ffffffff024a560000000000001976a9149879927890f86639802a85986bbb 5 f25ac18690d88ac88130000000000001976a9148e7000d85fc16085b08d22e098aaec8c1c1cd5fe88ac00000000 look not to understand? Never mind, paste the data here to decode it: bch.btc.com/tools/tx/de… This is a typical transaction with one input and two outputs, one of which is forwarded to the original address (change). With the analysis tool analysis of the internal, you can see a general meaning, but for the specific meaning of each data, to manual analysis. The transaction structure of BCH is the same as that of BTC, but the calculation of signature data is different. Below, we analyze these data manually

Explain the source of each data item in detail

[1] Version number In BCH, the version number is 01000000, but some transactions are 02000000, the difference is not known for the time being.

Each input here is a UTXO. Even for the same address, there will be multiple UTXOs as inputs.

[3] Enter the reverse order of TXID, which refers to the ID of a UTXO, and then swap the data. In the 2018-8-31 12:00 UTC time, 8 + can find address qzv8nyncjruxvwvq92zes6amtuj6cxrfp5creydtnm has a UTXO, Deal with ID b65c0c3e4221e1a59ae049d55689b28ea67444ba59388a2779bb547bdd8d2f89, the transaction ID, order You can get 892 f8ddd7b54bb79278a3859ba4474a68eb28956d549e09aa5e121423e0c5cb6.

[4] input tx of the serial number as above, find UTXO b65c0c3e4221e1a59ae049d55689b28ea67444ba59388a2779bb547bdd8d2f89, this transaction has two output, The first (serial number 0) for transfer to qzv8nyncjruxvwvq92zes6amtuj6cxrfp5creydtnm output, the second is op_return (number 1). The sequence number we need is 0, the encoding length is 4byte, the LE little encoder, and the result is 00000000.

[5] Script length The script length refers to the length of the unlock script, which consists of two parts: the signature part and the public key part. The length of the two parts should be added up.

[6] Signature Length Indicates the length of the signature data. 48 is hexadecimal, indicating that the signature data contains 72 bytes.

[7] Signature data is a very complex part, which will be explained in detail later.

[8] SigHash Code this can be considered a signature type. The current example is a P2PKH transaction where BTC uses SIGHASH_ALL (0x01) and BCH needs to do logic or operation with SIGHASH_FORKID (0x40) resulting in 0x41.

[9] Public key Length The length of the public key, now used with a compressed public key, is 33 (0x21) in length.

[10] The public key now uses the compressed public key, which contains only the x-coordinate of the point Q of the elliptic curve, with data preceded by either 02 (y is even) or 03 (y is odd).

[11] The serial number FFFFFFFF indicates that there is no serial number. This function is not used here.

[12] Output Quantity There are two outputs in this example. If it has op_return, it is also an output.

[13] The unit of transfer amount is Cong, LE little end code. The number of transfers to this person’s address is 22090, which translates to 564A in hexadecimal, using 8byte little encodings, resulting in 4A56000000000000.

[14] The length of the lock script includes several opcodes and the length of the public key hash. This example is P2PKH (pay-to-public-key address mode), which has the format: OP_DUP (0x76) OP_HASH160 (0xA9) Public key Hash Length (0x14) [a 20-byte public key hash] OP_EQUALVERIFY (0x88) OP_CHECKSIG (0xAC)

[15] OP_DUP

[16] OP_HASH160

[17] Public key Hash Length Fixed length 20 Byte (0x14)

[18] Public key hash Public key hash is derived from the reverse address. Base58 encoded addresses are converted into byte arrays using Base58Check.

[19] OP_EQUALVERIFY

[20] OP_CHECKSIG

[21] The current value of lock time is 00000000, which indicates that it takes effect immediately. < 500000000 Indicates the Block height and is locked before the Block.

= 500000000 Indicates a Unix timestamp. The timestamp before this time is locked (invalid). Now let’s start with the signature part of article [7]. Where does the signature data come from? Original signature data —-> twice SHA256—->ECDSA signature —-> Signature result Signature requires a private key. If there are multiple inputs, multiple signatures are required. The composition of original signature data includes the following 10 parts. 1. The version of nVersion of thetransaction (4-byte little endian) is 01000000, which is the same as that in thetransaction structure

2. HashPrevouts (32-bytehash) input txID (reverse order), input serial number (here is the serial number of the transaction input, not the sequence in UTXO), if there are multiple inputs, all the inputs should be connected, after combining two SHA256 operations.

Join the data of the above structure: [input 0 txID (reverse order) 32 bits] —- [input 0 serial number is 00000000] —- [Input 1 txID (reverse order) 32 bits] —- [input 1 serial number is 01000000] —- […] – […] Then do two SHA256 calculations. Case is only one input, txid b65c0c3e4221e1a59ae049d55689b28ea67444ba59388a2779bb547bdd8d2f89, serial number is 0, the serial number with 4 byte LE small end after code is 00000000. Is 892 f8ddd7b54bb79278a3859ba4474a68eb28956d549e09aa5e121423e0c5cb600000000 after the combination, After two SHA256 c68be60806e8f79ca8eba088575466de68f7e052bb8b701780c40a633b4dd15 is 1

3. HashSequence (32-bytehash) input sequence (utxo sequence), if there are multiple inputs, join the sequence of multiple inputs, and do SHA256 twice. Case is only one input, its sequence is 0, 4 byte code is 00000000, after the small end is 3 bb13029ce7b1f559ef5e747fcac439f1455a2ec7c5f09b72290795e70665044 after two SHA256

4. Outpoint (32-bit hash +4-byte little endian) This contains two parts. The first part is the TXID (reverse order) of the current input (which needs to be signed twice if there are two inputs), and the second part is the sequence of the current input in UTXO, encoded in 4byte LE little encoder. Examples of the two parts of data f8ddd7b54bb79278a3859ba4474a68eb28956d549e09aa5e121423e0c5cb6 892 and 00000000, respectively

5. ScriptCode of the input(serialized as scripts inside CTxOuts) Similar to the [14] to [20] structures in the transaction structure, the transaction structure refers to the locking script of the output, here refers to the locking script of the input. Because the first output in the example is change to the original input, the data is the same. In the example input lock scripts are 1976 a9149879927890f86639802a85986bbb5f25ac18690d88ac

6. Value of the output spentby this input (8-byte little endian) The number of coins currently entered, in 8-byte LE little endian. B56a000000000000 7. NSequence of the input(4-byte little endian) This example is a P2PKH transaction using FFFFFFFF to indicate no ordinal number.

Elsif outputs (32-bit hash) elsiF outputs (32-bit hash) Output amount (unit intellect, 8byte LE small encoder format), output lock script length (1byte), output lock script (structure refer to transaction structure [14] – [20]). If you have more than one output, concatenate all the output data, and finally do SHA256 twice.

Example has two output, 0 amount is 22090, encoded is 4 a56000000000000, length is 0 x19, locking the script is the amount of 76 a9149879927890f86639802a85986bbb5f25ac18690d88ac output 1 is 5000, Code is 8813000000000000, after the length is 0 x19, locking scripts are 76 a9148e7000d85fc16085b08d22e098aaec8c1c1cd5fe88ac this part of the data link is: 4a560000000000001976a9149879927890f86639802a85986bbb5f25ac18690d88ac88130000000000001976a9148e7000d85fc16085b08d22e098a Aec8c1c1cd5fe88ac do two SHA256 result: 7314809 dcfc7f52e42fdaaf898e22f85813d92cb39c240f972e005c86e23f1b6

9. NLocktime of thetransaction (4-byte little endian) lock time. The current value is 00000000, indicating that thetransaction takes effect immediately. < 500000000 Indicates the Block height and is locked before the Block.

= 500000000 Indicates a Unix timestamp. The timestamp before this time is locked (invalid). Sighash type of thesignature (4-byte little endian) current example is P2PKH transaction where BTC uses SIGHASH_ALL (0x01) BCH needs to do logic or operation with SIGHASH_FORKID (0x40) which is 0x41. Converted to 4byte LE small endian format, the result is 41000000. Concatenate all the above 10 pieces of data: 010000001c68be60806e8f79ca8eba088575466de68f7e052bb8b701780c40a633b4dd153bb13029ce7b1f559ef5e747fcac439f1455a2ec7c5f09b 72290795e70665044892f8ddd7b54bb79278a3859ba4474a68eb28956d549e09aa5e121423e0c5cb6000000001976a9149879927890f86639802a859 86bbb5f25ac18690d88acb56a000000000000ffffffff7314809dcfc7f52e42fdaaf898e22f85813d92cb39c240f972e005c86e23f1b600000000410 SHA256 twice: 287 ebc95c349b791885797ede0c1aa865f1cdc95140179c2d83b7c308d201cb2 ECDSA signature, need the private key, The private key for KyFj2LMgn54ByvzCWoPgPYK7XTBV7PywskiexBoJceziLy3V1UnR, after signature data is: 3045022100fac3c23687a75f23038d104a8545932db9815afdb6436daf2f52507a3a62da58022020ec3941165cfb6c054efd9f4cac757adab9d8c378 953ED621D118106A1779C3 fill the signed data into the transaction structure and broadcast it out.

Author: digging coal miners in 2018-09-03, BCH. The club is exceptional address: bitcoincash: qqe0dlh5u0mx7zctmrxeezh359zgtfszauhuyfes60