简体   繁体   English

智能合约 function 上的 ValidationError 无明显原因调用(web3py)?

[英]ValidationError on smart contract function call for no apparent reason(web3py)?

I am trying to call Uniswap's Router's function swapExactTokensForETHSupportingFeeOnTransferTokens() .我正在尝试调用 Uniswap 的路由器 function swapExactTokensForETHSupportingFeeOnTransferTokens() When I enter the values manually on etherscan, it goes through.当我在 etherscan 上手动输入值时,它会通过。 However, when I do it via python code it gives me a validation error.但是,当我通过 python 代码执行此操作时,它会给我一个验证错误。 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?我是否应该以某种方式将我的整数转换为 python 中的无符号整数? I tried but it didn't fix it.我试过了,但没有解决。 Im using the web3py library.我正在使用 web3py 库。 Could someone direct me to the issue or to existing code that calls said function?有人可以指导我解决这个问题或调用 function 的现有代码吗?

Thanks.谢谢。

Edit:编辑:

I converted timestamp into int and also made sure my address strings were checksum using the web3.toChecksum method.我将时间戳转换为 int,并使用 web3.toChecksum 方法确保我的地址字符串是校验和。

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 raise SolidityError(response['error']['message']) web3.exceptions.SolidityError:执行恢复:TransferHelper:TRANSFER_FROM_FAILED

The arguments types that you are passing do not match the expected argument types for the function.您传递的 arguments 类型与 function 的预期参数类型不匹配。

You are passing:你正在通过:

int, int, list, str, float

but the function expects:但 function 期望:

uint256, uint256, address[], address, uint256

I'm guessing that it is the last argument, unix_time_stamp_deadline , that is causing the mismatch.我猜这是导致不匹配的最后一个参数unix_time_stamp_deadline It is a float, but the function expects an int.它是一个浮点数,但 function 需要一个整数。 You can convert it to an int as you pass it to the function like this:您可以在将其传递给 function 时将其转换为 int,如下所示:

int(unix_time_stamp_deadline)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM