Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refresh subsquid indexer tutorial #1064

Merged
merged 1 commit into from
Jan 14, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<div id="termynal" data-termynal>
<span data-ty="input"><span class="file-path"></span>npx hardhat compile</span>
<span data-ty>Compiled 6 Solidity files successfully (evm target: paris) </span>
<span data-ty="input"><span class="file-path"></span></span>
</div>
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<div id="termynal" data-termynal>
<span data-ty="input"><span class="file-path"></span>npx hardhat run scripts/deploy.js --network dev</span>
<span data-ty>Contract deployed to 0xc01Ee7f10EA4aF4673cFff62710E1D7792aBa8f3</span>
<span data-ty="input"><span class="file-path"></span></span>
</div>
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<div id="termynal" data-termynal>
<span data-ty>query: CREATE TABLE "migrations" ("id" SERIAL NOT NULL, "timestamp" bigint NOT NULL, "name" character varying NOT NULL, CONSTRAINT "PK_8c82d7f526340ab734260ea46be" PRIMARY KEY ("id"))</span>
<span data-ty>query: SELECT * FROM "migrations" "migrations" ORDER BY "id" DESC</span>
<span data-ty>0 migrations are already loaded in the database.</span>
<span data-ty>1 migrations were found in the source code.</span>
<span data-ty>1 migrations are new migrations must be executed.</span>
<span data-ty>query: START TRANSACTION</span>
<span data-ty>query: CREATE TABLE "transfer" ("id" character varying NOT NULL, "block_number" integer NOT NULL, "timestamp" TIMESTAMP WITH TIME ZONE NOT NULL, "tx_hash" text NOT NULL, "amount" numeric NOT NULL, "from_id" character varying, "to_id" character varying, CONSTRAINT "PK_fd9ddbdd49a17afcbe014401295" PRIMARY KEY ("id"))</span>
<span data-ty>query: CREATE INDEX "ID_76bdfed1a7eb27c6d8ecbb7349" ON "transfer" ("from_id")</span>
<span data-ty>query: CREATE INDEX "IDX_0751309c6697eac9ef1149362" ON "transfer" ("to_id")</span>
<span data-ty>query: CREATE TABLE "account" ("id" character varying NOT NULL, CONSTRAINT "PK_54115ee388cdb6d86bb4bf5bZea" PRIMARY KEY ("id"))</span>
<span data-ty>query: ALTER TABLE "transfer" ADD CONSTRAINT "FK_76bdfed1a7eb27c6d8ecbb73496" FOREIGN KEY ("from_id") REFERENCES "account"("id") ON DELETE NO ACTION ON UPDATE NO ACTION</span>
<span data-ty>query: ALTER TABLE "transfer" ADD CONSTRAINT "FK_0751309c66e97eac9ef11493623" FOREIGN KEY ("to_id") REFERENCES "account"("id") ON DELETE NO ACTION ON UPDATE NO ACTION</span>
<span data-ty>query: INSERT INTO "migrations" ("timestamp", "name") VALUES ($1, $2) -- PARAMETERS: [1700202953250, "Data1700202953250"]</span>
<span data-ty>Migration Data1700202953250 has been executed</span>
<span data-ty>query: COMMIT </span>
<span data-ty="input"><span class="file-path"></span></span>
</div>
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<div id="termynal" data-termynal>
<span data-ty="input"><span class="file-path"></span>docker run --rm --name moonbeam_development -p 9944:9944 \</span>
<span data-ty>moonbeamfoundation/moonbeam:v0.42.1 \</span>
<span data-ty>--dev --rpc-external</span>
<span data-ty>WARNING: The requested image's platform (linux/amd64) does not match the detected host platform (linux/arm64/v8) and no specific platform was requested</span>
<span data-ty>2025-01-07 18:28:51 Moonbeam Parachain Collator</span>
<span data-ty>2025-01-07 18:28:51 ✌️ version 0.42.1-1432b45b797</span>
<span data-ty>2025-01-07 18:28:51 ❤️ by PureStake, 2019-2025</span>
<span data-ty>2025-01-07 18:28:51 📋 Chain specification: Moonbase Development Testnet</span>
<span data-ty>2025-01-07 18:28:51 🏷 Node name: truthful-volcano-8206</span>
<span data-ty>2025-01-07 18:28:51 👤 Role: AUTHORITY</span>
<span data-ty>2025-01-07 18:28:51 💾 Database: RocksDb at /tmp/substrate5PF2uR/chains/moonbase_dev/db/full</span>
<span data-ty>2025-01-07 18:28:54 🔨 Initializing Genesis block/state (state: 0x554b…9ef4, header-hash: 0xbe59…cd6e)</span>
<span data-ty>2025-01-07 18:28:54 Using default protocol ID "sup" because none is configured in the chain specs</span>
<span data-ty>2025-01-07 18:28:54 🏷 Local node identity is: 12D3KooWJf8ba9DW6XH6Q7RZZK6qKHyYXAxE7eMSEgLqUDGaNP3n</span>
<span data-ty>2025-01-07 18:28:54 Running libp2p network backend</span>
<span data-ty>2025-01-07 18:28:55 💻 Operating system: linux</span>
<span data-ty>2025-01-07 18:28:55 💻 CPU architecture: x86_64</span>
<span data-ty>2025-01-07 18:28:55 💻 Target environment: gnu</span>
<span data-ty>2025-01-07 18:28:55 💻 Memory: 12200MB</span>
<span data-ty>2025-01-07 18:28:55 💻 Kernel: 6.10.14-linuxkit</span>
<span data-ty>2025-01-07 18:28:55 💻 Linux distribution: Debian GNU/Linux 12 (bookworm)</span>
<span data-ty>2025-01-07 18:28:55 💻 Virtual machine: no</span>
<span data-ty>2025-01-07 18:28:55 📦 Highest known block at #0</span>
<span data-ty>2025-01-07 18:28:55 〽️ Prometheus exporter started at 127.0.0.1:9615</span>
<span data-ty>2025-01-07 18:28:55 Running JSON-RPC server: addr=0.0.0.0:9944, allowed origins=["*"]</span>
<span data-ty>2025-01-07 18:28:55 🏁 CPU score: 708.84 MiBs</span>
<span data-ty>2025-01-07 18:28:55 🏁 Memory score: 25.72 GiBs</span>
<span data-ty>2025-01-07 18:28:55 🏁 Disk score (seq. writes): 2.24 GiBs</span>
<span data-ty>2025-01-07 18:28:55 🏁 Disk score (rand. writes): 717.22 MiBs</span>
<span data-ty>2025-01-07 18:28:55 Development Service Ready</span>
<span data-ty>2025-01-07 18:29:00 💤 Idle (0 peers), best: #0 (0xbe59…cd6e), finalized #0 (0xbe59…cd6e), ⬇ 0 ⬆ 0</span>
<span data-ty="input"><span class="file-path"></span></span>
</div>
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<div id="termynal" data-termynal>
<span data-ty="input"><span class="file-path"></span>npx hardhat run scripts/transactions.js --network dev</span>
<span data-ty>Transfer to Baltathar with TxHash 0x188eca1c42c6fa63588f998a453e2ce40d7d2166fdaa36b1838226dd06c8e3c2</span>
<span data-ty>Transfer to Charleth with TxHash 0xc38dfa6addffbdb21d66e009a7c96f17c6dffd9f278fcefb62abb839a14f48be</span>
<span data-ty>Transfer to Dorothy with TxHash Oxe413ee2dea27ac8d1ec281caff3f5235b098c28e38b7cdcae88455c571d2d3b0</span>
<span data-ty>Transfer to Ethan with TxHash 0x21cb2a2b8e714a23c12eac41b75a369da06afe8d3bcfa56acf3d68649a4874a1</span>
<span data-ty="input"><span class="file-path"></span></span>
</div>
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<div id="termynal" data-termynal>
<span data-ty="input"><span class="file-path"></span>sqd typegen</span>
<span data-ty>TYPEGEN</span>
<span data-ty>22:30:43 INFO sqd:evm-typegen saved src/abi/abi.support.ts</span>
<span data-ty>22:30:43 INFO sqd:evm-typegen saved src/abi/multicall.ts</span>
<span data-ty>22:30:43 INFO sqd:evm-typegen processing./abi/erc20.json</span>
<span data-ty>22:30:43 INFO sqd:evm-typegen saved src/abi/erc20.abi.ts</span>
<span data-ty>22:30:43 INFO sqd:evm-typegen saved src/abi/erc20.ts</span>
<span data-ty="input"><span class="file-path"></span></span>
</div>
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
16 changes: 7 additions & 9 deletions tutorials/integrations/local-subsquid.md
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ To spin up a development node, which will pull the latest Docker image for Moonb

