⌘K

Icon HelpCircleForumIcon Link
Icon SunFilledIcon MoonStars

⌘K

Icon HelpCircleForumIcon Link
Icon SunFilledIcon MoonStars
Recipes

Icon LinkRecipes

You can see and test the example queries and mutations below. Click the "Run" button to run the query above it and see the response. Click the "TypeScript", "Apollo Client", or "urql" buttons to see code examples.

Icon LinkGet an asset balance of an address

query Balance($address: Address, $assetId: AssetId) {
    balance(owner: $address, assetId: $assetId) {
      owner
      amount
      assetId
    }
  }

Variables:

{
  "address": "0xce9f8d9367fc4671c0ececce7ab603f6f75d1e66082a82ad12ecdc219b308820",
  "assetId": "0x2a0d0ed9d2217ec7f32dcd9a1902ce2a66d68437aeff84e3a3cc8bebee0d2eea"
}
Icon LinkCheck it working
const BALANCE_QUERY = `query Balance($address: Address, $assetId: AssetId) {
    balance(owner: $address, assetId: $assetId) {
      owner
      amount
      assetId
    }
  }`;
 
const BALANCE_ARGS = {
  address: '0xce9f8d9367fc4671c0ececce7ab603f6f75d1e66082a82ad12ecdc219b308820',
  assetId: '0x2a0d0ed9d2217ec7f32dcd9a1902ce2a66d68437aeff84e3a3cc8bebee0d2eea',
};
 
const getBalance = async () => {
  const response = await fetch('https://testnet.fuel.network/v1/graphql', {
    method: 'POST',
    headers: {
      'Content-Type': 'application/json',
      Accept: 'application/json',
    },
    body: JSON.stringify({
      query: BALANCE_QUERY,
      variables: BALANCE_ARGS,
    }),
  });
  const json: any = await response.json();
  console.log('BALANCE:', json.data.balance);
  expect(json.data.balance.amount).toBeTruthy();
};
 
await getBalance();

Icon LinkList all asset balances of an address

query Balances($filter: BalanceFilterInput) {
    balances(filter: $filter, first: 5) {
      nodes {
        amount
        assetId
      }
    }
  }

Variables:

{
  "filter": {
    "owner": "0xce9f8d9367fc4671c0ececce7ab603f6f75d1e66082a82ad12ecdc219b308820"
  }
}
Icon LinkCheck it working
const BALANCES_QUERY = `query Balances($filter: BalanceFilterInput) {
    balances(filter: $filter, first: 5) {
      nodes {
        amount
        assetId
      }
    }
  }`;
 
const BALANCES_ARGS = {
  filter: {
    owner: '0xce9f8d9367fc4671c0ececce7ab603f6f75d1e66082a82ad12ecdc219b308820',
  },
};
 
const getBalances = async () => {
  const response = await fetch('https://testnet.fuel.network/v1/graphql', {
    method: 'POST',
    headers: {
      'Content-Type': 'application/json',
      Accept: 'application/json',
    },
    body: JSON.stringify({
      query: BALANCES_QUERY,
      variables: BALANCES_ARGS,
    }),
  });
  const json: any = await response.json();
  console.log('BALANCES:', json.data.balances);
  expect(json.data.balances.nodes).toBeTruthy();
};
 
await getBalances();

Icon LinkList all transactions from an address

query Transactions($address: Address) {
  transactionsByOwner(owner: $address, first: 5) {
    nodes {
      id
      inputs {
        __typename
        ... on InputCoin {
          owner
          utxoId
          amount
          assetId
        }
        ... on InputContract {
          utxoId
          contractId
        }
        ... on InputMessage {
          sender
          recipient
          amount
          data
        }
      }
      outputs {
        __typename
        ... on CoinOutput {
          to
          amount
          assetId
        }
        ... on ContractOutput {
          inputIndex
          balanceRoot
          stateRoot
        }
        ... on ChangeOutput {
          to
          amount
          assetId
        }
        ... on VariableOutput {
          to
          amount
          assetId
        }
        ... on ContractCreated {
          contract
          stateRoot
        }
      }
      status {
        __typename
        ... on FailureStatus {
          reason
          programState {
            returnType
          }
        }
      }
    }
  }
}

