Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cant deploy solidity contract with python #3141

Closed
zmctinas opened this issue Nov 3, 2023 · 1 comment
Closed

cant deploy solidity contract with python #3141

zmctinas opened this issue Nov 3, 2023 · 1 comment

Comments

@zmctinas
Copy link

zmctinas commented Nov 3, 2023

  • Version: 5.31.3
  • Python:3.9.16
  • OS: osx

What was wrong?

Please include any of the following that are applicable:

  • The code which produced the error
def compile_source_file(self, file_path):
    with open(file_path, 'r') as f:
        source = f.read()

    return compile_source(source, output_values=['abi', 'bin'])

contract_source_path = os.path.join(base_dir, 'contracts/greeter.sol')

compiled_sol = self.compile_source_file(contract_source_path)
contract_id, contract_interface = compiled_sol.popitem()
contract = self.w3.eth.contract(abi=contract_interface['abi'], bytecode=contract_interface['bin'])

gas = self.w3.eth.gas_price
nonce = self.w3.eth.getTransactionCount(wallet_address)
chain_id = self.w3.eth.chain_id


deploy_transaction = contract.constructor().build_transaction({
    'chainId': chain_id,
    'from': wallet_address,
    'gas': 4000000,
    'gasPrice': gas,
    'nonce': nonce,
})
signed_txn = account.sign_transaction(deploy_transaction)
tx_hash = self.w3.eth.send_raw_transaction(signed_txn.rawTransaction)

tx_receipt = self.w3.eth.waitForTransactionReceipt(tx_hash)

contract_address = tx_receipt['contractAddress']
print(f'contract_address: {contract_address}')
  • The full output of the error
Traceback (most recent call last):
  File "/Users/xiaoweiwang/Documents/python/bl-batch-operations/scripts/contract_module/deploy_contract.py", line 85, in <module>
    dc.deploy_contract('a5c5bb8d49d75b71247900e28cfe628396ab')
  File "/Users/xiaoweiwang/Documents/python/bl-batch-operations/scripts/contract_module/deploy_contract.py", line 72, in deploy_contract
    tx_hash = self.w3.eth.send_raw_transaction(signed_txn.rawTransaction)
  File "/Users/xiaoweiwang/.local/share/virtualenvs/bl-batch-operations-5D3lKCYn/lib/python3.9/site-packages/web3/eth.py", line 831, in send_raw_transaction
    return self._send_raw_transaction(transaction)
  File "/Users/xiaoweiwang/.local/share/virtualenvs/bl-batch-operations-5D3lKCYn/lib/python3.9/site-packages/web3/module.py", line 57, in caller
    result = w3.manager.request_blocking(method_str,
  File "/Users/xiaoweiwang/.local/share/virtualenvs/bl-batch-operations-5D3lKCYn/lib/python3.9/site-packages/web3/manager.py", line 198, in request_blocking
    return self.formatted_response(response,
  File "/Users/xiaoweiwang/.local/share/virtualenvs/bl-batch-operations-5D3lKCYn/lib/python3.9/site-packages/web3/manager.py", line 171, in formatted_response
    raise ValueError(response["error"])
ValueError: {'code': 3, 'message': 'Failed to serialize transaction: toAddressIsNull'}

how to fix it please

@fselmo
Copy link
Collaborator

fselmo commented Nov 3, 2023

ValueError: {'code': 3, 'message': 'Failed to serialize transaction: toAddressIsNull'}

This is coming from your node, not the library. I assume you want to deploy the contract so you likely need to specify the zero address ("0x0000000000000000000000000000000000000000") in the "to" field of your transaction with the current setup.

For usage questions, please refer to the documentation or ask in the Discord server.

@fselmo fselmo closed this as not planned Won't fix, can't repro, duplicate, stale Nov 3, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants