Skip to content

mcdayoub/go-bored-apes-graphql

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

20 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

go-bored-apes-graphql

Go / GraphQL / Bored Ape Yacht Club

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

Prereqs to running the app

Running the app

  • Create the postgres db: in the terminal run createdb transfers
  • From the /graphql directory run psql -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/

GraphQL Playground

In the playground you can find the queries and mutations used to:

  • query for transfers by transaction, token_id, sender, receiver
  • read transfers by transaction
  • 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
  }
}

Tools and References

Takeaways (If this were in prod I would instead do...)

  • 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

image

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages