Links

Creating a Subgraph

💡 If you already have a subgraph and are looking to deploy it on Satsuma, see Subgraph Deploys.

Creating the subgraph

  1. 1.
    Install the graph-cli:
    npm install -g @graphprotocol/graph-cli
  2. 2.
    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

  1. 1.
    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
  2. 2.
    Write your GraphQL schema in schema.graphql.
  3. 3.
    Add new mappings, entities, and event handlers.
  4. 4.
    Add mappings to datasources in the subgraph.yml manifest that tell the indexer which handlers to call when triggers occur.
  5. 5.
    Write the corresponding handlers.
For more details, see these docs.