[英]ValidationError on smart contract function call for no apparent reason(web3py)?
我正在嘗試調用 Uniswap 的路由器 function swapExactTokensForETHSupportingFeeOnTransferTokens() 。 當我在 etherscan 上手動輸入值時,它會通過。 但是,當我通過 python 代碼執行此操作時,它會給我一個驗證錯誤。 錯誤如下所示:
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.
這是我使用的代碼:
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)
我是否應該以某種方式將我的整數轉換為 python 中的無符號整數? 我試過了,但沒有解決。 我正在使用 web3py 庫。 有人可以指導我解決這個問題或調用 function 的現有代碼嗎?
謝謝。
編輯:
我將時間戳轉換為 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)
當我運行它時,它給了我這個錯誤:
raise SolidityError(response['error']['message']) web3.exceptions.SolidityError:執行恢復:TransferHelper:TRANSFER_FROM_FAILED
您傳遞的 arguments 類型與 function 的預期參數類型不匹配。
你正在通過:
int, int, list, str, float
但 function 期望:
uint256, uint256, address[], address, uint256
我猜這是導致不匹配的最后一個參數unix_time_stamp_deadline
。 它是一個浮點數,但 function 需要一個整數。 您可以在將其傳遞給 function 時將其轉換為 int,如下所示:
int(unix_time_stamp_deadline)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.