What is The Graph? π€
Imagine trying to find a specific piece of information in thousands of pages of documents. Pretty hard, right? That's similar to what it's like trying to get specific data from a blockchain. The Graph is like having a super-smart librarian who organizes all this information and helps you find exactly what you need, instantly!
In Simple Terms:
The Graph is like "Google for blockchain data"
It makes it easy to get information from blockchains
It organizes data in a way that's fast and efficient to access
Why Do We Need The Graph? π―
Let's say you want to:
Show all NFTs owned by a user
List all trades made by a specific wallet
Display historical price data
Without The Graph, you'd need to:
Scan through every block in the blockchain
Filter out the information you need
Process and organize this data
Store it somewhere for quick access
This would be:
The Graph solves all these problems by doing this work for you!
What is a Graph Node? π₯οΈ
A Graph Node is like your personal data processing center. It:
Listens to new blockchain events
Processes and organizes this data
Stores it in a way that's easy to query
Serves this data to your applications
Why Run Your Own Node? π€
Control: You're not dependent on third-party services
Speed: Faster access to data as it's on your infrastructure
Cost: Can be cheaper for high-volume applications
Privacy: Your queries stay on your infrastructure
Customization: You can optimize for your specific needs
Setting Up Your Own Node (Sepolia Network) π οΈ
Step 1: Prerequisites Checklist
[ ] Docker installed
[ ] Git installed
[ ] Basic command line knowledge
[ ] Sepolia RPC URL (from Infura or Alchemy)
[ ] 4GB RAM minimum recommended
[ ] 20GB storage space
Step 2: Environment Setup
- Create your project folder:
mkdir my-graph-node
cd my-graph-node
- Create a
.env file:
# Your Sepolia RPC endpoints (always good to have backup RPCs)
ETHEREUM_RPC1=https:
ETHEREUM_RPC2=https:
# Database settings
POSTGRES_USER=graph-node
POSTGRES_PASSWORD=choose-a-strong-password
POSTGRES_DB=graph-node
# Ports
GRAPH_NODE_HTTP_PORT=8000
GRAPH_NODE_ADMIN_PORT=8020
GRAPH_NODE_INDEX_PORT=8030
GRAPH_NODE_METRICS_PORT=8040
IPFS_API_PORT=5001
Step 3: Setting Up Docker
Create docker-compose.yml:
version: '3'
services:
graph-node:
image: graphprotocol/graph-node:v0.35.1
platform: linux/amd64
ports:
- '${GRAPH_NODE_HTTP_PORT:-8000}:8000'
- '${GRAPH_NODE_ADMIN_PORT:-8020}:8020'
- '${GRAPH_NODE_INDEX_PORT:-8030}:8030'
- '${GRAPH_NODE_METRICS_PORT:-8040}:8040'
depends_on:
- ipfs
- postgres
extra_hosts:
- host.docker.internal:host-gateway
environment:
postgres_host: postgres
postgres_user: ${POSTGRES_USER:-postgres}
postgres_pass: ${POSTGRES_PASSWORD:-postgres}
postgres_db: ${POSTGRES_DB:-graph-node}
ipfs: 'ipfs:5001'
ethereum: 'sepolia:${ETHEREUM_RPC1}'
GRAPH_LOG: info
GRAPH_ALLOW_NON_DETERMINISTIC_IPFS: 'true'
ETHEREUM_REORG_THRESHOLD: 50
ETHEREUM_ANCESTOR_COUNT: 500
ETHEREUM_POLLING_INTERVAL: 1000
GRAPH_ETHEREUM_REQUEST_RETRIES: 10
GRAPH_ETHEREUM_MAX_PARALLEL_BLOCKS: 10
GRAPH_ETHEREUM_BLOCK_BATCH_SIZE: 10
GRAPH_ETHEREUM_MAX_BLOCK_RANGE_SIZE: 1000
GRAPH_ETHEREUM_TARGET_TRIGGERS_PER_BLOCK_RANGE: 100
ipfs:
image: ipfs/kubo:v0.25.0
platform: linux/amd64
ports:
- '${IPFS_API_PORT:-5001}:5001'
volumes:
- ./data/ipfs:/data/ipfs
postgres:
image: postgres:16
platform: linux/amd64
ports:
- '${POSTGRES_PORT:-5432}:5432'
command:
[
"postgres",
"-cshared_preload_libraries=pg_stat_statements"
]
environment:
POSTGRES_USER: ${POSTGRES_USER:-postgres}
POSTGRES_PASSWORD: ${POSTGRES_PASSWORD:-postgres}
POSTGRES_DB: ${POSTGRES_DB:-graph-node}
POSTGRES_INITDB_ARGS: "-E UTF8 --locale=C"
volumes:
- ./data/postgres:/var/lib/postgresql/data
Step 4: Starting Your Node π
- Create data directories:
mkdir -p data/ipfs data/postgres
- Start the services:
docker-compose up -d
- Check if everything is running:
docker-compose ps
Step 5: Verifying Your Setup β
- Check if the Graph Node is responding:
curl http://localhost:8000/graphql
- Watch the logs:
docker-compose logs -f graph-node
You should see your node syncing with Sepolia blockchain!
Common Issues and Solutions π§
1. RPC Connection Issues
Problem: "Unable to connect to ethereum node"
Solution:
- Check if your RPC URL is correct
- Ensure you have credits/allowance on your RPC provider
- Try using a backup RPC
2. Memory Issues
Problem: "Out of memory" or container stops
Solution:
- Increase Docker memory limit
- Ensure your machine has enough free RAM
- Consider reducing block range size in config
3. IPFS Issues
Problem: "Unable to connect to IPFS"
Solution:
- Reset IPFS data: rm -rf data/ipfs
Next Steps π―
After your node is running:
Create your first subgraph
Deploy it to your node
Start querying data!
Monitoring Tips π
Keep an eye on:
Node logs: docker-compose logs -f graph-node
System resources (CPU, RAM, Disk)
Sync status through the admin port
PostgreSQL database size
Best Practices π
Always use multiple RPC endpoints for redundancy
Backup your PostgreSQL data regularly
Monitor your node's performance
Keep your node updated with the latest versions
Use proper security measures if exposing to the internet
Remember: Running a Graph Node is like maintaining a small data center. Take care of it, and it'll serve your data needs reliably! π
Need Help? π
Visit the Graph Protocol Discord
Check GitHub issues
Read the official documentation
Join The Graph community forums
Happy indexing! π