Python – Earlybirds Invest https://earlybirdsinvest.com Latest Crypto News Sun, 25 May 2025 22:04:35 +0000 en-US hourly 1 https://wordpress.org/?v=6.9.8 https://i0.wp.com/earlybirdsinvest.com/wp-content/uploads/2024/12/cropped-New-Project-2024-12-17T235703.455.png?fit=32%2C32&ssl=1 Python – Earlybirds Invest https://earlybirdsinvest.com 32 32 240146708 How to generate a Coinbase transaction in Python? https://earlybirdsinvest.com/how-to-generate-a-coinbase-transaction-in-python/ https://earlybirdsinvest.com/how-to-generate-a-coinbase-transaction-in-python/#respond Sun, 25 May 2025 22:04:35 +0000 https://earlybirdsinvest.com/how-to-generate-a-coinbase-transaction-in-python/ I know that there are many questions on this forum about this topic, but I have checked most of these but can’t find a solution for my task. I’m writing my own algorithm for Solo Mining Bitcoin in Python. I’ve written all the methods needed to do this. This includes calculations such as hashing of the Merkle route, block headers, and more. But now I’ve been stuck in a Coinbase transaction for a few weeks. I’ve studied the Coinbase transaction page at LearnMeabitcoin.com and tried to implement all the logic, but I can’t fully understand how to create it. I would like to include a new rule (BIP34-block header, BIP141-SEGWIT TX) in this algorithm, but my knowledge about hashing this is not sufficient. 🙁

Could someone perhaps provide more material, code samples, or explain more about generating Coinbase transactions? Any information is very helpful, I hope for your help.

I’m also training my Bitcoin core in Regtest mode. Using the “GenerateToAddress” method (for generation block), if you don’t use Coinbase Tx with BIP34 and BIP141 requirements, do you need to set this setting? I found someone saying something about the block version of Arg, is that true?

Thank you very much ^^

PS If I missed the details of my task, I can freely ask and provide all the information I have, a sample of code I have (it’s not working)

update
I have great news, I’ll find a solution and complete this) Thanks for your support. But there is only one question left. I use Object to generate the Tx on the screen. There is a difference from Coinbase Tx generated with Bitcoin Core using GenerateToAddress only in one location, submitting n in the first output. Can someone explain what it is? I’m using a P2WPKH script for the hash address, is this the type? Adding this value everything worked fine, and after broadcasting to Build Block header and full block and node, I succeeded in General Coinbasetx. However, just to fully understand my code, I would like to know what this means “0000000” means, but the name “n” in the field was my own.
Enter the image description here

]]>
https://earlybirdsinvest.com/how-to-generate-a-coinbase-transaction-in-python/feed/ 0 38295
How can I get the actual balance of XPub in Python Bitcoinlib? https://earlybirdsinvest.com/how-can-i-get-the-actual-balance-of-xpub-in-python-bitcoinlib/ https://earlybirdsinvest.com/how-can-i-get-the-actual-balance-of-xpub-in-python-bitcoinlib/#respond Sun, 09 Mar 2025 13:23:59 +0000 https://earlybirdsinvest.com/how-can-i-get-the-actual-balance-of-xpub-in-python-bitcoinlib/

goal

Create a wallet feature for at least Watch only in Python. Included send I’ll be sitting in the future too.

detail

I’m already sharing my code on GitHub (in Python). I’m looking for some feedback and trying to clarify some of the concepts I lack.

You can make any ideas, but here are the specific questions I have. I’m a complete noob in the Bitcoin world, so some clarifications are appreciated.

question

  • Is that there? bitcoinlib Python library interface with Authentic Bitcoin blockchain? I understand that there are some kind of test chain where you can get free test coins. But is there a tutorial on how to use it, especially using the Python library?
  • Seed word generated data/seed.txt Using Blue Wallet (BW), XPUB exposed by BW matches what was returned by CustomWallet.get_xpub method. However, the receiving address from BW is do not have Match CustomWallet.get_address method. What does that mean? I understand that under Xpub there are multiple (infinite?) receiving addresses, but is that why?
  • If you send SATS to the address generated by CustomWallet.get_addressif initialized with the same species, will it appear in my blue wallet? And the other way around?
  • Should wallet.transactions(include_new=True) Please tell me about unconfirmed transactions. I have an unconfirmed transaction (in the actual blockchain I sent it from Trezor), but it doesn’t show up when calling a method in Python.
  • You should do Wallet.balance() Do you show the actual balance of a method blockchain wallet? I transferred some amount to the wallet that BW is displaying, but my code says it’s zero balance. What gives?
  • What is the best way to send and receive multiple transactions through code? Authentic Blockchain works as much as possible, but will it be wasted my sat?
]]>
https://earlybirdsinvest.com/how-can-i-get-the-actual-balance-of-xpub-in-python-bitcoinlib/feed/ 0 24153
Python script – Ckeys not extracted https://earlybirdsinvest.com/python-script-ckeys-not-extracted/ https://earlybirdsinvest.com/python-script-ckeys-not-extracted/#respond Fri, 28 Feb 2025 16:08:15 +0000 https://earlybirdsinvest.com/python-script-ckeys-not-extracted/

I have this code:

#!/usr/bin/env python3

# pip3 install pycryptodome bsddb3

import os
import bsddb3.db as bdb
import struct

def extract_keys(wallet_path):
    try:
        # Open the wallet.dat file
        db_env = bdb.DBEnv()
        db_env.open(os.path.dirname(wallet_path), bdb.DB_CREATE | bdb.DB_INIT_MPOOL)
        db = bdb.DB(db_env)
        db.open(wallet_path, "main", bdb.DB_BTREE, bdb.DB_RDONLY)

        mkey, ckeys = None, ()

        for key, value in db.items():
            if key.startswith(b'\x04mkey'):
                mkey = value  # Extract master key
            elif key.startswith(b'\x07ckey'):
                ckeys.append(value)  # Extract crypted keys

        db.close()
        db_env.close()

        return {"mkey": mkey, "ckeys": ckeys}

    except Exception as e:
        print(f"Error: {e}")
        return None

if __name__ == "__main__":
    for infile in os.listdir('.'):
        if os.path.isfile(infile) and infile(-4:)=='.dat':
            result = extract_keys(infile)

            if result:
                print(f"File: {infile}")
                print(f"mkey: {result('mkey').hex() if result('mkey') else 'Not found'}")
                print(f"ckey: {(ckey.hex() for ckey in result('ckeys'))}\n")
            else:
                print("Failed to extract keys.")

Mkeys extracts, but ckeys don’t. How to fix it?

Do you want to properly extract MKEY?

]]>
https://earlybirdsinvest.com/python-script-ckeys-not-extracted/feed/ 0 22447