Bitcoin Forum
May 01, 2024, 04:24:55 PM *
News: Latest Bitcoin Core release: 27.0 [Torrent]
 
   Home   Help Search Login Register More  
Pages: [1]
  Print  
Author Topic: Bitcoin Mining Technical Details. Help  (Read 261 times)
xDilettante (OP)
Newbie
*
Offline Offline

Activity: 14
Merit: 1


View Profile
October 10, 2023, 07:49:59 PM
 #1

Hey, everybody. I'm trying to figure out how Bitcoin works. I'm getting a little bit of it, but I'm not getting some of it. I ask for help from knowledgeable and understanding Bitcoin coders.

I can get HASH transactions by double hashing (sha256) HEX data (raw transaction). But I can't find information and examples how to get TXID transaction.

For example:

Code:
{
    "result": {
        "in_active_chain": true,
        "txid": "f0acda99bd6f1042f98e042853e99dc0febb55325dda6ce8c4df7fe307816631",
        "hash": "eb55e1c0fc83dda66b9d69701ee6f79a49b5af73952600766d6d3af83fb9046e",
        "version": 1,
        "size": 262,
        "vsize": 235,
        "weight": 940,
        "locktime": 3758567493,
        "vin": [
            {
                "coinbase": "03e7610c0446f724652f4d41524120506f6f6c2ffabe6d6d621175c7c1371ebd43cefcefc3ab0453b7f952101cb5575976420d0104e9f0dd01000000000000006ffead5c76d2571ade6aa17dc7be6bde12b33031f30094000000ffffffff",
                "txinwitness": [
                    "0000000000000000000000000000000000000000000000000000000000000000"
                ],
                "sequence": 4294967295
            }
        ],
        "vout": [
            {
                "value": 6.3601069,
                "n": 0,
                "scriptPubKey": {
                    "asm": "OP_DUP OP_HASH160 2fc701e2049ee4957b07134b6c1d771dd5a96b21 OP_EQUALVERIFY OP_CHECKSIG",
                    "desc": "addr(15MdAHnkxt9TMC2Rj595hsg8Hnv693pPBB)#j6z3mx70",
                    "hex": "76a9142fc701e2049ee4957b07134b6c1d771dd5a96b2188ac",
                    "address": "15MdAHnkxt9TMC2Rj595hsg8Hnv693pPBB",
                    "type": "pubkeyhash"
                }
            },
            {
                "value": 0.0,
                "n": 1,
                "scriptPubKey": {
                    "asm": "OP_RETURN aa21a9edaf182da3eb02887057bacf92ae319a024020f02c8d50537fe33f45f1c922e08d",
                    "desc": "raw(6a24aa21a9edaf182da3eb02887057bacf92ae319a024020f02c8d50537fe33f45f1c922e08d)#rst44kmt",
                    "hex": "6a24aa21a9edaf182da3eb02887057bacf92ae319a024020f02c8d50537fe33f45f1c922e08d",
                    "type": "nulldata"
                }
            }
        ],
        "hex": "010000000001010000000000000000000000000000000000000000000000000000000000000000ffffffff5e03e7610c0446f724652f4d41524120506f6f6c2ffabe6d6d621175c7c1371ebd43cefcefc3ab0453b7f952101cb5575976420d0104e9f0dd01000000000000006ffead5c76d2571ade6aa17dc7be6bde12b33031f30094000000ffffffffffffffff02c2c0e825000000001976a9142fc701e2049ee4957b07134b6c1d771dd5a96b2188ac0000000000000000266a24aa21a9edaf182da3eb02887057bacf92ae319a024020f02c8d50537fe33f45f1c922e08d01200000000000000000000000000000000000000000000000000000000000000000453007e0",
        "blockhash": "00000000000000000000bd684e36789d16da2cf5b08b47deb72d1448a73eae5c",
        "confirmations": 77,
        "time": 1696921412,
        "blocktime": 1696921412
    },
    "error": null,
    "id": "1"
}

What data from this block do I need to hash to get TXID?
1714580695
Hero Member
*
Offline Offline

Posts: 1714580695

View Profile Personal Message (Offline)

Ignore
1714580695
Reply with quote  #2

1714580695
Report to moderator
1714580695
Hero Member
*
Offline Offline

Posts: 1714580695

View Profile Personal Message (Offline)

Ignore
1714580695
Reply with quote  #2

