This is a GraphQL server written in Go that listens to the Ethereum transfer events for Bored Ape Yacht Club (BAYC).
These events are found at: https://etherscan.io/address/0xbc4ca0eda7647a8ab7c2061c2e118a18a936f13d
- Clone this repo
- Download postgres. On mac I use https://postgresapp.com/
- Go to https://infura.io/ and get set up with a project id
- Create the postgres db: in the terminal run
createdb transfers
- From the
/graphql
directory runpsql -d transfers -a -f schema.sql
- Run
./api -key={YOUR_INFURA_PROJECT_ID}
from the root of this directory - Go to
http://localhost:8080
to play in the GraphQL playground - Wait for some BAYC transactions to happen. Hopefully they weren't phished.
If you'd like to run the app yourself with Go, make sure to have go 1.17 installed. You can find downloads here: https://go.dev/dl/
In the playground you can find the queries and mutations used to:
- query for
transfers
bytransaction
,token_id
,sender
,receiver
- read
transfers
bytransaction
- create
transfers
Here are a few examples:
mutation {
createTransfer(
input: { transaction: "0xTransaction", sender: "0xSender", receiver: "0xReceiver", token_id: 101, read:false }
) {
transaction
sender
receiver
read
token_id
}
}
query {
unreadTransfers {
transaction
sender
receiver
read
}
}
mutation {
readTransfer(transaction: "0xTransaction") {
transaction
sender
receiver
read
token_id
}
}
- Infura for ethereum network information https://infura.io/
go-ethereum
https://github.com/ethereum/go-ethereumgqlgen
https://github.com/99designs/gqlgen- This blog post for a quick briefing on how to gen a lot of the GraphQL + Postgres code https://w11i.me/graphql-server-go-part1
- I looked into ent: https://entgo.io/ and it seems suitable for building large apps, but not suitable for this small project.
- The postgres setup could be done better with
docker-compose
- There are a lot of hard coded values that would live better as a kube secret or an environment variable.
- Tests: I want to add tests to this app. A lot of the testing so far is just sanity checks via
- GraphQL queries and mutations in the playground
- Log messages while the app is running
- If I were to make tests I would want:
- Unit tests for each of the methods that handle data conversions (eth hex -> transfer data)
- Service tests for GraphQL + Postgres
- BAYC kinda ugly tho