Getting Started

Getting started with SendBlocks subgraphs should be familiar to anyone who has worked with subgraphs before.

Step 1: Install the SendBlocks CLI

The first step in migrating your subgraph is to install the SendBlocks CLI. You can do this by running the following command:

npm install --global sendblocks-cli

Step 2: Create a New SendBlocks Project Based on an Existing Contract

Run the following command to create a new SendBlocks project:

sb-cli subgraph init <PROJECT_NAME> --contract <CONTRACT_ADDRESS> --chain_id <CHAIN_ID>

This will fetch the contract's ABI and create a new SendBlocks project with the schema and mappings for the contract.

If you want a clean slate, you can run sb-cli subgraph init without the --contract flag.

Step 3: Define Your Schema

Define the schema in the schema.graphql file (assuming it wasn't created automatically). This schema is identical to the schema file you would use in a traditional subgraph but does not require the @entity directive.

Example:

type Book {
    id: ID!
    title: String!
    author: Author!
}

type Author {
    id: ID!
    name: String!
    books: [Book!]! @derivedFrom(field: "author")
}

Step 4: Create Mappings

Create your mapping logic in a file called mappings.ts. The mapping logic will be written in JavaScript or TypeScript and will use runtime APIs to write data to your subgraph.

Step 5: Deploy Your Subgraph

Deploy your schema and mappings by running sb-cli subgraph deploy. Once deployed, your indexing will begin from the current block.

You can use the Replay Blocks feature to index historical data.