【发布时间】:2021-06-02 15:49:45
【问题描述】:
我正在尝试使用 swapExactTokensForTokens()(Pancakeswap 路由器功能)交换令牌。
这是我的代码
def swapTokens():
amountIn = (w3.toWei(0.00001, 'ether'))
amount1 = contractR.functions.getAmountsOut(
amountIn,
[wbnb, tokenToBuy]
).call()
amountOutMin = amount1[1] * 0.9
minAmountPrint = w3.fromWei(amountOutMin, 'ether')
print('Minimum recieved:', minAmountPrint)
swap_TX = contractR.functions.swapExactTokensForTokens(
amountIn,
amountOutMin,
[wbnb, tokenToBuy],
myAccount,
(int(time.time()) + 1000000)
).buildTransaction({
'from': myAccount,
'value': w3.toWei(0.0001, 'ether'),
'gas': 250000,
'gasPrice': w3.toWei('5', 'gwei'),
'nonce': nonce,
})
signed_TX = w3.eth.account.sign_transaction(swap_TX, private_key=privateKey)
tx_token = w3.eth.send_raw_transaction(signed_TX.rawTransaction)
print(w3.toHex(tx_token))
但结果我不断收到错误:
Could not identify the intended function with name `swapExactTokensForTokens`, positional argument(s) of type `(<class 'int'>, <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 no matching argument types.
我检查了传递给函数的每个参数的类型并匹配。
【问题讨论】:
-
你传递的第二个参数是类型'float'而不是'int'。这可能是问题吗?
-
这就是问题所在。谢谢!顺便说一句,交易失败。您是否知道有一项服务可以帮助我弄清楚它在 tx 的哪一步失败?
-
嘿@richie,既然是这样,也许考虑发布您的 somment 作为答案,以便 OP 可以接受它以获得甜蜜的 +10 声誉:b
-
我喜欢我的代表@jemand771:D
-
你可以用其他问题的详细信息编辑问题或用它打开一个新帖子吗?