Variables:

{
  "address": "0xf65d6448a273b531ee942c133bb91a6f904c7d7f3104cdaf6b9f7f50d3518871"
}
Icon LinkCheck it working
const TRANSACTIONS_QUERY = `query Transactions($address: Address) {
  transactionsByOwner(owner: $address, first: 5) {
    nodes {
      id
      inputs {
        __typename
        ... on InputCoin {
          owner
          utxoId
          amount
          assetId
        }
        ... on InputContract {
          utxoId
          contractId
        }
        ... on InputMessage {
          sender
          recipient
          amount
          data
        }
      }
      outputs {
        __typename
        ... on CoinOutput {
          to
          amount
          assetId
        }
        ... on ContractOutput {
          inputIndex
          balanceRoot
          stateRoot
        }
        ... on ChangeOutput {
          to
          amount
          assetId
        }
        ... on VariableOutput {
          to
          amount
          assetId
        }
        ... on ContractCreated {
          contract
          stateRoot
        }
      }
      status {
        __typename
        ... on FailureStatus {
          reason
          programState {
            returnType
          }
        }
      }
    }
  }
}`;
 
const TRANSACTIONS_ARGS = {
  address: '0xf65d6448a273b531ee942c133bb91a6f904c7d7f3104cdaf6b9f7f50d3518871',
};
 
const getTransactions = async () => {
  const response = await fetch('https://testnet.fuel.network/v1/graphql', {
    method: 'POST',
    headers: {
      'Content-Type': 'application/json',
      Accept: 'application/json',
    },
    body: JSON.stringify({
      query: TRANSACTIONS_QUERY,
      variables: TRANSACTIONS_ARGS,
    }),
  });
  const json: any = await response.json();
  console.log('TRANSACTIONS:', json.data.transactionsByOwner);
  expect(Array.isArray(json.data.transactionsByOwner.nodes)).toBeTruthy();
};
 
await getTransactions();

Icon LinkList the latest transactions

query LatestTransactions {
    transactions(last: 5) {
      nodes {
        id
        inputs {
          __typename
          ... on InputCoin {
            owner
            utxoId
            amount
            assetId
          }
          ... on InputContract {
            utxoId
            contractId
          }
          ... on InputMessage {
            sender
            recipient
            amount
            data
          }
        }
        outputs {
          __typename
          ... on CoinOutput {
            to
            amount
            assetId
          }
          ... on ContractOutput {
            inputIndex
            balanceRoot
            stateRoot
          }
          ... on ChangeOutput {
            to
            amount
            assetId
          }
          ... on VariableOutput {
            to
            amount
            assetId
          }
          ... on ContractCreated {
            contract
            stateRoot
          }
        }
        status {
          __typename
          ... on FailureStatus {
            reason
            programState {
              returnType
            }
          }
        }
      }
    }
  }
Icon LinkCheck it working
const LATEST_TRANSACTIONS_QUERY = `query LatestTransactions {
    transactions(last: 5) {
      nodes {
        id
        inputs {
          __typename
          ... on InputCoin {
            owner
            utxoId
            amount
            assetId
          }
          ... on InputContract {
            utxoId
            contractId
          }
          ... on InputMessage {
            sender
            recipient
            amount
            data
          }
        }
        outputs {
          __typename
          ... on CoinOutput {
            to
            amount
            assetId
          }
          ... on ContractOutput {
            inputIndex
            balanceRoot
            stateRoot
          }
          ... on ChangeOutput {
            to
            amount
            assetId
          }
          ... on VariableOutput {
            to
            amount
            assetId
          }
          ... on ContractCreated {
            contract
            stateRoot
          }
        }
        status {
          __typename
          ... on FailureStatus {
            reason
            programState {
              returnType
            }
          }
        }
      }
    }
  }`;
 
const getLatestTransactions = async () => {
  const response = await fetch('https://testnet.fuel.network/v1/graphql', {
    method: 'POST',
    headers: {
      'Content-Type': 'application/json',
      Accept: 'application/json',
    },
    body: JSON.stringify({
      query: LATEST_TRANSACTIONS_QUERY,
    }),
  });
  const json: any = await response.json();
  console.log('TRANSACTIONS:', json.data.transactions);
  expect(json.data.transactions.nodes.length).toBeTruthy();
};
 
