path = [TETHER, wAVAX, TIME]
contract_txn = contract_TJ_ROUTER.functions.swapExactTokensForTokens( Web3.toWei(380.27, 'ether'), Web3.toWei(0, 'ether'), path , address_wallet, block['timestamp']+30 ).buildTransaction({
'type': '0x2',
'chainId': 31337,
'gas': 8000000,
'maxFeePerGas': 2 * block['baseFeePerGas'], # required for dynamic fee transactions
'maxPriorityFeePerGas': 0, # required for dynamic fee transactions
'nonce': nonce,
})
signed = w3.eth.account.sign_transaction(contract_txn, privatekey)
tx_hash =w3.eth.send_raw_transaction(signed.rawTransaction)
Above is the transaction sign formatting I have been using. I am trying to swap Tether for TIME via wAVAX. (I am trying this transaction on Avalanche, an EVM chain).
I was able to successfully implement swapExactAVAXForTokens
function to go from wAVAX to Tether. So I think I have a rough idea of how EIP-1559 works and calling functions works.
However, when running the block of code above, I get the following error:
File "traderjoe_swap.py", line 169, in <module>
tx_hash =w3.eth.send_raw_transaction(signed.rawTransaction)
File "/home/blackwidow/.local/lib/python3.8/site-packages/web3/eth.py", line 698, in send_raw_transaction
return self._send_raw_transaction(transaction)
File "/home/blackwidow/.local/lib/python3.8/site-packages/web3/module.py", line 57, in caller
result = w3.manager.request_blocking(method_str,
File "/home/blackwidow/.local/lib/python3.8/site-packages/web3/manager.py", line 187, in request_blocking
return self.formatted_response(response,
File "/home/blackwidow/.local/lib/python3.8/site-packages/web3/manager.py", line 168, in formatted_response
raise ValueError(response["error"])
ValueError: {'code': -32603, 'message': "Error: VM Exception while processing transaction: reverted with reason string 'TransferHelper: TRANSFER_FROM_FAILED'", 'data': {'txHash': '0x5c3531ff85064d8e8458881631d5b7ed60a8ff8160b7d09923c748682d8d496a'}}
I have looked at the chain explorer to see some example execution of swapExactTokensForTokens
to make sure I had the right input arguments.
P.S. When trying to implement swapExactAVAXForTokens
to go from wAVAX to Tether to TIME, the transaction does not throw an error and it does subtract the right amount of AVAX but I do not receive either Tether nor TIME in return.