2 minutes
Migrate Your Subgraph From Alchemy to The Graph Network
Migrate Your Subgraph From Alchemy to The Graph Network
Goal
Migrate or deploy an existing Subgraph to The Graph.
Overview
This guide walks you through:
- Preparing your environment and source code
- Building and testing locally with Graph Node Dev Mode (
gnd) - Deploying to The Graph Studio.
1. Prerequisites
You’ll need:
- Your subgraph source code (
subgraph.yaml,schema.graphql,src/mapping.ts) - Node.js, Yarn, and
graph-cli:1npm install -g @graphprotocol/graph-cli - A The Graph Studio account and access token
2. Install and Authenticate with CLI
Install and authenticate the CLI:
1npm install -g @graphprotocol/graph-cli2graph auth --studio <YOUR_ACCESS_TOKEN>3. Prepare and Build Your Subgraph
If you don’t already have a project, initialize one from a contract:
1graph init --from-contract <CONTRACT_ADDRESS> <SUBGRAPH_NAME>Then build it:
1yarn codegen && yarn build4. Test Locally with Subgraph Dev Mode
gnd lets you run a local Graph Node instance for rapid testing—no IPFS or manual database setup required.
Install gnd
1graph node install2gnd --versionRun Locally
From your subgraph directory:
1gnd --ethereum-rpc mainnet:http://localhost:<PORT> --watchQuery your subgraph at:
http://localhost:8000/subgraphs/name/subgraph-0/
On Windows, include a PostgreSQL connection string:
1gnd --ethereum-rpc mainnet:http://localhost:<PORT> > --postgres-url "postgresql://graph:yourpassword@localhost:5432/graph-node"Common Flags | Flag | Description | |------|--------------| | --watch | Auto-redeploy when files change | | --postgres-url | Required on Windows | | --ethereum-rpc | RPC endpoint (required) |
5. Deploy to The Graph Network
After verifying locally, deploy your subgraph to Studio:
1graph deploy --studio <SUBGRAPH_SLUG>This command publishes your Subgraph to The Graph Network via Studio.
6. Monitor and Manage Your Deployment
Access your Subgraph dashboard to view logs, indexing progress, and query endpoints:
Dashboard:
https://thegraph.com/studio/<subgraph-name>
List all Subgraph deployments:
1graph subgraph list7. Update Your Application
Your subgraph’s GraphQL endpoint follows this format:
1https://api.studio.thegraph.com/query/{user_id}/{subgraph_slug}/{version}Example:
1https://api.studio.thegraph.com/query/1234/my-subgraph/v1.0.0Replace your old endpoint with this one in your dApp or backend configuration.
8. Verify Your Deployment
Run a quick test query:
1{2 transfers(first: 5) {3 id4 from5 to6 value7 }8}Ensure results match your expectations.
9. Next Steps
Learn more about Graph Node Dev Mode →
https://thegraph.com/docs/en/subgraphs/developing/creating/graph-node-dev/