🌌
AirDAO Docs
Documentation
Documentation
  • 👋Welcome to AirDAO!
  • 🌌About AirDAO
    • What is AirDAO?
    • The AirDAO Network
      • $AMB and $BOND
      • Smart Contracts
    • Validator Nodes
      • Validation Rewards and Distribution
      • How to Setup and Run a Node on AirDAO
  • 👥Getting Started
    • User Guides
      • Connect Your Wallet
      • Purchase AMB
      • AirDAO Bridge
    • Ecosystem Products
      • Kosmos Bond Marketplace
      • Astra DEX & P2P Trading
      • Harbor Liquid Staking
  • ⚒️Build on AirDAO
    • Smart Contract Overview
    • API Guide/References
    • Predeploys and Addresses
    • How to Deploy
    • Builders Program
  • 🗣️Get in Touch
Powered by GitBook
On this page
  • Deploying Subgraphs on AirDAO Network
  • 1. Install Dependencies
  • 2. Create a New Project Directory
  • 3. Create a File for Your Contract ABI
  • 4. Initialize the Subgraph
  • 5. Update subgraph.yaml
  • 6. Define Your Entities (schema.graphql)
  • 7. Write Your Mappings (in src/)
  • 8. Generate Code & Build
  • 9. Deploy to AirDAO’s Graph Node
  • 10. Verify & Query
  1. Build on AirDAO

API Guide/References

AirDAO JSON-RPC API

The AirDAO JSON-RPC API is accessible via the AirDAO RPC endpoint. Below is a detailed guide to using the API.

Connecting to the AirDAO JSON-RPC Endpoint

Configure your application or library with the following RPC endpoint:

  • RPC Endpoint: https://network.ambrosus.io

  • RPC Endpoint: https://network.ambrosus-test.io

  • Chain ID: 16718

  • Chain ID: 22040

Example Configuration with Web3.js:

Copy

const Web3 = require('web3');

// Connect to the AirDAO RPC
const web3 = new Web3('https://network.ambrosus.io');

// Verify connection
web3.eth.net.isListening()
  .then(() => console.log('Connected to AirDAO Network'))
  .catch(error => console.error('Connection error:', error));

Example: Fetching the Latest Block

web3.eth.getBlock('latest')
  .then(block => console.log("Latest Block:", block))
  .catch(error => console.error("Error:", error));

Example: Getting an Account Balance

const address = '0x...'; // Replace with the account address
web3.eth.getBalance(address)
  .then(balance => console.log("Balance (in wei):", balance))
  .catch(error => console.error("Error:", error));

GraphQL API

GraphQL API provides an alternative and highly efficient way to query blockchain data. You may deploy your own subgraph and query blockchain data directly from the network.

Deploying Subgraphs on AirDAO Network

1. Install Dependencies

  1. Node.js and npm (or yarn)

  2. Install The Graph CLI globally:

    npm install -g @graphprotocol/graph-cli
  3. Confirm installation:

    graph --version

2. Create a New Project Directory

Create (or navigate into) a folder for your subgraph:

mkdir airdao-dex-subgraph
cd airdao-dex-subgraph

3. Create a File for Your Contract ABI

Inside the airdao-dex-subgraph folder, create a subdirectory for ABIs and place your contract’s ABI file there:

mkdir abis
touch abis/DexContract.json

Paste your ABI (in JSON format) into abis/DexContract.json.


4. Initialize the Subgraph

Run the following command to initialize the subgraph:

graph init \
  --protocol ethereum \
  --from-contract <CONTRACT_ADDRESS> \
  --index-events \
  --contract-name DexContract \
  --network mainnet \
  airdao/airdao-dex-subgraph

Note: Replace <CONTRACT_ADDRESS> with the actual contract address on AirDAO. airdao/airdao-dex-subgraph is the subgraph slug (you can rename it as needed).

This generates a basic structure:

airdao-dex-subgraph/
├─ subgraph.yaml
├─ package.json
├─ schema.graphql
├─ tsconfig.json
└─ src/

5. Update subgraph.yaml

Open subgraph.yaml and update it as follows:

specVersion: 0.0.4
schema:
  file: ./schema.graphql
