本质上,我正在尝试对 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代码有问题,这是我问题的根源