Somnia Docs
Developer DiscordTestnet Homepage
Somnia Documentation
Somnia Documentation
  • 📍Introduction
  • 🔥Get Started
    • Connect your Wallet
    • Request STT Tokens & Try sending tokens to a Random address
    • Removing the Somnia Devnet Network
    • Update the block explorer in metamask
  • Developer
    • Network Info
    • Resources & Important Links
    • Add Custom token in Metamask
    • Tutorials
      • How to Deploy Your First Smart Contract to Somnia Network
      • Create and Deploy your ERC20 Smart Contract to Somnia Network
      • Deploy and Verify A Smart Contract on Somnia using Hardhat
      • Deploy a Smart Contract on Somnia Testnet using Foundry
      • How to Connect to Somnia Network via Viem Library
      • How to Setup MetaMask Authentication to Connect Somnia Network
      • Build a Simple DAO Smart Contract
      • How To Build A User Interface For DAO Smart Contract p1
      • How To Build A User Interface For DAO Smart Contract p2
      • How To Build A User Interface For DAO Smart Contract p3
    • Partners
      • How to deploy Smart Contracts to Somnia using Thirdweb
      • Integrate ConnectKit with Somnia in a Next.js Application
      • Integrating RainbowKit with Somnia in a Next.js Application
      • Integrating DIA Oracles on Somnia
      • Indexing Data on Somnia using Graph Services
      • Somnia Account Abstraction Apps using Thirdweb React SDK
      • Build a NextJS UI for Subgraphs on Somnia
      • Deploy a Subgraph on Somnia using Ormi
    • Infrastructure Providers
      • RPC
      • Oracles
      • Safes
      • Explorers
      • SDKs
  • 📜Litepaper
    • Mission
    • Problem
  • ⛓️Somnia Blockchain
    • Overview
    • MultiStream Consensus
    • Accelerated Sequential Execution
    • Somnia's IceDB
    • Advanced Compression Techniques
    • Security
    • Use Cases
  • 🌐Ecosystem
    • Protocols
      • SOM0
      • SOM1
    • Experiences
      • Metaverse Browser
      • Somnia Playground
    • Content Creation
  • 🌑Conclusion
Powered by GitBook
On this page
  • Prerequisites
  • Install Graph CLI globally
  • Initialize Your Subgraph
  • Define the Subgraph Schema
  • Build the Subgraph
  • Deploy Using Ormi
  • Conclusion
Export as PDF
  1. Developer
  2. Partners

Deploy a Subgraph on Somnia using Ormi

PreviousBuild a NextJS UI for Subgraphs on SomniaNextInfrastructure Providers

Last updated 18 hours ago

The Graph is a decentralized indexing protocol that allows developers to query blockchain data using GraphQL. Instead of parsing complex raw logs and events directly from smart contracts, developers can build subgraphs that transform onchain activity into structured, queryable datasets.

This tutorial demonstrates how to deploy a subgraph on the Somnia Testnet using , a powerful gateway that simplifies subgraph deployment through a hosted Graph Node and IPFS infrastructure.

Prerequisites

  • GraphQL is installed and set up on your local machine.

  • A verified smart contract address deployed on Somnia.

  • An Ormi account and Private Key.

Install Graph CLI globally

npm install -g @graphprotocol/graph-cli

Initialize Your Subgraph

The Graph services rely on the existence of a deployed Smart Contract with onchain activity. The subgraph will be created based on indexing the events emitted from the Smart Contract. To set up a subgraph service for an example contract called MyToken run the following command to scaffold a new subgraph project:

graph init --contract-name MyToken --from-contract 0xYourTokenAddress --network somnia-testnet mytoken

mytoken is the folder that contains the subgraph files. Replace 0xYourTokenAddress with your actual deployed Smart Contract address on Somnia.

This command will generate the following files:

  • subgraph.yamlDefines the data sources and events to index

  • schema.graphql Structure of your data

  • src/mytoken.tsTypeScript logic to handle events

Define the Subgraph Schema

For the exampleMyToken Contract, which is an ERC20 Token, Edit schema.graphql to index all the Transfer events emitted from the Smart Contract.

type Transfer @entity(immutable: true) {
  id: Bytes!
  from: Bytes!
  to: Bytes!
  value: BigInt!
  blockNumber: BigInt!
  blockTimestamp: BigInt!
  transactionHash: Bytes!
}

Build the Subgraph

After customizing your schema and mapping logic, build the subgraph by running the command:

graph codegen && graph build

This will generate the necessary artifacts for deployment.

Deploy Using Ormi

On the left navigation menu, click the "key" icon to access your privateKey.

Deploy your subgraph to Ormi’s hosted infrastructure with the following command:

graph deploy mytoken --node https://api.subgraph.somnia.network/deploy --ipfs https://api.subgraph.somnia.network/ipfs --deploy-key yourORMIPrivateKey

Replace yourPrivateKey with your Somnia Ormi account private key.

Once deployed, Ormi will return a GraphQL endpoint where you can begin querying your subgraph.

Return to the dashboard to find your list of deployed subgraphs.

Open the deployed subgraph in the explorer to interact with it:

Conclusion

You have successfully deployed a subgraph to index events emitted from your Smart Contract. To challenge yourself even further, you can extend your build:

  • Expand your schema and mapping logic to cover more events.

  • Connect your subgraph to a frontend UI or analytics dashboard.

Open the Somnia Ormi website and create an account.

For more information, visit the Ormi .

Ormi
https://subgraph.somnia.network/
docs