dataSources:
  - kind: ethereum/contract
    name: DexContract
    network: ambnet           # Change network to "ambnet"
    source:
      address: "0x12345678..."  # Replace with your contract address
      abi: DexContract
      startBlock: 123456        # Specify the start block
    mapping:
      language: wasm/assemblyscript
      entities:
        - Trade
      abis:
        - name: DexContract
          file: ./abis/DexContract.json
      eventHandlers:
        - event: Transfer(indexed address, indexed address, uint256)
          handler: handleTransfer

Key Edits:

  • Network: Change to ambnet

  • Address: Replace with "0xYOUR_CONTRACT_ADDRESS"

  • Start Block: Set to the desired block number

  • Event Handlers: Adjust according to your contract’s event definitions


6. Define Your Entities (schema.graphql)

Define the entities to store. For example, if you want to track trades:

type Trade @entity {
  id: ID!
  from: Bytes!
  to: Bytes!
  amount: BigInt!
  timestamp: BigInt!
}

7. Write Your Mappings (in src/)

In the src/ folder, create or update your mapping file (e.g., mapping.ts) with the event logic:

import { Transfer } from "../generated/DexContract/DexContract"
import { Trade } from "../generated/schema"

export function handleTransfer(event: Transfer): void {
  let id = event.transaction.hash.toHex() + "-" + event.logIndex.toString()
  let trade = new Trade(id)
  trade.from = event.params.from
  trade.to = event.params.to
  trade.amount = event.params.value
  trade.timestamp = event.block.timestamp
  trade.save()
}

Note: Adjust the imports and event references based on your contract’s ABI and event definitions.


8. Generate Code & Build

Before deploying, generate the necessary code and build your subgraph:

  1. Generate the types from the ABI and schema:

    graph codegen
  2. Build the subgraph:

    graph build

9. Deploy to AirDAO’s Graph Node

  1. Create the subgraph:

    graph create \
      --node https://graph-node-api.ambrosus.io/deploy \
      airdao/airdao-dex-subgraph
  2. Deploy the subgraph:

    graph deploy \
      --node https://graph-node-api.ambrosus.io/deploy \
      my-org/airdao-dex-subgraph

Note: Replace my-org/airdao-dex-subgraph with your organization and subgraph name as required.


10. Verify & Query

Once deployed, you can:

  1. Visit the hosted subgraph in your browser to test queries.

  2. Query the subgraph using a GraphQL client with an endpoint similar to:

    https://graph-node-api.ambrosus.io/subgraphs/name/my-org/airdao-dex-subgraph
  3. Run a sample query to see if data is being indexed:

    {
      trades(first: 5, orderBy: timestamp, orderDirection: desc) {
        id
        from
        to
        amount
        timestamp
      }
    }

Here is an example of how to use and query Astra GraphQL API to get realtime blockchain data:

Connecting to the GraphQL Endpoint

  • Endpoint URL: https://graph-node-api.ambrosus.io/subgraphs/name/airdao/astra-fix/graphql


Query Examples

1. Fetching All Pairs

This query retrieves details about all pairs on Astra Factory contract.

query {
  pairs {
    token0Price
    token0 {
      name
    }
    token1 {
      name
    }
  }
}

2. Fetching all tokens on Astra

query {
  tokens {
    name
    symbol
  }
}

3. Querying Token Balances

Retrieve balances for an account address.


Below is an example of querying all tokens on Astra:

const { request, gql } = require('graphql-request');

// Define Astra GraphQL endpoint
const endpoint = 'https://graph-node-api.ambrosus.io/subgraphs/name/airdao/astra-fix/graphql';

// Define the GraphQL query
const query = gql`
  query {
  tokens {
    name
  }
}
`;

// Execute the query
request(endpoint, query)
  .then(data => console.log("Tokens name data:", data))
  .catch(error => console.error("Error:", error));

Useful Links

PreviousSmart Contract OverviewNextPredeploys and Addresses

Last updated 2 months ago

Deploy your subgraph to the AirDAO/Ambrosus Graph Node at :

AirDAO Graph Node:

Deploy Subgraphs:

⚒️
https://graph-node-api.ambrosus.io/deploy
https://graph-node-api.ambrosus.io
https://graph-node-api.ambrosus.io/deploy