Skip to content

Indexers API

Overview

XDEFI provides Indexers API for developers to fetch balances, transactions, fees across many blockchains supported by XDEFI Wallet.

The base URL for all API endpoints is: https://gql-router.xdefi.services/graphql.

Here are the chains supported by the Indexers API:
ChainKeyBase chain
AkashakashCosmosChain
ArbitrumarbitrumEVM
AuroraauroraEVM
AvalancheavalancheEVM
AxelaraxelarCosmosChain
BinancebinanceBinanceChain
Binance Smart ChainbinanceSmartChainEVM
BitcoinbitcoinBitcoinChain
Bitcoin CashbitcoincashBitcoinChain
CantocantoEVMEVM
Cosmos HubcosmosCosmosChain
CrescentcrescentCosmosChain
CronoscronosEVMEVM
DogecoindogecoinBitcoinChain
EthereumethereumEVM
FantomfantomEVM
JunojunoCosmosChain
KavakavaCosmosChain
KujirakujiraCosmosChain
LitecoinlitecoinBitcoinChain
Maya ProtocolmayachainMayaChain
NearnearNearChain
OptimismoptimismEVM
OsmosisosmosisCosmosChain
PolygonpolygonEVM
SolanasolanaSolanaChain
StargazestargazeStargazeChain
StridestrideCosmosChain
ThorChainthorchainThorChain
TrontronTronChain

Get Balance

javascript
const GRAPHQL_ENDPOINT = "https://gql-router.xdefi.services/graphql";
const query = `query GetBalances($address: String!, $first: Int, $after: String) {
  ${chain.key} {
    balances(address: $address, first: $first, after: $after) {
      amount {
        value
      }
    }
  }
}`;

await fetch(GRAPHQL_ENDPOINT, {
  method: "POST",
  headers: {
    "Content-Type": "application/json",
    "apollographql-client-name": "docs-indexers-api",
    "apollographql-client-version": "v1.0",
  },
  body: JSON.stringify({
    query,
    variables: {
      address: address // Input address
      first: 1,
      after: null,
    },
  }),
})
  .then((response) => response.json())
  .then((result) => {
    console.log(result);
    // Do something with the result
  });
javascript
const GRAPHQL_ENDPOINT = "https://gql-router.xdefi.services/graphql";
const query = `query GetBalances($address: String!, $tokenAddresses: [String!]) {
  ${chain.key} {
    balances(address: $address, tokenAddresses: $tokenAddresses) {
      amount {
        value
      }
    }
  }
}`;

await fetch(GRAPHQL_ENDPOINT, {
  method: "POST",
  headers: {
    "Content-Type": "application/json",
  },
  body: JSON.stringify({
    query,
    variables: {
      address: address // Input address
      tokenAddresses: null,
    },
  }),
})
  .then((response) => response.json())
  .then((result) => {
    console.log(result);
    // Do something with the result
  });
javascript
const GRAPHQL_ENDPOINT = "https://gql-router.xdefi.services/graphql";
const query = `query GetBalances($address: String!) {
  ${chain.key} {
    balances(address: $address) {
      amount {
        value
      }
    }
  }
}`;

await fetch(GRAPHQL_ENDPOINT, {
  method: "POST",
  headers: {
    "Content-Type": "application/json",
    "apollographql-client-name": "docs-indexers-api",
    "apollographql-client-version": "v1.0",
  },
  body: JSON.stringify({
    query,
    variables: {
      address: address, // Input address
    },
  }),
})
  .then((response) => response.json())
  .then((result) => {
    console.log(result);
    // Do something with the result
  });

Get Gas Fee

javascript
const GRAPHQL_ENDPOINT = "https://gql-router.xdefi.services/graphql";
const query = `query GetGasFee {
  ${chain.key} {
    fee {
      high
      low
      medium
    }
  }
}`;

await fetch(GRAPHQL_ENDPOINT, {
  method: "POST",
  headers: {
    "Content-Type": "application/json",
    "apollographql-client-name": "docs-indexers-api",
    "apollographql-client-version": "v1.0",
  },
  body: JSON.stringify({
    query,
  }),
})
  .then((response) => response.json())
  .then((result) => {
    console.log(result);
    // Do something with the result
  });
javascript
const GRAPHQL_ENDPOINT = "https://gql-router.xdefi.services/graphql";
const query = `query GetFee {
  ${chain.key} {
    fee {
      defaultGasPrice
      high {
        maxFeePerGas
        baseFeePerGas
        priorityFeePerGas
      }
      low {
        baseFeePerGas
        maxFeePerGas
        priorityFeePerGas
      }
      medium {
        baseFeePerGas
        maxFeePerGas
        priorityFeePerGas
      }
    }
  }
}`;
await fetch(GRAPHQL_ENDPOINT, {
  method: "POST",
  headers: {
    "Content-Type": "application/json",
    "apollographql-client-name": "docs-indexers-api",
    "apollographql-client-version": "v1.0",
  },
  body: JSON.stringify({
    query,
  }),
})
  .then((response) => response.json())
  .then((result) => {
    console.log(result);
    // Do something with the result
  });

UTXOs (Bitcoin, Bitcoin Cash, Dogecoin, Litecoin)

Get Unspent Transaction Outputs (UTXOs)

javascript
const GRAPHQL_ENDPOINT = "https://gql-router.xdefi.services/graphql";
const query = `query GetUnspentTxOutputsV5($address: String!, $page: Int!) {
  ${chain.key} {
    unspentTxOutputsV5(address: $address, page: $page) {
      oIndex
      oTxHash
      value {
        value
      }
      scriptHex
      oTxHex
      isCoinbase
      address
    }
  }
}`;

await fetch(GRAPHQL_ENDPOINT, {
  method: "POST",
  headers: {
    "Content-Type": "application/json",
    "apollographql-client-name": "docs-indexers-api",
    "apollographql-client-version": "v1.0",
  },
  body: JSON.stringify({
    query,
    variables: {
      address: address, // Input address
      page: 1,
    },
  }),
})
  .then((response) => response.json())
  .then((result) => {
    console.log(result);
    // Do something with the result
  });

Broadcast Transaction

javascript
const GRAPHQL_ENDPOINT = "https://gql-router.xdefi.services/graphql";
const query = `query BroadcastTransaction($rawHex: String!) {
  ${chain.key} {
    broadcastTransaction(rawHex: $rawHex)
  }
}`;

await fetch(GRAPHQL_ENDPOINT, {
  method: "POST",
  headers: {
    "Content-Type": "application/json",
    "apollographql-client-name": "docs-indexers-api",
    "apollographql-client-version": "v1.0",
  },
  body: JSON.stringify({
    query,
    variables: {
      rawHex: rawHex, // Input raw transaction hex
    },
  }),
})
  .then((response) => response.json())
  .then((result) => {
    console.log(result);
    // Do something with the result
  });

View more about raw transaction hex here.