Ethereum NFT Connector
Listen NFT events on Ethereum.
How to Build a Connector
Prerequisites
- Golang 1.20+
- Docker
- protoc
- protoc-gen-go
- abigen
- 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>