Skip to content

Instantly share code, notes, and snippets.

@ilyapt
Forked from fxfactorial/example.go
Created June 16, 2023 22:51
Show Gist options
  • Save ilyapt/2f0fa10c64e607cd345c7eedebe3e3ca to your computer and use it in GitHub Desktop.
Save ilyapt/2f0fa10c64e607cd345c7eedebe3e3ca to your computer and use it in GitHub Desktop.

Revisions

  1. @fxfactorial fxfactorial created this gist Feb 14, 2022.
    39 changes: 39 additions & 0 deletions example.go
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,39 @@
    package main

    import (
    "fmt"
    "math/big"

    "github.com/ethereum/go-ethereum/accounts/abi"
    "github.com/ethereum/go-ethereum/common"
    "github.com/ethereum/go-ethereum/common/hexutil"
    )

    var (
    structThing, _ = abi.NewType("tuple", "struct thing", []abi.ArgumentMarshaling{
    {Name: "field_one", Type: "uint256"},
    {Name: "field_two", Type: "address"},
    })

    args = abi.Arguments{
    {Type: structThing, Name: "param_one"},
    }
    )

    func main() {
    record := struct {
    FieldOne *big.Int
    FieldTwo common.Address
    }{
    big.NewInt(2e18),
    common.HexToAddress("0x0002"),
    }

    packed, err := args.Pack(&record)
    if err != nil {
    fmt.Println("bad bad ", err)
    return
    } else {
    fmt.Println("abi encoded", hexutil.Encode(packed))
    }
    }