0

Please tell me about the solid parameter byte []. After abigen compilation, the parameter in golang becomes [] [] byte. How should I construct this?

// Multicall0 is a paid mutator transaction binding the contract method 0x5ae401dc.
//
// Solidity: function multicall(uint256 deadline, bytes[] data) payable returns(bytes[])
func (_UniSwapV3Router *UniSwapV3RouterTransactor) Multicall0(opts *bind.TransactOpts, deadline *big.Int, data [][]byte) (*types.Transaction, error) {
    return _UniSwapV3Router.contract.Transact(opts, "multicall0", deadline, data)
}

https://etherscan.io/tx/0xafa45bc1badb33b4804249c1e5549ba9bc32f876d08a9a246806aa46f360faa3

This is the contract call of uniswap, and this is the call instance of manual transaction

1 Answer 1

2

Please tell me about the solid parameter byte []. After abigen compilation, the parameter in golang becomes [] [] byte. How should I construct this?

Almost, it's not byte[] but bytes[] :

// Solidity: function multicall(uint256 deadline, bytes[] data) payable returns(bytes[])
//                                                ^^^^^^^

Which is an alias for bytes1[] so data is actually bytes1[][] which in go effectively translates to [][]byte.

The multicall is just a way to make several calls through one single transaction. So you need to send an array of arrays of bytes. The first dimensions contain arrays of bytes and the second dimension is their respective contents (i.e., bytes representing the calldata with the function identifier and the parameters for each call).

4
  • Thank you very much for answering my question, I would like to ask. How should I convert path []common.address{} to []byte?
    – k z
    Commented Mar 18, 2022 at 15:15
  • I think it's better to convert everything at once using the Pack method from the abi, maybe this gist can help you ? gist.github.com/miguelmota/e2f90037eb4c4bd3f3d3711778ca5635 otherwise please provide your go code and contract.
    – hroussille
    Commented Mar 18, 2022 at 16:45
  • ok i will try it thank you very much
    – k z
    Commented Mar 18, 2022 at 17:08
  • I tried and failed, can't work, can you give me a demo? Thank you very much
    – k z
    Commented Mar 19, 2022 at 13:25

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.