Web3.py Guide – How to Use sendRawTransaction in Python

djangopythonweb3.py

I read the web3.eth.API carefully and I typed the code in my project.

    signed_txn = self.web3.eth.account.signTransaction(
        {
            'nonce': self.web3.eth.getTransactionCount(Web3.toChecksumAddress(self.address)),
            'gasPrice': Web3.toWei(21, 'gwei'),
            'from': Web3.toChecksumAddress(self.address),
            'gas': 21000,
            'to': recipient,
            # 'chainId': 1,
            'value': Web3.toWei(amount, 'ether')
        },
        private_key
    )

This code doesn't run.
Here what I can't understand is as follow.

  1. chainId: What value is this?
  2. private_key: I can't get this value. I created ethereum wallet using pywallet.

Wallet to be created using pywallet is HD Wallet.
If anyone know about this, plz help me.

Best Answer

ChainID was introduced in EIP-155 to prevent replay attacks between the main ETH and ETC chains, which both have a networkID of 1.

For the Ethereum Mainnet the ChainID is 1 you can check the ChainId on the table at the end of EIP-155

When you create a new wallet with pywallet the output shows you the private key you can see this in the documentation