Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
595 views
in Technique[技术] by (71.8m points)

python - ValidationError on smart contract function call for no apparent reason(web3py)?

I am trying to call Uniswap's Router's function swapExactTokensForETHSupportingFeeOnTransferTokens(). When I enter the values manually on etherscan, it goes through. However, when I do it via python code it gives me a validation error. The error looks like this:

web3.exceptions.ValidationError: Could not identify the intended function with name swapExactTokensForETHSupportingFeeOnTransferTokens, positional argument(s) of type (<class int>, <class int>, <class list>, <class str>, <class float>) and keyword argument(s) of type {}. Found 1 function(s) with the name swapExactTokensForETHSupportingFeeOnTransferTokens: [swapExactTokensForETHSupportingFeeOnTransferTokens(uint256,uint256,address[],address,uint256)] Function invocation failed due to no matching argument types.

Here's the code im using:

swap = uniswap_router_contract.functions.swapExactTokensForETHSupportingFeeOnTransferTokens(uint amount, 0, list_of_two_token_addresses, my_address_string, unix_time_stamp_deadline).buildTransaction({'nonce': some_nonce})

gas_amount = web3.eth.estimateGas(swap)

print(gas amount)

Am I supposed to somehow turn my ints into unsigned int in python? I tried but it didn't fix it. Im using the web3py library. Could someone direct me to the issue or to existing code that calls said function?

Thanks.

Edit:

I converted timestamp into int and also made sure my address strings were checksum using the web3.toChecksum method.

swap = uniswap_router_contract.functions.swapExactTokensForETHSupportingFeeOnTransferTokens(uint amount, 0, list_of_two_token_addresses, my_address_string, int(unix_time_stamp_deadline)).buildTransaction({'nonce': some_nonce})
gas = web3.eth.estimateGas(swap)
print(gas)

When I run this it gives me this error:

raise SolidityError(response['error']['message']) web3.exceptions.SolidityError: execution reverted: TransferHelper: TRANSFER_FROM_FAILED

question from:https://stackoverflow.com/questions/65951183/validationerror-on-smart-contract-function-call-for-no-apparent-reasonweb3py

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

The arguments types that you are passing do not match the expected argument types for the function.

You are passing:

int, int, list, str, float

but the function expects:

uint256, uint256, address[], address, uint256

I'm guessing that it is the last argument, unix_time_stamp_deadline, that is causing the mismatch. It is a float, but the function expects an int. You can convert it to an int as you pass it to the function like this:

int(unix_time_stamp_deadline)

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...