running Web3 5.13; python 3.9; Mac 10.15.7

Trying to run test on solidity contract based on the example provided in teh Web3.py docs. When running this I receive an error stating TypeError: estimate_gas() takes 2 positional arguments but 3 were given.

When I pass a specific value in for gas I do not receive the error. But I have not received this when running similar smart contract transactions. How can I resolve this?

The error is called on the tx_hash = LotteryContract.constructor().transact({ 'from': deploy_address, }) line.

import os
import pytest
from solcx import compile_source
from web3 import EthereumTesterProvider, Web3

def tester_provider():
    e = EthereumTesterProvider()
    return e

def w3(tester_provider):
    return Web3(tester_provider)

def ether_tester(tester_provider):
    return tester_provider.ethereum_tester

def compiled_contract():
    contract_path = os.path.join(os.getcwd(), 'lottery.sol')

    with open(contract_path, 'r') as f:
        source = f.read()

    return compile_source(source)

def lottery_contract(w3, ether_tester, compiled_contract):
    contract_id, contract_interface = compiled_contract.popitem()

    deploy_address = ether_tester.get_accounts()[0]

    LotteryContract = w3.eth.contract(

    tx_hash = LotteryContract.constructor().transact({
        'from': deploy_address,

    tx_receipt = w3.eth.waitForTransactionReceipt(tx_hash, 180)
    return LotteryContract(tx_receipt.contractAddress)

def test_deploys_contract(lottery_contract):
    i = lottery_contract.functions.getPlayers().call()
    assert 1 == i


self = <eth_tester.main.EthereumTester object at 0x7ff073b85c40>
transaction = {'data': '0x6060604052341561000f57600080fd5b336000806101000a81548173ffffffffffffffffffffffffffffffffffffffff0219169083...ad680f662db6452e96bfca95e817c346bcc2a08a49e6f6726acd20ec3a70029', 'from': '0xaBbACadABa000000000000000000000000000000'}
block_number = 'latest'

    def estimate_gas(self, transaction, block_number="latest"):
        self.validator.validate_inbound_transaction(transaction, txn_type='estimate')
        raw_transaction = self.normalizer.normalize_inbound_transaction(transaction)
        raw_block_number = self.normalizer.normalize_inbound_block_number(block_number)
>       raw_gas_estimate = self.backend.estimate_gas(raw_transaction, raw_block_number)
E       TypeError: estimate_gas() takes 2 positional arguments but 3 were given

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.