decoder

package module
v0.0.0-...-e9c1071 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 28, 2022 License: MIT Imports: 5 Imported by: 0

README

ABI-DECODER

decode ethereum transaction data of contract call. Inspired by abi-decoder

Example

var myContractAbi = `
[
   {
   	"constant": true,
   	"inputs": [],
   	"name": "name",
   	"outputs": [
   		{
   			"name": "",
   			"type": "string"
   		}
   	],
   	"payable": false,
   	"stateMutability": "view",
   	"type": "function"
   },
   {
   	"constant": false,
   	"inputs": [
   		{
   			"name": "_name",
   			"type": "string"
   		},
   		{
   			"name": "_age",
   			"type": "uint256"
   		},
   		{
   			"name": "_addr",
   			"type": "address"
   		}
   	],
   	"name": "save",
   	"outputs": [],
   	"payable": false,
   	"stateMutability": "nonpayable",
   	"type": "function"
   },
   {
   	"constant": true,
   	"inputs": [],
   	"name": "age",
   	"outputs": [
   		{
   			"name": "",
   			"type": "uint256"
   		}
   	],
   	"payable": false,
   	"stateMutability": "view",
   	"type": "function"
   },
   {
   	"constant": true,
   	"inputs": [],
   	"name": "addr",
   	"outputs": [
   		{
   			"name": "",
   			"type": "address"
   		}
   	],
   	"payable": false,
   	"stateMutability": "view",
   	"type": "function"
   }
]
   `

func main()  {
   txData := "0x19e7a9660000000000000000000000000000000000000000000000000000000000000060000000000000000000000000000000005a4728ca063b522c0b728f8000000000000000000000000000000000839c6f5a014cbfa319e8fdfa01aac186638945a80000000000000000000000000000000000000000000000000000000000000006e5b08fe6988e0000000000000000000000000000000000000000000000000000"
   txDataDecoder := decoder.NewABIDecoder()
   txDataDecoder.SetABI(myContractAbi)
   method, err := txDataDecoder.DecodeMethod(txData)
   if err != nil {
   	log.Fatal(err)
   }
   fmt.Println(method.Name)
   for _, param := range method.Params {
   	fmt.Println(param)
   }
}

Contribution

  • Fork this repository
  • Clone your repository
  • Install dependencies
  • Checkout a feature branch
  • Feel free to add your features
  • Make sure your features are fully tested
  • Open a pull request, and enjoy (:

LICENSE

Package abi-decoder is licensed under the MIT License.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ABIDecoder

type ABIDecoder struct {
	// contains filtered or unexported fields
}

ethereum transaction data decoder

func NewABIDecoder

func NewABIDecoder() *ABIDecoder

func (*ABIDecoder) ABI

func (d *ABIDecoder) ABI() abi.ABI

func (*ABIDecoder) DecodeMethod

func (d *ABIDecoder) DecodeMethod(txData string) (MethodData, error)

func (*ABIDecoder) SetABI

func (d *ABIDecoder) SetABI(contractAbi string)

type MethodData

type MethodData struct {
	Name   string
	Params []Param
}

type Param

type Param struct {
	Name  string
	Value string
	Type  string
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL