I'm currently facing an issue when interacting with an Ethereum smart contract using Python's Web3 module. More specifically, I'm trying to call a specific function named "requestL2Transaction" from the contract with a set of arguments, but I keep getting an error stating that the argument types do not match.
The function signature in the contract's ABI is as follows:
requestL2Transaction(address,uint256,bytes,uint256,uint256,bytes[],address)
And I'm trying to call it as follows (actual values have been replaced with generic representations for security reasons):
contract_address = "<contract_address>"
abi = <abi> # The actual ABI of the contract
function_name = "requestL2Transaction"
blockchain = "ethereum"
wallet = <wallet> # My wallet instance
# The arguments for the function
_contractL2 = "0x..."
_l2Value = 10000000000000000
_calldata = b''
_l2GasLimit = 1100000
_gasPricePerPubdata = 800
_factoryDeps = []
_refundRecipient = "0x..."
interact_with_contract(wallet, contract_address, abi, function_name, blockchain, None,
_contractL2=_contractL2, _l2Value=_l2Value, _calldata=_calldata,
_l2GasLimit=_l2GasLimit, _gasPricePerPubdata=_gasPricePerPubdata, _factoryDeps=_factoryDeps, _refundRecipient=_refundRecipient)
Here is the code of my "interact_with_contract" function:
async def interact_with_contract(self, wallet, contract_address, abi, function_name, blockchain, msg_value=None, *args, **kwargs):
contract = self.web3.eth.contract(address=contract_address, abi=abi)
function = contract.functions[function_name]
try:
function_call = function(*args, **kwargs)
except Exception as e:
# Handle exception
# ...
return
# Other operations
# ...
The returned error is the following:
ERROR - Error while building function call : Could not identify the intended function with name
requestL2Transaction, positional arguments with type(s) `` and keyword arguments with type(s){'_l2GasLimit': 'int', '_refundRecipient': 'address', '_gasPricePerPubdata': 'int', '_contractL2': 'address', '_calldata': 'bytes', '_factoryDeps': '(bytes)', '_l2Value': 'int'}. Found 1 function(s) with the namerequestL2Transaction: ['requestL2Transaction(address,uint256,bytes,uint256,uint256,bytes[],address)'] Function invocation failed due to no matching argument types.
As you can see, it seems like the argument types passed do not match those expected by the contract function, even though I have checked multiple times and they seem correct.
If anyone has faced a similar issue before or has an idea of what might be causing this error, I would be very grateful for any help or advice.