简体   繁体   English

'code': -32603, 'message': 'Error: Transaction reverted without a reason string' 当我尝试使用 swapExactTokensForTokens UNISWAP

[英]'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.

相关问题 Json请求中的错误:{“ jsonrpc”:“ 2.0”,“ id”:44,“错误”:{“代码”:-32603,“消息”:“没有此类服务方法”}} - Error in Json request :{“jsonrpc”:“2.0”,“id”:44,“error”:{“code”:-32603,“message”:“No such service method”}} 尝试使用 python -m pip install datatable 在 python 3.7.4 中安装数据表时收到错误消息 - I received an error message while trying to install datatable in python 3.7.4 using python -m pip install datatable 我正在尝试使用 Facebook API 获取有关广告的潜在客户信息,但我不断收到错误消息 - I'm trying to use the Facebook API to get lead information on an ad, but I keep getting an error message 尝试使用 len() 打印一条消息,指示我邀请的人数,但我收到错误消息 - Trying to use len() to print a message indicating the number of people i'm inviting, but im getting an error 我尝试编码的 Python 密码生成器不工作,但没有错误消息 - Python password generator I’m trying to code isn’t working, but there’s no error message 我正在尝试使用 Python 3 中的 while 循环来压缩我的代码 - I'm trying to condense my code with while loops in Python 3 我在尝试执行我的代码时收到此错误“语法错误:扫描字符串文字时 EOL” - I get this error "SyntaxError: EOL while scanning string literal" while trying to execute my code 嗨,我正在尝试连接来自不同类的两个节点,由于某种原因,它给了我这个错误 -&gt;neo4j.exceptions.CypherSyntaxError: {code: - Hi, I'm trying to connect two nodes from different classes and for some reason it's giving me this error ->neo4j.exceptions.CypherSyntaxError: {code: 我正在尝试在 for 循环中使用 int 但错误消息预期类型 &#39;collections.iterable&#39; got &#39;int&#39; 反而出现 - I'm trying to use int in a for loop but the error message expected type 'collections.iterable' got 'int' instead appears 我正在尝试编写代码,但出现此错误 - I'm trying to write a code but i got this error
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM