Creating a Subgraph
💡 If you already have a subgraph and are looking to deploy it on Satsuma, see Subgraph Deploys.
Creating the subgraph
Install the
graph-cli
:npm install -g @graphprotocol/graph-cli
Create a new subgraph.
To create a subgraph from scratch:
graph init --product hosted-service
To create a subgraph that indexes all events of an existing contract:
graph init \ --product hosted-service --from-contract <CONTRACT_ADDRESS> \ [--network <ETHEREUM_NETWORK>] \ [--abi <FILE>] \ <subgraph name>
The ABI will be fetched from Etherscan. If it can't be found, the
--abi
file will need to be specified.
Modifying the subgraph
Add new datasources with the
graph add
command.graph add <address> [<subgraph-manifest default: "./subgraph.yaml">] Options: --abi <path> Path to the contract ABI (default: download from Etherscan) --contract-name Name of the contract (default: Contract) --merge-entities Whether to merge entities with the same name (default: false) --network-file <path> Networks config file path (default: "./networks.json") -h, --help Show usage information
Write your GraphQL schema in
schema.graphql
.Add new mappings, entities, and event handlers.
Add mappings to datasources in the
subgraph.yml
manifest that tell the indexer which handlers to call when triggers occur.Write the corresponding handlers.
For more details, see these docs.
Last updated