1714580695
Report to moderator
1714580695
Hero Member
*
Offline Offline

Posts: 1714580695

View Profile Personal Message (Offline)

Ignore
1714580695
Reply with quote  #2

1714580695
Report to moderator
"This isn't the kind of software where we can leave so many unresolved bugs that we need a tracker for them." -- Satoshi
Advertised sites are not endorsed by the Bitcoin Forum. They may be unsafe, untrustworthy, or illegal in your jurisdiction.
1714580695
Hero Member
*
Offline Offline

Posts: 1714580695

View Profile Personal Message (Offline)

Ignore
1714580695
Reply with quote  #2

1714580695
Report to moderator
j2002ba2
Full Member
***
Offline Offline

Activity: 204
Merit: 437


View Profile
October 10, 2023, 10:21:44 PM
Merited by o_e_l_e_o (4), BlackHatCoiner (4), pooya87 (2), ABCbits (2), nc50lc (1), DdmrDdmr (1)
 #2

This is a segwit transaction. Remove the marker, flag, and witness.
https://github.com/bitcoin/bips/blob/master/bip-0141.mediawiki#user-content-Transaction_ID

Code:
 nVersion: 01000000
   marker: 00
     flag: 01
    txins: 010000000000000000000000000000000000000000000000000000000000000000ffffffff5e03e7610c0446f724652f4d41524120506f6f6c2ffabe6d6d621175c7c1371ebd43cefcefc3ab0453b7f952101cb5575976420d0104e9f0dd01000000000000006ffead5c76d2571ade6aa17dc7be6bde12b33031f30094000000ffffffffffffffff
   txouts: 02c2c0e825000000001976a9142fc701e2049ee4957b07134b6c1d771dd5a96b2188ac0000000000000000266a24aa21a9edaf182da3eb02887057bacf92ae319a024020f02c8d50537fe33f45f1c922e08d
  witness: 01200000000000000000000000000000000000000000000000000000000000000000
nLockTime: 453007e0
raybucks
Jr. Member
*
Offline Offline

Activity: 102
Merit: 1


View Profile
October 11, 2023, 08:04:45 AM
 #3

The "txid" in the JSON data is like a unique code for a Bitcoin transaction.
It's already calculated and provided in the "txid" field, so you don't need to do any more calculations. It's your transaction's special identifier.

Are you tired of losing money at online casinos and struggling to get your winnings?
Try The Best Casino: https://bit.ly/3RPj3P8
BlackHatCoiner
Legendary
*
Offline Offline

Activity: 1498
Merit: 7340


Farewell, Leo


View Profile
October 11, 2023, 10:21:20 AM
 #4

As told by j2002ba2, you hash [nVersion][txins][txouts][nLockTime]. Note that TXID is represented in little endian, so when you double-hash with SHA256 on these bytes, make sure to convert it to little endian.

You can try it out in here:
- https://emn178.github.io/online-tools/sha256.html
- https://www.save-editor.com/tools/wse_hex.html#littleendian

.
.HUGE.
▄██████████▄▄
▄█████████████████▄
▄█████████████████████▄
▄███████████████████████▄
▄█████████████████████████▄
███████▌██▌▐██▐██▐████▄███
████▐██▐████▌██▌██▌██▌██
█████▀███▀███▀▐██▐██▐█████

▀█████████████████████████▀

▀███████████████████████▀

▀█████████████████████▀

▀█████████████████▀

▀██████████▀▀
█▀▀▀▀











█▄▄▄▄
▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀
.
CASINSPORTSBOOK
▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄
▀▀▀▀█











▄▄▄▄█
xDilettante (OP)
Newbie
*
Offline Offline

Activity: 14
Merit: 1


View Profile
October 12, 2023, 07:03:07 PM
 #5

This is a segwit transaction. Remove the marker, flag, and witness.
https://github.com/bitcoin/bips/blob/master/bip-0141.mediawiki#user-content-Transaction_ID

Code:
 nVersion: 01000000
   marker: 00
     flag: 01
    txins: 010000000000000000000000000000000000000000000000000000000000000000ffffffff5e03e7610c0446f724652f4d41524120506f6f6c2ffabe6d6d621175c7c1371ebd43cefcefc3ab0453b7f952101cb5575976420d0104e9f0dd01000000000000006ffead5c76d2571ade6aa17dc7be6bde12b33031f30094000000ffffffffffffffff
   txouts: 02c2c0e825000000001976a9142fc701e2049ee4957b07134b6c1d771dd5a96b2188ac0000000000000000266a24aa21a9edaf182da3eb02887057bacf92ae319a024020f02c8d50537fe33f45f1c922e08d
  witness: 01200000000000000000000000000000000000000000000000000000000000000000
