API Examples: List Transactions

Authentication

The first step in interacting with IO GraphQL API is to authenticate through our OAuth service. This process involves obtaining an access token, which is crucial for making authenticated requests to our GraphQL endpoint. For comprehensive instructions and best practices on authentication, please visit our authentication guide.

const authResponse = await fetch('https://api.iofinnet.com/auth/v1/accessToken', {
  method: 'POST',
  headers: {
    'Content-Type': 'application/json',
    Accept: 'application/json'
  },
  body: JSON.stringify({
    clientId: "<client_id>",
    clientSecret: "<client_secret>"
  })
});

Executing a Basic GraphQL Query

Once you have obtained your access token, it becomes the key to securely interacting with our GraphQL endpoint. Ensure that every request includes this token within the 'Authorization' header. Remember, GraphQL operates exclusively with POST requests, so set your HTTP method accordingly. This example illustrates the use of GraphQL fragments, a powerful feature for structuring queries within our schema. These fragments are particularly useful given the complexity and flexibility of our API. For an extensive list of query possibilities that our API supports, refer to our queries documentation.

const vaults = await fetch('https://api.iofinnet.com/graphql', {
  method: 'POST',
  headers: {
    'Content-Type': 'application/json',
    Authorization: `Bearer ${authResponse.accessToken}`,
  },
  body: JSON.stringify({
    query: `
        query {
          operationHistory{
            edges {
              node {

                  ... on OperationTransferIn {
                    amount
                    fromAddressHash
                    __typename
                  }
                  ... on OperationTransferOut {
                    amount
                    toAddressHash
                    __typename
                  }
              }
            }
          }
        }
    `,
  }),
});
console.log(vaults)
{
  "data": {
    "operationHistory": {
      "edges": [
        {
          "node": {
            "amount": "100",
            "toAddressHash": "0xe5D79fF6E9f6f2Df3d0C5a4e103A4Db0A5B02588",
            "__typename": "OperationTransferOut"
          }
        },
        {
          "node": {
            "amount": "12",
            "toAddressHash": "0x72FaE7C59377E6Ed087Ad5604976F3fe51A58119",
            "__typename": "OperationTransferOut"
          }
        },
        {
          "node": {
            "amount": "600",
            "toAddressHash": "0x21f9225F9015eD5FD283Ac5439ff7c4b63a57491",
            "__typename": "OperationTransferOut"
          }
        },
        {
          "node": {
            "amount": "30",
            "toAddressHash": "0x21f9225F9015eD5FD283Ac5439ff7c4b63a57491",
            "__typename": "OperationTransferOut"
          }
        },
        {
          "node": {
            "amount": "500",
            "toAddressHash": "0x21f9225F9015eD5FD283Ac5439ff7c4b63a57491",
            "__typename": "OperationTransferOut"
          }
        },
        {
          "node": {
            "amount": "5000",
            "toAddressHash": "0x10cd80c5ab527cB766791899B599aC11ED8b732b",
            "__typename": "OperationTransferOut"
          }
        }
      ]
    }
  }
}

Note: select the JSON tab in the above code window to see the response.

Useful Links