This section provides comprehensive guidance on setting up, deploying, and using a custom subgraph based on Goldsky. It is designed to simplify querying blockchain data for StoryHunt’s native AMM DEX.
Prerequisites
Before you begin, ensure your system has the following tools installed:
Node.js (>=16.x) and Yarn (>=1.22.x)
Git
The Graph CLI: Install globally with npm install -g @graphprotocol/graph-cli.
Installation Steps
1. Install Goldsky CLI and Log In
Install Goldsky CLI:
curlhttps://goldsky.com|sh
Log In via CLI:
Create an API Key in your Goldsky project’s Settings.
Log in using:
goldskylogin
Verify Installation: Run:
goldsky
This should display the available commands.
Set Up Your Subgraph
Clone Repository
Install Dependencies
Create subgraph.yaml
Create a subgraph.yaml file in the root directory with the following:
Customize the File
Replace placeholders like <START_BLOCK> and <FACTORY_CONTRACT_ADDRESS> with your actual contract details.
Define the Schema
In schema.graphql, define entities:
Implement Mappings
Mappings transform events into queryable data. Example for factory.ts:
Generate Code and Build
Deploy to Goldsky
Subgraph initialization complete!
Our subgraph has now been successfully deployed to Goldsky. The wizard provides a summary of the files written locally, the builds and deploys that were performed, and links to the subgraph dashboard and the GraphiQL web interface to query the subgraph data.
you can make use of the subgraph queries url to init the wrapper-sdk
By following these steps and examples, you can fully integrate subgraph with the Storyhunt V3 contracts while leveraging Goldsky for efficient querying.
type Pool @entity {
id: ID!
token0: Token!
token1: Token!
feeTier: BigInt!
}
type Token @entity {
id: ID!
symbol: String!
name: String!
decimals: BigInt!
}
...
# Refer to git repository for more info
import { PoolCreated } from "../../generated/Factory/Factory";
import { Pool, Token } from "../../generated/schema";
import { Pool as PoolTemplate } from "../../generated/templates";
export function handlePoolCreated(event: PoolCreated): void {
let token0 = new Token(event.params.token0.toHexString());
token0.symbol = fetchTokenSymbol(event.params.token0);
token0.save();
let token1 = new Token(event.params.token1.toHexString());
token1.symbol = fetchTokenSymbol(event.params.token1);
token1.save();
let pool = new Pool(event.params.pool.toHexString());
pool.token0 = token0.id;
pool.token1 = token1.id;
pool.feeTier = event.params.fee;
pool.save();
PoolTemplate.create(event.params.pool);
}