nLockTime: 453007e0

Thank you so much! You have helped me a lot with this. It works as it should, everything matches.
xDilettante (OP)
Newbie
*
Offline Offline

Activity: 14
Merit: 1


View Profile
October 13, 2023, 12:57:30 PM
Last edit: October 13, 2023, 01:11:16 PM by xDilettante
 #6

Could you please tell me what exactly I'm doing wrong with getting the Merkle root? Here is my Python code, but I am not getting the result I need.

Target: "merkleroot": "19f3769778eb2019476630aafb376634cdf3f114e617a7e0a300e822265022bc"

Code:
#! /usr/bin/env python3
# -*- coding: utf-8 -*-
from hashlib import sha256
import requests, json

DEFAULT_RPC_REGTEST_PORT = "18443"
DEFAULT_RPC_TEST_PORT = "18332"
DEFAULT_RPC_MAIN_PORT = "8332"

rpcAddress = "127.0.0.1"  # localhost
rpcPort = DEFAULT_RPC_MAIN_PORT
rpcUser = "rpcuser"
rpcPassword = "rpcpassword"
rpcUrl = "http://" + rpcAddress + ":" + rpcPort
headers = {'content-type': 'application/json'}

def double_sha256(data):
    return bytes.fromhex(sha256(bytes.fromhex(sha256(bytes.fromhex(data)).hexdigest())).hexdigest())

def request_rpc(method, params):
    payload = json.dumps(
        {
            "jsonrpc": "2.0",
            "id": "1",
            "method": method,
            "params": params
        }
    )
    return requests.request("POST", rpcUrl, data=payload, headers=headers,
                                auth=(rpcUser, rpcPassword))


if __name__ == "__main__":
    res = request_rpc(method="getblock", params=["00000000000000000000bd684e36789d16da2cf5b08b47deb72d1448a73eae5c"])
    tx = res.json()["result"]["tx"]
    print(tx)

    hashes = []
    for i in range(len(tx)):
        res = request_rpc(method="getrawtransaction",
                          params=[tx[i], 1, '00000000000000000000bd684e36789d16da2cf5b08b47deb72d1448a73eae5c'])
        hashes.append(res.json()["result"]["hash"])
    print(len(hashes))
    # print(hashes)

    hashes = [bytes.fromhex(x) for x in hashes]
    while len(hashes) > 1:
        if len(hashes) % 2 == 1:
            hashes.append(hashes[-1])
        parent_level = []
        for x in range(0, len(hashes), 2):
            hash = sha256(hashes[x] + hashes[x + 1]).digest()
            parent_level.append(hash)
        hashes = parent_level

    print(hashes[0].hex())

I also did a double hash, and also tried to get the root by hashing TXID, but that also didn't help me get the result I wanted.
witcher_sense
Legendary
*
Offline Offline

Activity: 2324
Merit: 4316

🔐BitcoinMessage.Tools🔑


View Profile WWW
October 13, 2023, 02:03:28 PM
 #7

Could you please tell me what exactly I'm doing wrong with getting the Merkle root? Here is my Python code, but I am not getting the result I need.

Target: "merkleroot": "19f3769778eb2019476630aafb376634cdf3f114e617a7e0a300e822265022bc"

Code:
#! /usr/bin/env python3
# -*- coding: utf-8 -*-
from hashlib import sha256
import requests, json

DEFAULT_RPC_REGTEST_PORT = "18443"
DEFAULT_RPC_TEST_PORT = "18332"
DEFAULT_RPC_MAIN_PORT = "8332"

rpcAddress = "127.0.0.1"  # localhost
rpcPort = DEFAULT_RPC_MAIN_PORT
rpcUser = "rpcuser"
rpcPassword = "rpcpassword"
rpcUrl = "http://" + rpcAddress + ":" + rpcPort
headers = {'content-type': 'application/json'}

def double_sha256(data):
    return bytes.fromhex(sha256(bytes.fromhex(sha256(bytes.fromhex(data)).hexdigest())).hexdigest())