await getLatestTransactions();

Icon LinkGet an asset balance of a contract

query ContractBalance($contract: ContractId, $asset: AssetId) {
    contractBalance(contract: $contract, asset: $asset) {
      contract
      amount
      assetId
    }
  }

Variables:

{
  "contract": "0xf5b08689ada97df7fd2fbd67bee7dea6d219f117c1dc9345245da16fe4e99111",
  "asset": "0x2a0d0ed9d2217ec7f32dcd9a1902ce2a66d68437aeff84e3a3cc8bebee0d2eea"
}
Icon LinkCheck it working
const CONTRACT_BALANCE_QUERY = `query ContractBalance($contract: ContractId, $asset: AssetId) {
    contractBalance(contract: $contract, asset: $asset) {
      contract
      amount
      assetId
    }
  }`;
 
const CONTRACT_BALANCE_ARGS = {
  contract:
    '0xf5b08689ada97df7fd2fbd67bee7dea6d219f117c1dc9345245da16fe4e99111',
  asset: '0x2a0d0ed9d2217ec7f32dcd9a1902ce2a66d68437aeff84e3a3cc8bebee0d2eea',
};
 
const getContractBalance = async () => {
  const response = await fetch('https://testnet.fuel.network/v1/graphql', {
    method: 'POST',
    headers: {
      'Content-Type': 'application/json',
      Accept: 'application/json',
    },
    body: JSON.stringify({
      query: CONTRACT_BALANCE_QUERY,
      variables: CONTRACT_BALANCE_ARGS,
    }),
  });
  const json: any = await response.json();
  console.log('CONTRACT BALANCE:', json.data.contractBalance);
  expect(json.data.contractBalance.amount).toBeTruthy();
};
 
await getContractBalance();

Icon LinkList all asset balances of a contract

query ContractBalances($filter: ContractBalanceFilterInput!) {
    contractBalances(filter: $filter, first: 5) {
    nodes {
        amount
        assetId
    }
    }
}

Variables:

{
  "filter": {
    "contract": "0xf5b08689ada97df7fd2fbd67bee7dea6d219f117c1dc9345245da16fe4e99111"
  }
}
Icon LinkCheck it working
const CONTRACT_BALANCES_QUERY = `query ContractBalances($filter: ContractBalanceFilterInput!) {
    contractBalances(filter: $filter, first: 5) {
    nodes {
        amount
        assetId
    }
    }
}`;
 
const CONTRACT_BALANCES_ARGS = {
  filter: {
    contract:
      '0xf5b08689ada97df7fd2fbd67bee7dea6d219f117c1dc9345245da16fe4e99111',
  },
};
 
const getContractBalances = async () => {
  const response = await fetch('https://testnet.fuel.network/v1/graphql', {
    method: 'POST',
    headers: {
      'Content-Type': 'application/json',
      Accept: 'application/json',
    },
    body: JSON.stringify({
      query: CONTRACT_BALANCES_QUERY,
      variables: CONTRACT_BALANCES_ARGS,
    }),
  });
  const json: any = await response.json();
  console.log('CONTRACT BALANCES:', json.data.contractBalances);
  expect(json.data.contractBalances.nodes).toBeTruthy();
};
 
await getContractBalances();

Icon LinkList the latest blocks

query LatestBlocks {
    blocks(last: 5) {
      nodes {
        id
        transactions {
          id
          inputAssetIds
          inputs {
            __typename
            ... on InputCoin {
              owner
              utxoId
              amount
              assetId
            }
            ... on InputContract {
              utxoId
              contractId
            }
            ... on InputMessage {
              sender
              recipient
              amount
              data
            }
          }
          outputs {
            __typename
            ... on CoinOutput {
              to
              amount
              assetId
            }
            ... on ContractOutput {
              inputIndex
              balanceRoot
              stateRoot
            }
            ... on ChangeOutput {
              to
              amount
              assetId
            }
            ... on VariableOutput {
              to
              amount
              assetId
            }
            ... on ContractCreated {
              contract
              stateRoot
            }
          }
        }
      }
    }
  }
