[英]'code': -32603, 'message': 'Error: Transaction reverted without a reason string' while i'm trying to use swapExactTokensForTokens UNISWAP
I have read documentation on this function.我已阅读有关此功能的文档。 I'm using
Hardhat
to visualize Blockchain at a particular moment.我正在使用
Hardhat
在特定时刻可视化区块链。
I deposit()
ETH
to WETH
, then I approve()
WETH
to router.我
deposit()
ETH
WETH
,然后我将approve()
WETH
到路由器。 Everything looks fine.一切看起来都很好。 But when i try to call
swapExactTokensForTokens()
, it do not work.但是当我尝试调用
swapExactTokensForTokens()
时,它不起作用。 This is my code:这是我的代码:
from web3 import Web3
from interface import getInterface
import threading
import time
from Token import getERC20Abi
time1 = time.time()
w3 = Web3(Web3.HTTPProvider("http://127.0.0.1:8545/"))
uniswap = w3.eth.contract(address="0x7a250d5630B4cF539739dF2C5dAcb4c659F2488D", abi=getInterface())#UniswapV2Router02
walletAddress = Web3.toChecksumAddress('0x3c44cdddb6a900fa2b585dd299e03d12fa4293bc')
recipient = Web3.toChecksumAddress('0x14dc79964da2c08b23698b3d3cc7ca32193d9955')
ETHToken = w3.eth.contract(address='0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2', abi=getERC20Abi())
private_key = '0x5de4111afa1a4b94908f83103eb1f1706367c2e68ca870fc3fb9a804cdab365a'
Chuyen ETH sang WETH
transaction = ETHToken.functions.deposit().buildTransaction({
'chainId':31337,
'from': walletAddress,
'gas': 70000,
'value':1000000000000000000,
'maxFeePerGas': 57562177587,
'maxPriorityFeePerGas': w3.toWei('1', 'gwei'),
'nonce': 21
})
signed_txn = w3.eth.account.sign_transaction(transaction, private_key=private_key)
w3.eth.send_raw_transaction(signed_txn.rawTransaction)
print(ETHToken.functions.balanceOf(walletAddress).call())
Approve WETH cho Router
transaction_1 = ETHToken.functions.approve('0x7a250d5630B4cF539739dF2C5dAcb4c659F2488D', 1000000000000000000).buildTransaction({
'chainId':31337,
'from': walletAddress,
'gas': 70000,
'maxFeePerGas': 57562177587,
'maxPriorityFeePerGas': w3.toWei('1', 'gwei'),
'nonce': 22
})
signed_txn_1 = w3.eth.account.sign_transaction(transaction_1, private_key=private_key)
w3.eth.send_raw_transaction(signed_txn_1.rawTransaction)
print("Luong WETH da improve cho router:")
print(ETHToken.functions.allowance(Web3.toChecksumAddress('0xf39fd6e51aad88f6f4ce6ab8827279cfffb92266'), '0x7a250d5630B4cF539739dF2C5dAcb4c659F2488D').call())
# Swap WETH vs ENJ
timestamp = int((time.time() + 100000000000)//1)
transaction_2 = uniswap.functions.swapExactTokensForTokens(100000000000000000,0,
["0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2","0xF629cBd94d3791C9250152BD8dfBDF380E2a3B9c"],
recipient,timestamp).buildTransaction({
'chainId':31337,
'gas': 70000,
'from': walletAddress,
'maxFeePerGas': 57562177587,
'maxPriorityFeePerGas': w3.toWei('1', 'gwei'),
'nonce': 23
})
signed_txn_2 = w3.eth.account.sign_transaction(transaction_2, private_key=private_key)
w3.eth.send_raw_transaction(signed_txn_2.rawTransaction)
# print(ETHToken.functions.allowance(walletAddress, '0x7a250d5630B4cF539739dF2C5dAcb4c659F2488D').call())
pls explain it for me请为我解释一下
If you look at your hardhat console output, you should see something like this (this is example output found somewhere else online):如果您查看您的安全帽控制台输出,您应该会看到类似这样的内容(这是在网上其他地方找到的示例输出):
Error: Transaction reverted without a reason string
at <UnrecognizedContract>.<unknown> (0x5aa53f03197e08c4851cad8c92c7922da5857e5d)
at <UnrecognizedContract>.<unknown> (0x5aa53f03197e08c4851cad8c92c7922da5857e5d)
at processTicksAndRejections (node:internal/process/task_queues:96:5)
at runNextTicks (node:internal/process/task_queues:65:3)
at listOnTimeout (node:internal/timers:526:9)
at processTimers (node:internal/timers:500:7)
at async EthModule._estimateGasAction (node_modules/hardhat/src/internal/hardhat-network/provider/modules/eth.ts:425:7)
at async HardhatNetworkProvider.request (node_modules/hardhat/src/internal/hardhat-network/provider/provider.ts:108:18)
at async EthersProviderWrapper.send (node_modules/@nomiclabs/hardhat-ethers/src/internal/ethers-provider-wrapper.ts:13:20)
In this case, you can at least see the contract address ( 0x5aa53f03197e08c4851cad8c92c7922da5857e5d
) that was causing the revert.在这种情况下,您至少可以看到导致还原的合约地址(
0x5aa53f03197e08c4851cad8c92c7922da5857e5d
)。 I think with uniswap, even with WETH, there's a separate function you need to use to swap it.我认为使用 uniswap,即使使用 WETH,也需要使用单独的函数来交换它。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.