20 使用web3.py 调用马蹄链合约,出现卡死问题(tuple传参问题)

调用合约出现了电脑卡死的问题,感觉是tuple 传参出了问题,试了很多方式都不行 部分代码:

inputTokenAddress=Web3.toChecksumAddress('0x0000000000000000000000000000000000000000')

inputAmountIn=Web3.toInt(1000000000000000000)
inputReceiver=Web3.toChecksumAddress('0x8Fd175fda06AEB02d8e10D3b9DeAD8A122D4d9d8')
inputPermit=Web3.toBytes(text='0x')

inputs={'inputs':{'tokenAddress':inputTokenAddress,'amountIn':inputAmountIn,'receiver':inputReceiver,'permit':inputPermit}}

outputToAddress=Web3.toChecksumAddress('0x980111ae1B84E50222C8843e3A7a038F36Fecd2b')
outputRelativeValue=Web3.toInt(1)
outputReceiver=Web3.toChecksumAddress('0xF706c6212EebB7FB3A974A76978AA85D584f120B')

outputs={'outputs':{'tokenAddress':outputToAddress,'relativeValue':outputRelativeValue,'receiver':outputReceiver}}

valueOutQuote=Web3.toInt(83127426808074820000)

valueOutMin=Web3.toInt(82296152539994071800)

executor=Web3.toChecksumAddress('0x8Fd175fda06AEB02d8e10D3b9DeAD8A122D4d9d8')

pathDefinition=Web3.toBytes(text='0102030005010102030001010102011eff000000000000000000000000000000a996e14433e21a178893cd89e1c1f6f55563122d0d500b1d8e8ef31e21c99d1db9a6444d3adf1270')

print("------")

increment_tx = contract.functions.swap(inputs,outputs,valueOutQuote,valueOutMin,executor,pathDefinition).build_transaction(
        {

            "from": sender_addr,
            "value": 0,
            'gasPrice': Web3.toWei(str(200), 'gwei'),
            "gas": 300000,
            "nonce": w3.eth.getTransactionCount(sender_addr),

        }
        )

部分abi :

{
        "inputs":[
            {
                "components":[
                    {
                        "internalType":"address",
                        "name":"tokenAddress",
                        "type":"address"
                    },
                    {
                        "internalType":"uint256",
                        "name":"amountIn",
                        "type":"uint256"
                    },
                    {
                        "internalType":"address",
                        "name":"receiver",
                        "type":"address"
                    },
                    {
                        "internalType":"bytes",
                        "name":"permit",
                        "type":"bytes"
                    }
                ],
                "internalType":"struct OdosRouter.inputToken[]",
                "name":"inputs",
                "type":"tuple[]"
            },
            {
                "components":[
                    {
                        "internalType":"address",
                        "name":"tokenAddress",
                        "type":"address"
                    },
                    {
                        "internalType":"uint256",
                        "name":"relativeValue",
                        "type":"uint256"
                    },
                    {
                        "internalType":"address",
                        "name":"receiver",
                        "type":"address"
                    }
                ],
                "internalType":"struct OdosRouter.outputToken[]",
                "name":"outputs",
                "type":"tuple[]"
            },
            {
                "internalType":"uint256",
                "name":"valueOutQuote",
                "type":"uint256"
            },
            {
                "internalType":"uint256",
                "name":"valueOutMin",
                "type":"uint256"
            },
            {
                "internalType":"address",
                "name":"executor",
                "type":"address"
            },
            {
                "internalType":"bytes",
                "name":"pathDefinition",
                "type":"bytes"
            }
        ]
请先 登录 后评论

最佳答案 2022-10-29 16:02

inputs={'inputs':{'tokenAddress':inputTokenAddress,'amountIn':inputAmountIn,'receiver':inputReceiver,'permit':inputPermit}}

这个类型不对,应该是数组里面存对象

请先 登录 后评论

其它 2 个回答

Tiny熊
  擅长:智能合约,以太坊
请先 登录 后评论
oxo
请先 登录 后评论
  • 3 关注
  • 1 收藏,2056 浏览
  • oxo 提出于 2022-10-16 19:19