1

I'm trying to make a multicall using go. The function "aggregate" takes a tuple of "calls" with address and bytes.

        "name": "aggregate",
        "inputs": [
            {
                "type": "tuple[]",
                "name": "calls",
                "components": [
                    {
                        "type": "address",
                        "name": "target"
                    },
                    {
                        "type": "bytes",
                        "name": "callData"
                    }
                ]
            }
        ]

In Go, I first defined a type struct of "Call" with common.Address and []byte

type Call struct {
    target   common.Address
    callData []byte
}

When I put an array of "Call" in "multiCallAggregate.Inputs.Pack([]Call{data})", it always packs an empty []byte. Am I doing something wrong in the Call struct? Thank you!

ERC20BalanceOf := ERC20rAbi.Methods["balanceOf"]
    comptrolleId := ERC20BalanceOf.ID
    inputs, err := ERC20BalanceOf.Inputs.Pack(
        common.HexToAddress("0xd6801a1DfFCd0a410336Ef88DeF4320D6DF1883e"),
    )
    inputs = append(comptrolleId[:], inputs[:]...)

    ERC20Address := common.HexToAddress("0xab5801a7d398351b8be11c439e05c5b3259aec9b")

    data := Call{target: ERC20Address, callData: inputs}

    multiCallAggregate := multicallAbi.Methods["aggregate"]
    multicallInputs, err := multiCallAggregate.Inputs.Pack([]Call{data})
    fmt.Println(multicallInputs)

1 Answer 1

0

multicall input for golang is data [][]byte. no need to use any structs and all call's target is the same contract so you need to create []byte for every call and pack them together as input for multicall

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.