This will start up our development node, which can be accessed on port 9944. Note that you do not have to use Docker; you can also [run a local node by compiling the Moonbeam binary](/builders/get-started/networks/moonbeam-dev/#getting-started-with-the-binary-file){target=\_blank}.

![Spin up a Moonbeam development node](/images/tutorials/integrations/local-subsquid/new/local-squid-1.webp)
--8<-- 'code/tutorials/integrations/local-subsquid/terminal/start-node.md'

Our development node comes with 10 prefunded accounts.

Expand Down Expand Up @@ -140,7 +140,7 @@ To compile the contract, you can run:
npx hardhat compile
```

![Compile contracts using Hardhat](/images/tutorials/integrations/local-subsquid/new/local-squid-2.webp)
--8<-- 'code/tutorials/integrations/local-subsquid/terminal/compile.md'

This command will compile our contract and generate an `artifacts` directory containing the ABI of the contract. To deploy our contract, we'll need to create a deployment script that deploys our ERC-20 contract and mints an initial supply of MYTOKs. We'll use Alith's account to deploy the contract, and we'll specify the initial supply to be 1000 MYTOK. The initial supply will be minted and sent to the contract owner, which is Alith.

Expand Down Expand Up @@ -168,7 +168,7 @@ Let's take the following steps to deploy our contract:

The address of the deployed contract should be printed to the terminal. Save the address, as we'll need it to interact with the contract in the following section.

![Deploy contracts using Hardhat](/images/tutorials/integrations/local-subsquid/new/local-squid-3.webp)
--8<-- 'code/tutorials/integrations/local-subsquid/terminal/deploy.md'

### Transfer ERC-20s {: #transfer-erc-20s }

Expand Down Expand Up @@ -196,7 +196,7 @@ Since we'll be indexing `Transfer` events for our ERC-20, we'll need to send a f

As each transaction is sent, you'll see a log printed to the terminal.

![Send transactions using Hardhat](/images/tutorials/integrations/local-subsquid/new/local-squid-4.webp)
--8<-- 'code/tutorials/integrations/local-subsquid/terminal/transaction.md'

Now we can move on to creating our Squid to index the data on our local development node.

Expand Down Expand Up @@ -267,7 +267,7 @@ Next, we can use our contract's ABI to generate TypeScript interface classes. We
sqd typegen
```

![Run sqd typegen](/images/tutorials/integrations/local-subsquid/new/local-squid-5.webp)
--8<-- 'code/tutorials/integrations/local-subsquid/terminal/typegen.md'

This will generate the related TypeScript interface classes in the `src/abi/erc20.ts` file. For this tutorial, we'll be accessing the `events` specifically.

Expand Down Expand Up @@ -300,8 +300,6 @@ The `.toLowerCase()` is critical because the SQD processor is case-sensitive, an
})
```

![Run SQD commands](/images/tutorials/integrations/local-subsquid/new/local-squid-6.webp)

The Squid template comes with a variable for your RPC URL defined in your `.env` file. You can replace that with the RPC URL for your local development node. For demonstration purposes, the RPC URL for a local development node is hardcoded directly, as shown above. If you're setting the RPC URL in your `.env`, the respective line will look like this:

```text
Expand Down Expand Up @@ -410,7 +408,7 @@ To run our indexer, we're going to run a series of `sqd` commands, as follows:

In your terminal, you should see your indexer starting to process blocks!

![Run sqd process](/images/tutorials/integrations/local-subsquid/new/local-squid-6.webp)
--8<-- 'code/tutorials/integrations/local-subsquid/terminal/squid-commands.md'

If your Squid isn't indexing blocks properly, make sure that your development node is running with the `--sealing` flag. For this example, you should have set the flag as `--sealing 4000`, so that a block is produced every four seconds. You can feel free to edit the sealing interval as needed. Before you try to spin up your Squid again, run the following commands to restart your Squid:

Expand Down Expand Up @@ -450,7 +448,7 @@ And that's it! You can now run queries against your Squid on the GraphQL playgro
--8<-- 'code/tutorials/integrations/local-subsquid/sample-query.graphql'
```

![Running queries in GraphQL playground](/images/tutorials/integrations/local-subsquid/new/local-squid-7.webp)
![Running queries in GraphQL playground](/images/tutorials/integrations/local-subsquid/new/local-squid-1.webp)

All of the transfers will be returned, including the transfer of the initial supply to Alith's account and the transfers from Alith to Baltathar, Charleth, Dorothy, and Ethan.

Expand Down