Estoy tratando de intercambiar tokens usando swapExactTokensForTokens()
(función Pancakeswap Router), web3 importado en Python. Aquí está mi código y el error a continuación. Sea específico en sus respuestas, ya que soy un novato en la codificación.
tokenToSpend=$BUSD, tokenToBuy=$CAKE
Código:
#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,
})
Aquí está el mensaje de error:
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.
Solución del problema
Intente volver a copiar y pegar sus ABI de fábrica o de enrutador... Parece que encontré y reemplacé "MyVariableName" de "WBNB" (o "WETH") en las ABI mencionadas. Se deshizo de ese error después de mirar un poco
No hay comentarios.:
Publicar un comentario