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

Example: Getting an Account Balance


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:

  3. Confirm installation:


2. Create a New Project Directory

Create (or navigate into) a folder for your 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:

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


4. Initialize the Subgraph

Run the following command to initialize the 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:


5. Update subgraph.yaml

Open subgraph.yaml and update it as follows:

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:


7. Write Your Mappings (in src/)

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

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:

  2. Build the subgraph:


9. Deploy to AirDAO’s Graph Node

Deploy your subgraph to the AirDAO/Ambrosus Graph Node at https://graph-node-api.ambrosus.io/deploy:

  1. Create the subgraph:

  2. Deploy the 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:

  3. Run a sample query to see if data is being indexed:


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.

2. Fetching all tokens on Astra

3. Querying Token Balances

Retrieve balances for an account address.


Below is an example of querying all tokens on Astra:

Useful Links

Last updated