def request_rpc(method, params):
    payload = json.dumps(
        {
            "jsonrpc": "2.0",
            "id": "1",
            "method": method,
            "params": params
        }
    )
    return requests.request("POST", rpcUrl, data=payload, headers=headers,
                                auth=(rpcUser, rpcPassword))


if __name__ == "__main__":
    res = request_rpc(method="getblock", params=["00000000000000000000bd684e36789d16da2cf5b08b47deb72d1448a73eae5c"])
    tx = res.json()["result"]["tx"]
    print(tx)

    hashes = []
    for i in range(len(tx)):
        res = request_rpc(method="getrawtransaction",
                          params=[tx[i], 1, '00000000000000000000bd684e36789d16da2cf5b08b47deb72d1448a73eae5c'])
        hashes.append(res.json()["result"]["hash"])
    print(len(hashes))
    # print(hashes)

    hashes = [bytes.fromhex(x) for x in hashes]
    while len(hashes) > 1:
        if len(hashes) % 2 == 1:
            hashes.append(hashes[-1])
        parent_level = []
        for x in range(0, len(hashes), 2):
            hash = sha256(hashes[x] + hashes[x + 1]).digest()
            parent_level.append(hash)
        hashes = parent_level

    print(hashes[0].hex())

I also did a double hash, and also tried to get the root by hashing TXID, but that also didn't help me get the result I wanted.

Code:
#! /usr/bin/env python3
# -*- coding: utf-8 -*-

from hashlib import sha256
import requests
import json


def double_sha256(a, b):
    ab = a[::-1] + b[::-1]
    return sha256(sha256(ab).digest()).digest()[::-1]


if __name__ == "__main__":
    block_hash = "00000000000000000000bd684e36789d16da2cf5b08b47deb72d1448a73eae5c"
    response = requests.get(f'https://api.blockchair.com/bitcoin/raw/block/{block_hash}')
    tx = response.json()['data'][block_hash]["decoded_raw_block"]["tx"]
    print(tx)

    hashes = []
    for i in range(len(tx)):
        hashes.append(tx[i])
    print(len(hashes))
    # print(hashes)

    hashes = [bytes.fromhex(x) for x in hashes]
    while len(hashes) > 1:
        if len(hashes) % 2 == 1:
            hashes.append(hashes[-1])
        parent_level = []
        for x in range(0, len(hashes), 2):
            hash = double_sha256(hashes[x], hashes[x + 1])
            parent_level.append(hash)
        hashes = parent_level

    print(hashes[0].hex())


█▀▀▀











█▄▄▄
▀▀▀▀▀▀▀▀▀▀▀
e
▄▄▄▄▄▄▄▄▄▄▄
█████████████
████████████▄███
██▐███████▄█████▀
█████████▄████▀
███▐████▄███▀
████▐██████▀
█████▀█████
███████████▄
████████████▄
██▄█████▀█████▄
▄█████████▀█████▀
███████████▀██▀
████▀█████████
▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀
c.h.
▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄
▀▀▀█











▄▄▄█
▄██████▄▄▄
█████████████▄▄
███████████████
███████████████
███████████████
███████████████
███░░█████████
███▌▐█████████
█████████████
███████████▀
██████████▀
████████▀
▀██▀▀
xDilettante (OP)
Newbie
*
Offline Offline

Activity: 14
Merit: 1


View Profile
October 13, 2023, 02:45:51 PM
 #8

Could you please tell me what exactly I'm doing wrong with getting the Merkle root? Here is my Python code, but I am not getting the result I need.

Target: "merkleroot": "19f3769778eb2019476630aafb376634cdf3f114e617a7e0a300e822265022bc"

Code:
#! /usr/bin/env python3
# -*- coding: utf-8 -*-
from hashlib import sha256
import requests, json

DEFAULT_RPC_REGTEST_PORT = "18443"
DEFAULT_RPC_TEST_PORT = "18332"
DEFAULT_RPC_MAIN_PORT = "8332"

rpcAddress = "127.0.0.1"  # localhost
rpcPort = DEFAULT_RPC_MAIN_PORT
rpcUser = "rpcuser"
rpcPassword = "rpcpassword"
rpcUrl = "http://" + rpcAddress + ":" + rpcPort
headers = {'content-type': 'application/json'}

