Token Approval Subgraph Deployment Recipe
This recipe involves deploying a subgraph that tracks the approval lists of all Erc20, Erc721, and Erc1155 tokens.
Note: Before proceeding, ensure that you have Node.js installed on your system.
1. Install the latest version of Node.js
Open a terminal or command prompt.
Install the latest version of Node.js by visiting the official Node.js website (https://nodejs.org ) and following the installation instructions specific to your operating system.
2. Install the official Graph CLI
Copy npm i @graphprotocol/graph-cli
3. Clone the token approval subgraph repository
Run
Copy git clone https://github.com/ormi-labs/mantle-approvals-subgraph.git
to clone the Mantle token approval subgraph repository to your local machine.
4. Install dependencies
Navigate to the cloned directory: cd mantle-approvals-subgraph
.
Execute npm install
to install the required dependencies for the subgraph.
5. Generate subgraph types
Run the command to generate subgraph types:
which will generate the following output:
Copy Skip migration: Bump mapping apiVersion from 0.0.1 to 0.0.2
Skip migration: Bump mapping apiVersion from 0.0.2 to 0.0.3
Skip migration: Bump mapping apiVersion from 0.0.3 to 0.0.4
Skip migration: Bump mapping apiVersion from 0.0.4 to 0.0.5
Skip migration: Bump mapping apiVersion from 0.0.5 to 0.0.6
Skip migration: Bump manifest specVersion from 0.0.1 to 0.0.2
Skip migration: Bump manifest specVersion from 0.0.2 to 0.0.4
✔ Apply migrations
✔ Load subgraph from subgraph.yaml
Load contract ABI from abis/ERC20.json
Load contract ABI from abis/ERC721.json
✔ Load contract ABIs
Generate types for contract ABI: ERC20 (abis/ERC20.json)
Write types to generated/ERC20Approve/ERC20.ts
Generate types for contract ABI: ERC721 (abis/ERC721.json)
Write types to generated/ERC721Approve/ERC721.ts
✔ Generate types for contract ABIs
✔ Generate types for data source templates
✔ Load data source template ABIs
✔ Generate types for data source template ABIs
✔ Load GraphQL schema from schema.graphql
Write types to generated/schema.ts
✔ Generate types for GraphQL schema
Types generated successfully
6. Build the subgraph
Execute the following command to build the subgraph:
which will generate the following output:
Copy Skip migration: Bump mapping apiVersion from 0.0.1 to 0.0.2
Skip migration: Bump mapping apiVersion from 0.0.2 to 0.0.3
Skip migration: Bump mapping apiVersion from 0.0.3 to 0.0.4
Skip migration: Bump mapping apiVersion from 0.0.4 to 0.0.5
Skip migration: Bump mapping apiVersion from 0.0.5 to 0.0.6
Skip migration: Bump manifest specVersion from 0.0.1 to 0.0.2
Skip migration: Bump manifest specVersion from 0.0.2 to 0.0.4
✔ Apply migrations
✔ Load subgraph from subgraph.yaml
Compile data source: ERC20Approve = > build/ERC20Approve/ERC20Approve.wasm
Compile data source: ERC721Approve = > build/ERC721Approve/ERC721Approve.wasm
✔ Compile subgraph
Copy schema file build/schema.graphql
Write subgraph file build/ERC20Approve/abis/ERC20.json
Write subgraph file build/ERC721Approve/abis/ERC721.json
Write subgraph manifest build/subgraph.yaml
✔ Write compiled subgraph to build/
Build completed: build/subgraph.yaml
7. Authentication with API Key
Sign up for a Mantle API deployment key by visiting https://subgraph.mantle.xyz/dashboard/api
Run the following command and enter the Mantle API deployment key when prompted:
Copy graph auth https://subgraph-api.mantle.xyz/deploy
Enter your Mantle deploy key when prompted
Copy What is the deploy key?: *************************
Deploy key set for http://subgraph-api.mantle.xyz/deploy/
8. Create and deploy the subgraph
Run the following command to create a subgraph with the specified name:
Copy graph create test_org/token-approval --node https://subgraph-api.mantle.xyz/deploy
With the following result:
Copy Created subgraph: test_org/token-approval
Next, execute the following command to deploy your Mantle token approval subgraph
Copy graph deploy test_org/token-approval --node https://subgraph-api.mantle.xyz/deploy --ipfs https://subgraph-api.mantle.xyz/ipfs
The result will be the following:
Copy Which version label to use? (e.g. "v0.0.1"): v0.0.2
Skip migration: Bump mapping apiVersion from 0.0.1 to 0.0.2
Skip migration: Bump mapping apiVersion from 0.0.2 to 0.0.3
Skip migration: Bump mapping apiVersion from 0.0.3 to 0.0.4
Skip migration: Bump mapping apiVersion from 0.0.4 to 0.0.5
Skip migration: Bump mapping apiVersion from 0.0.5 to 0.0.6
Skip migration: Bump manifest specVersion from 0.0.1 to 0.0.2
Skip migration: Bump manifest specVersion from 0.0.2 to 0.0.4
✔ Apply migrations
✔ Load subgraph from subgraph.yaml
Compile data source: ERC20Approve => build/ERC20Approve/ERC20Approve.wasm
Compile data source: ERC721Approve => build/ERC721Approve/ERC721Approve.wasm
✔ Compile subgraph
Copy schema file build/schema.graphql
Write subgraph file build/ERC20Approve/abis/ERC20.json
Write subgraph file build/ERC721Approve/abis/ERC721.json
Write subgraph manifest build/subgraph.yaml
✔ Write compiled subgraph to build/
Add file to IPFS build/schema.graphql
.. QmTULX5hVKutEPZMUEzewK46ym6tPAMUbziW2XW8LfLcML
Add file to IPFS build/ERC20Approve/abis/ERC20.json
.. QmNMmyQp7UQtgLxFZZmNuQQ2BWv7eum2KcTMYU5BP7zMhG
Add file to IPFS build/ERC721Approve/abis/ERC721.json
.. QmXVNNtLfETmLrarDMwR18Tk2kNUXyczLf7LdES4aFZkLi
Add file to IPFS build/ERC20Approve/ERC20Approve.wasm
.. QmPHX32f5XKyez15mT3V3VWGhw6iwRL9SdawoCz76pQcNe
Add file to IPFS build/ERC721Approve/ERC721Approve.wasm
.. Qmc2sY6DNfmFqEZdkXTsKssL75kDC7U1TGLEzN4cHY1Kog
✔ Upload subgraph to IPFS
Build completed: QmYKHNDoDn8Xzkv19dUxPcDrUw2gaVRukZhbxskwupZBQP
Deployed to https://subgraph-api.mantle.xyz:8000/subgraphs/name/test_org/token-approval/graphql
Subgraph endpoints:
Queries (HTTP): https://subgraph-api.mantle.xyz:8000/subgraphs/name/test_org/token-approval
If the deployment is successful, you will receive a completion message with the deployment ID. And you may query the newly deploy subgraph below.
Copy https://subgraph-api.mantle.xyz/subgraphs/name/test_org/token-approval
View deployed subgraph
You may view your recently deployed subgraph in your Mantle Subgraph Service Dashboard
Congratulations! 🚀🚀🚀 You have now successfully deployed the token approval subgraph on Metis Subgraph Service. You can utilize the provided deployment url to query the subgraph or integrate it into your decentralized application, enabling seamless access to Metis blockchain.