Is it possible to use the go-ethereum accounts/abi package to encode nested tuples? Say I have a Solidity struct

struct BlockHeader {
    bytes32 parentHash;

 struct SignalProof {
     BlockHeader header;
     bytes proof;
   function decodes(bytes input) {
      SignalProof memory mkp = abi.decode(input, (SignalProof));

Now, what I want to do is encode it from Golang, but am confused how to do so. From Typescript, I am basically looking for the equivilant of:

const thisWorks = ethers.defaultAbiCoder.Encode(["tuple(tuple(bytes32 parentHash), bytes proof)"],  {header:{parentHash: "0x123"}, proof: ethers.utils.randomBytes(32))`

await contract.decodes(thisWorks)

I have taken a stab but can't quite seem to get it.

blockHeaderType, _ := abi.NewType("tuple", "", []abi.ArgumentMarshaling{
        {Name: "parentHash", Type: "bytes32"},
signalProofType, _ := abi.NewType("tuple", "", []abi.ArgumentMarshaling{
        {Name: "header", Type: "tuple"},
        {Name: "proof", Type: "bytes"},
    signalProofArgs := abi.Arguments{
        {Type: signalProofType},
         type BlockHeader struct {
              ParentHash common.Hash
    type SignalProof struct {
        Header BlockHeader
        Proof []byte
         // etc, make a SignalProof with nested Blockheader, call signalProofArgs.Pack, pass it in to the .decodes, doesnt work

Is nested tuple possible?


Your Answer

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

Browse other questions tagged or ask your own question.