def double_sha256(data):
    return bytes.fromhex(sha256(bytes.fromhex(sha256(bytes.fromhex(data)).hexdigest())).hexdigest())

def request_rpc(method, params):
    payload = json.dumps(
        {
            "jsonrpc": "2.0",
            "id": "1",
            "method": method,
            "params": params
        }
    )
    return requests.request("POST", rpcUrl, data=payload, headers=headers,
                                auth=(rpcUser, rpcPassword))


if __name__ == "__main__":
    res = request_rpc(method="getblock", params=["00000000000000000000bd684e36789d16da2cf5b08b47deb72d1448a73eae5c"])
    tx = res.json()["result"]["tx"]
    print(tx)

    hashes = []
    for i in range(len(tx)):
        res = request_rpc(method="getrawtransaction",
                          params=[tx[i], 1, '00000000000000000000bd684e36789d16da2cf5b08b47deb72d1448a73eae5c'])
        hashes.append(res.json()["result"]["hash"])
    print(len(hashes))
    # print(hashes)

    hashes = [bytes.fromhex(x) for x in hashes]
    while len(hashes) > 1:
        if len(hashes) % 2 == 1:
            hashes.append(hashes[-1])
        parent_level = []
        for x in range(0, len(hashes), 2):
            hash = sha256(hashes[x] + hashes[x + 1]).digest()
            parent_level.append(hash)
        hashes = parent_level

    print(hashes[0].hex())

I also did a double hash, and also tried to get the root by hashing TXID, but that also didn't help me get the result I wanted.

Code:
#! /usr/bin/env python3
# -*- coding: utf-8 -*-

from hashlib import sha256
import requests
import json


def double_sha256(a, b):
    ab = a[::-1] + b[::-1]
    return sha256(sha256(ab).digest()).digest()[::-1]


if __name__ == "__main__":
    block_hash = "00000000000000000000bd684e36789d16da2cf5b08b47deb72d1448a73eae5c"
    response = requests.get(f'https://api.blockchair.com/bitcoin/raw/block/{block_hash}')
    tx = response.json()['data'][block_hash]["decoded_raw_block"]["tx"]
    print(tx)

    hashes = []
    for i in range(len(tx)):
        hashes.append(tx[i])
    print(len(hashes))
    # print(hashes)

    hashes = [bytes.fromhex(x) for x in hashes]
    while len(hashes) > 1:
        if len(hashes) % 2 == 1:
            hashes.append(hashes[-1])
        parent_level = []
        for x in range(0, len(hashes), 2):
            hash = double_sha256(hashes[x], hashes[x + 1])
            parent_level.append(hash)
        hashes = parent_level

    print(hashes[0].hex())



Thank you so much for the example! It's very easy to get confused with these reverse bytes and double hashing.

Here is a fully working code for MainNet:

Code:
#! /usr/bin/env python3
# -*- coding: utf-8 -*-
from hashlib import sha256

import json
import requests

DEFAULT_RPC_REGTEST_PORT = "18443"
DEFAULT_RPC_TEST_PORT = "18332"
DEFAULT_RPC_MAIN_PORT = "8332"

rpcAddress = "127.0.0.1"
rpcPort = DEFAULT_RPC_MAIN_PORT
rpcUser = "rpcuser"
rpcPassword = "rpcpassword"
rpcUrl = "http://" + rpcAddress + ":" + rpcPort

headers = {'content-type': 'application/json'}


# Double HASH SHA256
def double_sha256(data): return sha256(sha256(data).digest()).digest()


# Reverse
def r(data): return data[::-1]


def request_rpc(method, params):
    payload = json.dumps(
        {
            "method": method,
            "params": params
        }
    )
    return requests.request("POST", rpcUrl, data=payload, headers=headers,
                            auth=(rpcUser, rpcPassword))


if __name__ == "__main__":
    res = request_rpc(method="getblock", params=["00000000000000000000bd684e36789d16da2cf5b08b47deb72d1448a73eae5c"])
    tx = res.json()["result"]["tx"]

    hashes = [bytes.fromhex(x) for x in tx]
    while len(hashes) > 1:
        if len(hashes) % 2 == 1:
            hashes.append(hashes[-1])
        parent_level = []
        for i in range(0, len(hashes), 2):
            x = r(double_sha256(r(hashes[i]) + r(hashes[i + 1])))
            parent_level.append(x)
        hashes = parent_level
    merkleroot = hashes[0].hex()
    print(merkleroot)
