📊
Tx History API [Beta]
  • Introduction
  • Quick Start
  • Reference
    • API Reference
      • App
      • Chain
      • Fill
      • Liquidity Source
      • Transaction
  • Tips
Powered by GitBook
On this page
  1. Reference
  2. API Reference

Chain

Metadata of the chains in which the API is enabled.

query ChainsQuery {
  chains {
    name
    namespace
    reference
    uuid
  }
}

{
  "data": {
    "chains": [
      {
        "name": "Ethereum",
        "namespace": "eip155",
        "reference": "1",
        "uuid": "8acf2202-465d-47ae-b004-9b576dfedef7"
      },
      {
        "name": "Optimism",
        "namespace": "eip155",
        "reference": "10",
        "uuid": "c0acf60a-f13b-44ef-885f-548c83905eb0"
      },
      {
        "name": "BSC",
        "namespace": "eip155",
        "reference": "56",
        "uuid": "330be3a5-96f7-4a29-8636-15b81a00f8e2"
      },
      {
        "name": "Polygon",
        "namespace": "eip155",
        "reference": "137",
        "uuid": "cde41b7e-0f4f-4f63-aacd-d1b6ee4faaa8"
      },
      {
        "name": "Fantom",
        "namespace": "eip155",
        "reference": "250",
        "uuid": "b1e87dfa-764c-4021-81d4-5770cc0e94b4"
      },
      {
        "name": "Celo",
        "namespace": "eip155",
        "reference": "42220",
        "uuid": "315a155b-679f-4612-a699-6e7a0490d4f4"
      },
      {
        "name": "Avalanche",
        "namespace": "eip155",
        "reference": "43115",
        "uuid": "410004b6-e102-4d6b-81e1-a7547e472b3d"
      }
    ]
  }
}

async function fetchGraphQL(operationsDoc, operationName, variables) {
  const result = await fetch(
    "https://api.0x.org/data/v0",
    {
      method: "POST",
      headers: {
        '0x-api-key': 'USE_APY_KEY_HERE'
      },
      body: JSON.stringify({
        query: operationsDoc,
        variables: variables,
        operationName: operationName
      })
    }
  );

  return await result.json();
}

const operationsDoc = `
  query Chains {
    chains {
      name
      namespace
      reference
      uuid
    }
  }
`;

function fetchChains() {
  return fetchGraphQL(
    operationsDoc,
    "Chains",
    {}
  );
}

async function startFetchChains() {
  const { errors, data } = await fetchChains();

  if (errors) {
    // handle those errors like a pro
    console.error(errors);
  }

  // do something great with this precious data
  console.log(data);
}

startFetchChains();
PreviousAppNextFill

Last updated 2 years ago