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": "0xf65d6448a273b531ee942c133bb91a6f904c7d7f3104cdaf6b9f7f50d3518871",
3  "assetId": "0x0000000000000000000000000000000000000000000000000000000000000000"
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": "0xf65d6448a273b531ee942c133bb91a6f904c7d7f3104cdaf6b9f7f50d3518871"
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            contract {
16              id
17            }
18          }
19          ... on InputMessage {
20            sender
21            recipient
22            amount
23            data
24          }
25        }
26        outputs {
27          __typename
28          ... on CoinOutput {
29            to
30            amount
31            assetId
32          }
33          ... on ContractOutput {
34            inputIndex
35            balanceRoot
36            stateRoot
37          }
38          ... on ChangeOutput {
39            to
40            amount
41            assetId
42          }
43          ... on VariableOutput {
44            to
45            amount
46            assetId
47          }
48          ... on ContractCreated {
49            contract {
50              id
51            }
52            stateRoot
53          }
54        }
55        status {
56          __typename
57          ... on FailureStatus {
58            reason
59            programState {
60              returnType
61            }
62          }
63        }
64      }
65    }
66  }

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            contract {
16              id
17            }
18          }
19          ... on InputMessage {
20            sender
21            recipient
22            amount
23            data
24          }
25        }
26        outputs {
27          __typename
28          ... on CoinOutput {
29            to
30            amount
31            assetId
32          }
33          ... on ContractOutput {
34            inputIndex
35            balanceRoot
36            stateRoot
37          }
38          ... on ChangeOutput {
39            to
40            amount
41            assetId
42          }
43          ... on VariableOutput {
44            to
45            amount
46            assetId
47          }
48          ... on ContractCreated {
49            contract {
50              id
51            }
52            stateRoot
53          }
54        }
55        status {
56          __typename
57          ... on FailureStatus {
58            reason
59            programState {
60              returnType
61            }
62          }
63        }
64      }
65    }
66  }

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": "0xc9a5366c269438d294ef942bc962dd2e6c86121e3bca00192723eb7eb58fa87d",
3  "asset": "0x0000000000000000000000000000000000000000000000000000000000000000"
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": "0x0a98320d39c03337401a4e46263972a9af6ce69ec2f35a5420b1bd35784c74b1"
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              contract {
19                id
20              }
21            }
22            ... on InputMessage {
23              sender
24              recipient
25              amount
26              data
27            }
28          }
29          outputs {
30            __typename
31            ... on CoinOutput {
32              to
33              amount
34              assetId
35            }
36            ... on ContractOutput {
37              inputIndex
38              balanceRoot
39              stateRoot
40            }
41            ... on ChangeOutput {
42              to
43              amount
44              assetId
45            }
46            ... on VariableOutput {
47              to
48              amount
49              assetId
50            }
51            ... on ContractCreated {
52              contract {
53                id
54              }
55              stateRoot
56            }
57          }
58          gasPrice
59        }
60      }
61    }
62  }

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": "0xf65d6448a273b531ee942c133bb91a6f904c7d7f3104cdaf6b9f7f50d3518871"
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