ethnft

package module
v0.0.0-...-9478d72 Latest Latest
Warning

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

Go to latest
Published: Apr 5, 2024 License: MIT Imports: 17 Imported by: 0

README

Ethereum NFT Connector

Listen NFT events on Ethereum.

How to Build a Connector

Prerequisites

  1. Golang 1.20+
  2. Docker
  3. protoc
  4. protoc-gen-go
  5. abigen
  6. solc

Overview

Listen ERC721 and ERC1155 events on Ethereum.

Code of a Connector
1. Getting the ABI files for a smart contract

For now we just support only one ABI smart contract

3. Creating the contract handling files

First, enter the <contract_name>/ directory. Create the <contract_name>.abi file in <contract_name>/ and paste the ABI source code you copied earlier.

Next, generate the <contract_name>.abi.go file using abigen (you should have abigen installed from the above step) .

Need to add abigen and protogen installation guide links here

abigen --abi <contract_name>.abi --pkg <contract_name> --out <contract_name>.abi.go

Next, generate the <contract_name>.pb.go file using protoc(you should have protoc installed from the above step) .

protoc --go_out=. --go_opt=paths=source_relative ./<contract_name>.proto
go mod init

go mod tidy

This automatically creates the go.mod and go.sum files that tell go to fetch which modules and dependencies your program depends on.

Next, spin up kafka by running:

docker compose up -d

You can update rpc in file local.yaml and update manifest.yaml for kafka transaction id

Now start the connector locally by running the main.go file. (If you are running to “connection refused” error, make sure docker is running). ETH NFT connector support backfill event log with some flag

--from-block(uint64): Start backfill from specific block (For the first time run backfill. It should be the block when deploy smart contract)

--num-blocks(uint64): Number of blocks you want to backfill. If you want to crawl to the newest block you can skip this flag

Listening new event log

go run cmd/<connector_name>/main.go

Backfill mode You can use either or both flags

go run cmd/<connector_name>/main.go --from-block <blockNumber> --num-blocks <number>

Documentation

Index

Constants

View Source
const (
	EventApproval = "Approval"
	EventTransfer = "Transfer"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Config

type Config struct {
	BlockchainName string
	FromBlock      uint64
	NumBlocks      uint64
}

type Connector

type Connector struct {
	*ethereum.Connector
	*Config
	// contains filtered or unexported fields
}

func New

func New(conf *Config) *Connector

func (*Connector) Start

func (c *Connector) Start()

type Contract

type Contract struct {
	ABI           *abi.ABI
	Name          string
	MessageParser ISmartContract
}

func GetContracts

func GetContracts() []*Contract

type ISmartContract

type ISmartContract interface {
	Message(eventName string, contractAbi *abi.ABI, vLog types.Log, timestamp *timestamppb.Timestamp) protoreflect.ProtoMessage
}

Directories

Path Synopsis
cmd
smart-contracts

Jump to

Keyboard shortcuts

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