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.ioRPC Endpoint:
https://network.ambrosus-test.ioChain 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
Node.js and npm (or yarn)
Install The Graph CLI globally:
npm install -g @graphprotocol/graph-cliConfirm 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-subgraph3. 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.jsonPaste 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-subgraphNote: Replace
<CONTRACT_ADDRESS>with the actual contract address on AirDAO.airdao/airdao-dex-subgraphis 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
subgraph.yamlOpen 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: handleTransferKey Edits:
Network: Change to
ambnetAddress: 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)
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/)
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:
Generate the types from the ABI and schema:
graph codegenBuild the subgraph:
graph build
9. Deploy to AirDAO’s Graph Node
Deploy your subgraph to the AirDAO/Ambrosus Graph Node at https://graph-node-api.ambrosus.io/deploy:
Create the subgraph:
graph create \ --node https://graph-node-api.ambrosus.io/deploy \ airdao/airdao-dex-subgraphDeploy the subgraph:
graph deploy \ --node https://graph-node-api.ambrosus.io/deploy \ my-org/airdao-dex-subgraph
Note: Replace
my-org/airdao-dex-subgraphwith your organization and subgraph name as required.
10. Verify & Query
Once deployed, you can:
Visit the hosted subgraph in your browser to test queries.
Query the subgraph using a GraphQL client with an endpoint similar to:
https://graph-node-api.ambrosus.io/subgraphs/name/my-org/airdao-dex-subgraphRun 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
AirDAO Graph Node: https://graph-node-api.ambrosus.io
Deploy Subgraphs: https://graph-node-api.ambrosus.io/deploy
Last updated