Error: Could not identify the intended function with name 'swapExactTokensForTokens'
Error: Could not identify the intended function with name 'swapExactTokensForTokens'
我正在尝试使用 swapExactTokensForTokens()
(Pancakeswap 路由器功能)交换令牌,在 Python 中导入 web3。下面是我的代码和错误。请具体回答,因为我是编码新手。
tokenToSpend=$BUSD, tokenToBuy=$CAKE
代码:
#Calculate minimum amount of tokens to receive
receive = contract.functions.getAmountsOut(amount, [tokenToSpend, tokenToBuy]).call()
minReceived = receive[1] * (9/10)
receiveReadable = web3.fromWei(minReceived,'ether')
print("Minimum tokens to recieve:", str(receiveReadable))
#Trade execution:
pancakeswap2_txn = contract.functions.swapExactTokensForTokens(minReceived, [tokenToSpend,tokenToBuy], sender_address, (int(time.time()) + 1000000)).buildTransaction({
'from': sender_address,
'value': web3.toWei(amount,'ether'),
'gasPrice': web3.toWei('5','gwei'),
'nonce': nonce,
})
这是错误消息:
Traceback (most recent call last):
File "c:/Users/Owner/Documents/BlockchainPy/MyCodes/BuyPancake.py", line 64, in <module>
pancakeswap2_txn = contract.functions.swapExactTokensForTokens(minReceived, [spend,tokenToBuy], sender_address, (int(time.time()) + 1000000)).buildTransaction({
File "C:\Users\Owner\Documents\BlockchainPy\lib\site-packages\web3\contract.py",
line 876, in __call__
clone._set_function_info()
File "C:\Users\Owner\Documents\BlockchainPy\lib\site-packages\web3\contract.py",
line 881, in _set_function_info
self.abi = find_matching_fn_abi(
File "C:\Users\Owner\Documents\BlockchainPy\lib\site-packages\web3\_utils\contracts.py", line 163, in find_matching_fn_abi
raise ValidationError(message)
web3.exceptions.ValidationError:
Could not identify the intended function with name `swapExactTokensForTokens`, positional argument(s) of type `(<class 'float'>, <class 'list'>, <class 'str'>, <class 'int'>)` and keyword argument(s) of type `{}`.
Found 1 function(s) with the name `swapExactTokensForTokens`: ['swapExactTokensForTokens(uint256,uint256,address[],address,uint256)']
Function invocation failed due to improper number of arguments.
在 minReceived 之后,您需要提供 minAmountOut,这基本上是滑点。尝试 0,这将基本上匹配最优惠的价格,它应该有效
尝试 re-copy-and-pasting 您的工厂或路由器 ABI...我似乎在上述 ABI 中找到并替换了“WBNB”(或“WETH”)中的“MyVariableName”。环顾四周后摆脱了那个错误
我正在尝试使用 swapExactTokensForTokens()
(Pancakeswap 路由器功能)交换令牌,在 Python 中导入 web3。下面是我的代码和错误。请具体回答,因为我是编码新手。
tokenToSpend=$BUSD, tokenToBuy=$CAKE
代码:
#Calculate minimum amount of tokens to receive
receive = contract.functions.getAmountsOut(amount, [tokenToSpend, tokenToBuy]).call()
minReceived = receive[1] * (9/10)
receiveReadable = web3.fromWei(minReceived,'ether')
print("Minimum tokens to recieve:", str(receiveReadable))
#Trade execution:
pancakeswap2_txn = contract.functions.swapExactTokensForTokens(minReceived, [tokenToSpend,tokenToBuy], sender_address, (int(time.time()) + 1000000)).buildTransaction({
'from': sender_address,
'value': web3.toWei(amount,'ether'),
'gasPrice': web3.toWei('5','gwei'),
'nonce': nonce,
})
这是错误消息:
Traceback (most recent call last):
File "c:/Users/Owner/Documents/BlockchainPy/MyCodes/BuyPancake.py", line 64, in <module>
pancakeswap2_txn = contract.functions.swapExactTokensForTokens(minReceived, [spend,tokenToBuy], sender_address, (int(time.time()) + 1000000)).buildTransaction({
File "C:\Users\Owner\Documents\BlockchainPy\lib\site-packages\web3\contract.py",
line 876, in __call__
clone._set_function_info()
File "C:\Users\Owner\Documents\BlockchainPy\lib\site-packages\web3\contract.py",
line 881, in _set_function_info
self.abi = find_matching_fn_abi(
File "C:\Users\Owner\Documents\BlockchainPy\lib\site-packages\web3\_utils\contracts.py", line 163, in find_matching_fn_abi
raise ValidationError(message)
web3.exceptions.ValidationError:
Could not identify the intended function with name `swapExactTokensForTokens`, positional argument(s) of type `(<class 'float'>, <class 'list'>, <class 'str'>, <class 'int'>)` and keyword argument(s) of type `{}`.
Found 1 function(s) with the name `swapExactTokensForTokens`: ['swapExactTokensForTokens(uint256,uint256,address[],address,uint256)']
Function invocation failed due to improper number of arguments.
在 minReceived 之后,您需要提供 minAmountOut,这基本上是滑点。尝试 0,这将基本上匹配最优惠的价格,它应该有效
尝试 re-copy-and-pasting 您的工厂或路由器 ABI...我似乎在上述 ABI 中找到并替换了“WBNB”(或“WETH”)中的“MyVariableName”。环顾四周后摆脱了那个错误