Icon LinkCheck it working
const LATEST_BLOCKS_QUERY = `query LatestBlocks {
    blocks(last: 5) {
      nodes {
        id
        transactions {
          id
          inputAssetIds
          inputs {
            __typename
            ... on InputCoin {
              owner
              utxoId
              amount
              assetId
            }
            ... on InputContract {
              utxoId
              contractId
            }
            ... on InputMessage {
              sender
              recipient
              amount
              data
            }
          }
          outputs {
            __typename
            ... on CoinOutput {
              to
              amount
              assetId
            }
            ... on ContractOutput {
              inputIndex
              balanceRoot
              stateRoot
            }
            ... on ChangeOutput {
              to
              amount
              assetId
            }
            ... on VariableOutput {
              to
              amount
              assetId
            }
            ... on ContractCreated {
              contract
              stateRoot
            }
          }
        }
      }
    }
  }`;
 
const getLatestBlocks = async () => {
  const response = await fetch('https://testnet.fuel.network/v1/graphql', {
    method: 'POST',
    headers: {
      'Content-Type': 'application/json',
      Accept: 'application/json',
    },
    body: JSON.stringify({
      query: LATEST_BLOCKS_QUERY,
    }),
  });
  const json: any = await response.json();
  console.log('BLOCKS:', json.data.blocks);
  expect(json.data.blocks.nodes.length).toBeTruthy();
};
 
await getLatestBlocks();

Icon LinkGet block information by height

query Block($height: U64) {
    block(height: $height) {
      id
    }
  }

Variables:

{
  "height": "3412"
}
Icon LinkCheck it working
const BLOCK_BY_HEIGHT_QUERY = `query Block($height: U64) {
    block(height: $height) {
      id
    }
  }`;
 
const BLOCK_BY_HEIGHT_ARGS = {
  height: '3412',
};
 
const getBlock = async () => {
  const response = await fetch('https://testnet.fuel.network/v1/graphql', {
    method: 'POST',
    headers: {
      'Content-Type': 'application/json',
      Accept: 'application/json',
    },
    body: JSON.stringify({
      query: BLOCK_BY_HEIGHT_QUERY,
      variables: BLOCK_BY_HEIGHT_ARGS,
    }),
  });
  const json: any = await response.json();
  console.log('BLOCK:', json.data.block);
  expect(json.data.block.id).toBeTruthy();
};
 
await getBlock();

Icon LinkList all messages owned by address

query MessageInfo($address: Address) {
    messages(owner: $address, first: 5) {
      nodes {
        amount
        sender
        recipient
        nonce
        data
        daHeight
      }
    }
  }

Variables:

{
  "address": "0xce9f8d9367fc4671c0ececce7ab603f6f75d1e66082a82ad12ecdc219b308820"
}
Icon LinkCheck it working
const MESSAGE_INFO_QUERY = `query MessageInfo($address: Address) {
    messages(owner: $address, first: 5) {
      nodes {
        amount
        sender
        recipient
        nonce
        data
        daHeight
      }
    }
  }`;
 
const MESSAGE_INFO_ARGS = {
  address: '0xce9f8d9367fc4671c0ececce7ab603f6f75d1e66082a82ad12ecdc219b308820',
};
 
const getMessages = async () => {
  const response = await fetch('https://testnet.fuel.network/v1/graphql', {
    method: 'POST',
    headers: {
      'Content-Type': 'application/json',
      Accept: 'application/json',
    },
    body: JSON.stringify({
      query: MESSAGE_INFO_QUERY,
      variables: MESSAGE_INFO_ARGS,
    }),
  });
  const json: any = await response.json();
  console.log('MESSAGES:', json.data.messages);
  expect(json.data.messages.nodes).toBeTruthy();
};
 
await getMessages();

Icon LinkDry run a transaction

mutation DryRun($encodedTransaction: HexString!, $utxoValidation: Boolean) {
  dryRun(tx: $encodedTransaction, utxoValidation: $utxoValidation) {
    receiptType
    data
  }
}

Icon LinkSubmit a transaction

mutation submit($encodedTransaction: HexString!) {
  submit(tx: $encodedTransaction) {
    id
  }
}

Icon LinkMore Examples

You can find more examples of how we use this API in our GitHub:

Fuels Typescript SDK Icon Link

Fuels Rust SDK Icon Link