Deploy Subgraphs to Any EVM

Using Docker, The Graph, Graph-Node and OpenZepplin Subgraphs

Leon Do
Coinmonks
Published in
4 min readJan 29, 2022

--

Introduction

The Graph supports many networks such as Ethereum, xDAI, BSC etc. This article will explain how to build a subgraph with a custom network RPC.

Setup Local Node

Use Docker to run a local graph node and connect it to a blockchain via RPC.

Open docker-compose.yml located in:

Replace http://host.docker.internal:8545 with your RPC url. The default connects to a local ethereum node.

NOTE: Keep mainnet:

Go to graph-node/docker and run

The logs will show the current block head. You can compare it with what’s in the block explorer.

close enough

Your subgraph is running locally and is connected to the correct blockchain. Next, is creating a contract to index.

Deploy Contract to Index

This example will use OpenZepplin’s ERC-1155 contract. There is a public function to mint

Deploy and get a contract address

View the block explorer for contract address and block. The subgraph will index events from this contract address.

Setup Subgraph using OpenZepplin

This example will use OpenZepplin’s subgraph. This makes it easy to index contracts such as ERC-20, ERC-721 and ERC-1155.

https://docs.openzeppelin.com/subgraphs/0.1.x/

In config.json add and replace

  • address : The deployed contract address
  • startBlock : The deployed contract block

NOTE: Keep mainnet

Compile

This should generate a graphql and yaml file.

Create Subgraph

Deploy Subgraph

Once complete, visit http://localhost:8000/subgraphs/name/generated/sample

Test a query

Celebrate 🎉🎉🎉

This method can be deployed on any dedicated server.

Photo by Adam Whitlock on Unsplash

Join Coinmonks Telegram Channel and Youtube Channel learn about crypto trading and investing

Also, Read

--

--