xDilettante (OP)
Newbie
*
Offline Offline

Activity: 14
Merit: 1


View Profile
October 13, 2023, 07:57:09 PM
 #9

How do you create a "coinbase tx"? Can it be built via createrawtransaction or can it only be created in code? Then I don't fully understand how to build this transaction.

I will give you an example of a transaction from a real block, what I understand about it. What is marked with questions or not marked, I don't understand.

Code:
{
    "result": {
        "in_active_chain": true,
        "txid": "26110d654a1e52dd6fb6aa141e9ed37b83367daf3cfd35059188285bf5a4ca23",
        "hash": "fe239009e8a7c65da8ff48be0a50a3bd1cb19016e29d16453a94a89570b50ce9",
        "version": 2,
        "size": 214,
        "vsize": 187,
        "weight": 748,
        "locktime": 0,
        "vin": [
            {
                "coinbase": "03ed630c04a95e29652f466f756e6472792055534120506f6f6c202364726f70676f6c642f1a0727769676000000000000",
                "txinwitness": [
                    "0000000000000000000000000000000000000000000000000000000000000000"
                ],
                "sequence": 4294967295
            }
        ],
        "vout": [
            {
                "value": 6.36546374,
                "n": 0,
                "scriptPubKey": {
                    "asm": "0 35f6de260c9f3bdee47524c473a6016c0c055cb9",
                    "desc": "addr(bc1qxhmdufsvnuaaaer4ynz88fspdsxq2h9e9cetdj)#ry8yggxl",
                    "hex": "001435f6de260c9f3bdee47524c473a6016c0c055cb9",
                    "address": "bc1qxhmdufsvnuaaaer4ynz88fspdsxq2h9e9cetdj",
                    "type": "witness_v0_keyhash"
                }
            },
            {
                "value": 0.0,
                "n": 1,
                "scriptPubKey": {
                    "asm": "OP_RETURN aa21a9ed95c53abf59b8c6df571b1ca9ff8ad0e6f77a82b2b59c229463cda7a0281a4caf",
                    "desc": "raw(6a24aa21a9ed95c53abf59b8c6df571b1ca9ff8ad0e6f77a82b2b59c229463cda7a0281a4caf)#thl9sjed",
                    "hex": "6a24aa21a9ed95c53abf59b8c6df571b1ca9ff8ad0e6f77a82b2b59c229463cda7a0281a4caf",
                    "type": "nulldata"
                }
            }
        ],
        "hex": "020000000001010000000000000000000000000000000000000000000000000000000000000000ffffffff3103ed630c04a95e29652f466f756e6472792055534120506f6f6c202364726f70676f6c642f1a0727769676000000000000ffffffff0246edf0250000000016001435f6de260c9f3bdee47524c473a6016c0c055cb90000000000000000266a24aa21a9ed95c53abf59b8c6df571b1ca9ff8ad0e6f77a82b2b59c229463cda7a0281a4caf0120000000000000000000000000000000000000000000000000000000000000000000000000",
        "blockhash": "00000000000000000002faa1874cb499bcc39f45689a36387c4fbe9f3e5a28e4",
        "confirmations": 1,
        "time": 1697210044,
        "blocktime": 1697210044
    },
    "error": null,
    "id": null

Code:
# nVersion: 02000000
#   marker: 00
#     flag: 01
#     txIns:
#        #    countIns: 01
#        #          in: 0000000000000000000000000000000000000000000000000000000000000000
         #    sequence: ffffffff
         #              31 - ?????????????
         # heigt_block: 03ed630c
         #              04 - ?????????????
         #        time: a95e2965
         #     message: 2f466f756e6472792055534120506f6f6c202364726f70676f6c642f1a0727769676000000000000 - extranonce?
#                           : ffffffff
#                           : 02
#                           : 46edf025
#                           : 0000000016
#   (hex_address vout n - 0): 001435f6de260c9f3bdee47524c473a6016c0c055cb9
#                           : 000000000000000026
# default_witness_commitment: 6a24aa21a9ed95c53abf59b8c6df571b1ca9ff8ad0e6f77a82b2b59c229463cda7a0281a4caf  - ???????
#                   whitness: 01200000000000000000000000000000000000000000000000000000000000000000
#                  nLockTime: 00000000
j2002ba2
Full Member
***
Offline Offline

Activity: 204
Merit: 437


View Profile
October 13, 2023, 08:54:29 PM
Last edit: October 14, 2023, 12:27:37 AM by j2002ba2
 #10

How do you create a "coinbase tx"? Can it be built via createrawtransaction or can it only be created in code? Then I don't fully understand how to build this transaction.

Create it manually: createrawtransaction doesn't allow you to set the script of the input.

Code:
version: 02000000
marker: 00
flag: 01
txIns:
  num: 01
  in-1:
    txid: 0000000000000000000000000000000000000000000000000000000000000000
    index: ffffffff
    script:
      length: 31
      block-height-BIP34: 03 ed630c
      extra-nonce: 04a95e29652f466f756e6472792055534120506f6f6c202364726f70676f6c642f1a0727769676000000000000
    sequence: ffffffff
txOuts:
  num: 02
  out-1:
    value: 46edf02500000000
    script:
      length: 16
      P2SH: 00 14 35f6de260c9f3bdee47524c473a6016c0c055cb9
  out-2:
    value: 0000000000000000
    script:
      length: 26
      OP_RETURN: 6a
      OP_PUSH_36: 24
        commitment-header: aa21a9ed
        commitment-hash: 95c53abf59b8c6df571b1ca9ff8ad0e6f77a82b2b59c229463cda7a0281a4caf
witness:
  count: 01
  witness-1:
    length: 20
      data: 0000000000000000000000000000000000000000000000000000000000000000
locktime: 00000000

There are enough books explaining all this. I suggest to look inside "Programming Bitcoin" before asking here.


xDilettante (OP)
Newbie
*
Offline Offline

Activity: 14
Merit: 1


View Profile
October 15, 2023, 07:38:26 PM
 #11

On "regtest" when you try to send a block for confirmation(submitblock). I get an error. What could be the problem?

Code:
head_block:	02000000f8024dbfc207544804e79609b318eded16dc496a3d8ac37541b2f710b4baca5aede0d49252c8237598ae47f0078861c9fa1bad95a06b044228bb2fc6260fffbc633b2c65ffff7f20ceac66ad
txs: 0300
coinbase: 020000000001010000000000000000000000000000000000000000000000000000000000000000ffffffff3103cc00003f436653b8de179644bd49c22eedbf6fe1836393bb40cecc1b3160b40ecbdd64a8245c9ad3eb351487e7ae44e1ffffffff0240f831950000000042002024e4a9707352b05a15f9a2c0137f19f64f176b26ebe36e7d76bab3dde55aa200000000000000004c6a24aa21a9ed574959f5964b70e0bf54900f35d100b8755042d2c1da8e94bf755aa3411adce90120000000000000000000000000000000000000000000000000000000000000000000000000
tx0: 020000000001016f1b375ca92ed3d179aa6e210c4a474ee611a9b8a37804114a2e8c90dface1b50000000000fdffffff0260409f0600000000225120ce6e4ceb8f6d5a6b100ae9830c0cb87b6e7e0655940589be6a857a7ff5ee552600324f23010000002251207717106b74ff2b332e0f48d04e8342a7b8c4b7184f554cf9f6cad8bed1a600ed014024877d751eca430065e38b3015ed7c7ce60a837197e92a92d506a3f06d8f1f5937084b19f3166b16e4196aa123c655b9b9ac4ac6788a613c8cbde7cafc6604cfcb000000
tx1: 02000000000101b4a280789a22484e02f5b2d3f624e16bb60b9d05da9337bc678f6420cf540ba30000000000fdffffff02e0ce3e0d00000000225120e96eaa7a3def447531eb28b58ff0974974656d599566abb165160a4a0a5d673d80a3af1c01000000225120db9d070fd847cc0c0068f4c7f562874ab442ce105d8eef80fc4df1d6696f92b601400dcd13a372361fb006fadf9abefd9cf016dfe8d32838e986a1c0e34850f191d256cf06a0799a3978b9c7e3e2578dbc5453505137554fd7d8a692a13d3b39957bcb000000
{'result': None, 'error': {'code': -22, 'message': 'Block does not start with a coinbase'}, 'id': None}
Cricktor
Hero Member
*****
Offline Offline

Activity: 756
Merit: 1108


Crypto Swap Exchange


View Profile
October 15, 2023, 08:38:28 PM
 #12

Based on the error message, you either didn't assemble the coinbase transaction properly or it is not the first transaction in the block which it must be. I'm not going to deconstruct your hex strings, nor do you provide the full block that you want to submit in Regtest.

Oh, and when you have an odd number of transactions in your block, you have to pay attention to properly assemble the Merkle tree, because one transaction has to be doubled for Merkle hash calculation.

Did you even try to read a bit in "Programming Bitcoin" as @j2002ba2 suggested. I highly recommend it to you, too!

█▀▀▀











█▄▄▄
▀▀▀▀▀▀▀▀▀▀▀
e
▄▄▄▄▄▄▄▄▄▄▄
█████████████
████████████▄███
██▐███████▄█████▀
█████████▄████▀
███▐████▄███▀
████▐██████▀
█████▀█████
███████████▄
████████████▄
██▄█████▀█████▄
▄█████████▀█████▀
███████████▀██▀
████▀█████████
▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀
c.h.
▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄
▀▀▀█











▄▄▄█
▄██████▄▄▄
█████████████▄▄
███████████████
███████████████
███████████████
███████████████
███░░█████████
███▌▐█████████
█████████████
███████████▀
██████████▀
████████▀
▀██▀▀
xDilettante (OP)
Newbie
*
Offline Offline

Activity: 14
Merit: 1


View Profile
October 15, 2023, 08:47:56 PM
 #13

Based on the error message, you either didn't assemble the coinbase transaction properly or it is not the first transaction in the block which it must be. I'm not going to deconstruct your hex strings, nor do you provide the full block that you want to submit in Regtest.

Oh, and when you have an odd number of transactions in your block, you have to pay attention to properly assemble the Merkle tree, because one transaction has to be doubled for Merkle hash calculation.

Did you even try to read a bit in "Programming Bitcoin" as @j2002ba2 suggested. I highly recommend it to you, too!

This is a complete block in a HEX string. On the print, it's just broken down into objects to show where and what. If you combine all of these pieces, this is block
NotATether
Legendary
*
Offline Offline

Activity: 1582
Merit: 6718


bitcoincleanup.com / bitmixlist.org


View Profile WWW
October 17, 2023, 12:16:30 PM
 #14

On "regtest" when you try to send a block for confirmation(submitblock). I get an error. What could be the problem?

Code:
head_block:	02000000f8024dbfc207544804e79609b318eded16dc496a3d8ac37541b2f710b4baca5aede0d49252c8237598ae47f0078861c9fa1bad95a06b044228bb2fc6260fffbc633b2c65ffff7f20ceac66ad
~

I'm going to assume this is the block header, since it's exactly 160 hex characters long (= 80 bytes long, exactly matching the size)?

Code:
txs:		0300

If what I'm reading here in little-endian (3 transactions) is correct, note that according to the protocol documentation, the field for the number of transactions in the block header is always supposed to be zero. https://en.bitcoin.it/wiki/Protocol_documentation#Block_Headers

.
.BLACKJACK ♠ FUN.
█████████
██████████████
████████████
█████████████████
████████████████▄▄
░█████████████▀░▀▀
██████████████████
░██████████████
████████████████
░██████████████
████████████
███████████████░██
██████████
CRYPTO CASINO &
SPORTS BETTING
▄▄███████▄▄
▄███████████████▄
███████████████████
█████████████████████
███████████████████████
█████████████████████████
█████████████████████████
█████████████████████████
███████████████████████
█████████████████████
███████████████████
▀███████████████▀
█████████
.
j2002ba2
Full Member
***
Offline Offline

Activity: 204
Merit: 437


View Profile
October 17, 2023, 01:47:18 PM
Merited by Cricktor (1)
 #15

Code:
txs:		0300

If what I'm reading here in little-endian (3 transactions) is correct, note that according to the protocol documentation, the field for the number of transactions in the block header is always supposed to be zero. https://en.bitcoin.it/wiki/Protocol_documentation#Block_Headers

What you are reading here is the mistake. And the real link should be this one:
https://en.bitcoin.it/wiki/Protocol_documentation#block

You could see how it is in the very genesis block as well:
https://en.bitcoin.it/wiki/Genesis_block#Raw_block_data

Even in your link var_int (CompactSize) is used. It cannot be 2 bytes long.

Pages: [1]
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.19 | SMF © 2006-2009, Simple Machines Valid XHTML 1.0! Valid CSS!