Web3.py Web3.exceptions.ContractLogicError:在getAmountOutMin和swap函数上恢复执行

2024-10-08 18:29:11 发布

您现在位置:Python中文网/ 问答频道 /正文

本质上,我试图为web3.py使用一个令牌交换函数,调用该函数时,它给了我一个ContractLogic错误:执行被还原,这发生在getAmountOutMin和交换函数上。我已经仔细阅读了文档和其他帖子,我不确定为什么这段代码会复制这个错误。如果有人能找到解决办法,我将不胜感激

以下是使用的代码:

uniswap_factory_abi = json.loads('''[
        {
            "inputs": [
                {
                    "internalType": "address",
                    "name": "_tokenIn",
                    "type": "address"
                },
                {
                    "internalType": "address",
                    "name": "_tokenOut",
                    "type": "address"
                },
                {
                    "internalType": "uint256",
                    "name": "_amountIn",
                    "type": "uint256"
                },
                {
                    "internalType": "uint256",
                    "name": "_amountOutMin",
                    "type": "uint256"
                },
                {
                    "internalType": "address",
                    "name": "_to",
                    "type": "address"
                }
            ],
            "name": "swap",
            "stateMutability": "nonpayable",
            "type": "function"
        },
                {
                "inputs": [
                    {
                        "internalType": "address",
                        "name": "_tokenIn",
                        "type": "address"
                    },
                    {
                        "internalType": "address",
                        "name": "_tokenOut",
                        "type": "address"
                    },
                    {
                        "internalType": "uint256",
                        "name": "_amountIn",
                        "type": "uint256"
                    }
                ],
                "name": "getAmountOutMin",
                "outputs": [
                    {
                        "internalType": "uint256",
                        "name": "",
                        "type": "uint256"
                    }
                ],
                "stateMutability": "nonpayable",
                "type": "function"
            }]''')

actual_min = float(min)
amountout = contract.functions.getAmountOutMin("0xd0A1E359811322d97991E03f863a0C30C2cF029C", "0xF6fF8efc1e11A17E410F248475ffE870E8FC6ebD", int(actual_min * 1e18))


txn = {
    'from': account,
    'gas': 650000,
    'gasPrice': web3.eth.gasPrice,
    'nonce': web3.eth.getTransactionCount(account)
}


amountoutmin = amountout.call(txn)

token_swap = contract.functions.swap("0xd0A1E359811322d97991E03f863a0C30C2cF029C", "0xF6fF8efc1e11A17E410F248475ffE870E8FC6ebD", int(actual_min * 1e18), amountoutmin, account)

token_swap.call(txn)

编辑:

在使用solcx编译solidity代码之后,它解决了我的问题

编辑2:

显然,使用solcx编译solidity代码并没有解决这个问题,但是我现在发现我一直在使用的solidity代码出现了错误,这就是我的问题的根源


Tags: 函数代码nameaddresstype错误accountmin
1条回答
网友
1楼 · 发布于 2024-10-08 18:29:11

我会先检查您的契约是否成功部署,然后看看您使用的函数是否也能正常工作。不确定您使用了什么来部署它,但是在Remix中,您可以使用web界面来测试您的功能,并且还有一个很好的dubug特性。在那里输入值,检查输出,如果有效,则转到代码部分。我猜您的txn可能缺少一些参数,如chainId、value等。您是否也对事务进行签名

相关问题 更多 >

    热门问题