Docs Icon CaretRight Recipes

Recipes

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.

Get an asset balance of an address

1query Balance($address: Address, $assetId: AssetId) {
2    balance(owner: $address, assetId: $assetId) {
3      owner
4      amount
5      assetId
6    }
7  }

Variables:

1{
2  "address": "0xce9f8d9367fc4671c0ececce7ab603f6f75d1e66082a82ad12ecdc219b308820",
3  "assetId": "0x2a0d0ed9d2217ec7f32dcd9a1902ce2a66d68437aeff84e3a3cc8bebee0d2eea"
4}

List all asset balances of an address

1query Balances($filter: BalanceFilterInput) {
2    balances(filter: $filter, first: 5) {
3      nodes {
4        amount
5        assetId
6      }
7    }
8  }

Variables:

1{
2  "filter": {
3    "owner": "0xce9f8d9367fc4671c0ececce7ab603f6f75d1e66082a82ad12ecdc219b308820"
4  }
5}

List all transactions from an address

1query Transactions($address: Address) {
2  transactionsByOwner(owner: $address, first: 5) {
3    nodes {
4      id
5      inputs {
6        __typename
7        ... on InputCoin {
8          owner
9          utxoId
10          amount
11          assetId
12        }
13        ... on InputContract {
14          utxoId
15          contractId
16        }
17        ... on InputMessage {
18          sender
19          recipient
20          amount
21          data
22        }
23      }
24      outputs {
25        __typename
26        ... on CoinOutput {
27          to
28          amount
29          assetId
30        }
31        ... on ContractOutput {
32          inputIndex
33          balanceRoot
34          stateRoot
35        }
36        ... on ChangeOutput {
37          to
38          amount
39          assetId
40        }
41        ... on VariableOutput {
42          to
43          amount
44          assetId
45        }
46        ... on ContractCreated {
47          contract
48          stateRoot
49        }
50      }
51      status {
52        __typename
53        ... on FailureStatus {
54          reason
55          programState {
56            returnType
57          }
58        }
59      }
60    }
61  }
62}

Variables:

1{
2  "address": "0xf65d6448a273b531ee942c133bb91a6f904c7d7f3104cdaf6b9f7f50d3518871"
3}

List the latest transactions

1query LatestTransactions {
2    transactions(last: 5) {
3      nodes {
4        id
5        inputs {
6          __typename
7          ... on InputCoin {
8            owner
9            utxoId
10            amount
11            assetId
12          }
13          ... on InputContract {
14            utxoId
15            contractId
16          }
17          ... on InputMessage {
18            sender
19            recipient
20            amount
21            data
22          }
23        }
24        outputs {
25          __typename
26          ... on CoinOutput {
27            to
28            amount
29            assetId
30          }
31          ... on ContractOutput {
32            inputIndex
33            balanceRoot
34            stateRoot
35          }
36          ... on ChangeOutput {
37            to
38            amount
39            assetId
40          }
41          ... on VariableOutput {
42            to
43            amount
44            assetId
45          }
46          ... on ContractCreated {
47            contract
48            stateRoot
49          }
50        }
51        status {
52          __typename
53          ... on FailureStatus {
54            reason
55            programState {
56              returnType
57            }
58          }
59        }
60      }
61    }
62  }

Get an asset balance of a contract

1query ContractBalance($contract: ContractId, $asset: AssetId) {
2    contractBalance(contract: $contract, asset: $asset) {
3      contract
4      amount
5      assetId
6    }
7  }

Variables:

1{
2  "contract": "0xf5b08689ada97df7fd2fbd67bee7dea6d219f117c1dc9345245da16fe4e99111",
3  "asset": "0x2a0d0ed9d2217ec7f32dcd9a1902ce2a66d68437aeff84e3a3cc8bebee0d2eea"
4}

List all asset balances of a contract

1query ContractBalances($filter: ContractBalanceFilterInput!) {
2    contractBalances(filter: $filter, first: 5) {
3    nodes {
4        amount
5        assetId
6    }
7    }
8}

Variables:

1{
2  "filter": {
3    "contract": "0xf5b08689ada97df7fd2fbd67bee7dea6d219f117c1dc9345245da16fe4e99111"
4  }
5}

List the latest blocks

1query LatestBlocks {
2    blocks(last: 5) {
3      nodes {
4        id
5        transactions {
6          id
7          inputAssetIds
8          inputs {
9            __typename
10            ... on InputCoin {
11              owner
12              utxoId
13              amount
14              assetId
15            }
16            ... on InputContract {
17              utxoId
18              contractId
19            }
20            ... on InputMessage {
21              sender
22              recipient
23              amount
24              data
25            }
26          }
27          outputs {
28            __typename
29            ... on CoinOutput {
30              to
31              amount
32              assetId
33            }
34            ... on ContractOutput {
35              inputIndex
36              balanceRoot
37              stateRoot
38            }
39            ... on ChangeOutput {
40              to
41              amount
42              assetId
43            }
44            ... on VariableOutput {
45              to
46              amount
47              assetId
48            }
49            ... on ContractCreated {
50              contract
51              stateRoot
52            }
53          }
54        }
55      }
56    }
57  }

Get block information by height

1query Block($height: U64) {
2    block(height: $height) {
3      id
4    }
5  }

Variables:

1{
2  "height": "3412"
3}

List all messages owned by address

1query MessageInfo($address: Address) {
2    messages(owner: $address, first: 5) {
3      nodes {
4        amount
5        sender
6        recipient
7        nonce
8        data
9        daHeight
10      }
11    }
12  }

Variables:

1{
2  "address": "0xce9f8d9367fc4671c0ececce7ab603f6f75d1e66082a82ad12ecdc219b308820"
3}

Dry run a transaction

1mutation DryRun($encodedTransaction: HexString!, $utxoValidation: Boolean) {
2  dryRun(tx: $encodedTransaction, utxoValidation: $utxoValidation) {
3    receiptType
4    data
5  }
6}

Submit a transaction

1mutation submit($encodedTransaction: HexString!) {
2  submit(tx: $encodedTransaction) {
3    id
4  }
5}

More 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