Skip to content

0xhyim/fourbyte

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

fourbyte Go Report Card GoDoc

4byte.directory API Client for Go.

Check out the endpoints or usage section for more information.

Documentation

https://pkg.go.dev/github.com/0xhyim/fourbyte

Install

go get -u github.com/0xhyim/fourbyte

Endpoints

Endpoint Function
/api/v1/signatures GetFunctionSignatures, GetFunctionSignatureById, CreateFunctionSignature
/api/v1/event-signatures GetEventSignatures, GetEventSignatureById, CreateEventSignature
/api/v1/import-solidity ImportFromSourceCode, ImportFromABI

Refer to 4byte.directory Official API Documentation for more information.

Usage

The fourbyte package provides access to all the endpoints listed above.

Basic Function Signature Lookup

package main

import (
	"context"
	"fmt"
	"log"

	"github.com/0xhyim/fourbyte"
)

func main() {
	response, err := fourbyte.GetFunctionSignatures(context.Background(), fourbyte.WithHexSignature("0x1249c58b"))
	if err != nil {
		log.Fatal(err)
	}
	// "mint()"
	fmt.Println(response.Signatures[0].TextSignature)
}

Signature Lookup (following Next)

package main

import (
	"context"
	"fmt"
	"log"

	"github.com/0xhyim/fourbyte"
)

func main() {
	signatures := []fourbyte.Signature{}
	response, err := fourbyte.GetFunctionSignatures(context.Background(), fourbyte.WithTextSignature("WETH"))
	if err != nil {
		log.Fatal(err)
	}
	signatures = append(signatures, response.Signatures...)
	for response.Next != nil {
		response, err = response.Next.Follow(context.Background())
		if err != nil {
			log.Fatal(err)
		}
		signatures = append(signatures, response.Signatures...)
	}
	fmt.Println(signatures)
}

TODOS

  • Add tests to project
  • Add documentation/comments to code

License

MIT License