Skip to main content

List Accounts

Query multiple accounts with filtering, sorting, and pagination.

Query Structure​

query GetAccounts(
$where: accounts_bool_exp
$order_by: [accounts_order_by!]
$limit: Int
$offset: Int
) {
accounts(
where: $where
order_by: $order_by
limit: $limit
offset: $offset
) {
id
label
image
type
created_at
}
accounts_aggregate(where: $where) {
aggregate {
count
}
}
}

Variables​

{
"where": {
"type": { "_eq": "AtomWallet" }
},
"order_by": [{ "created_at": "desc" }],
"limit": 20,
"offset": 0
}

Response Fields​

FieldTypeDescription
idStringAccount address
labelStringHuman-readable name
imageStringProfile image URL
typeStringAccount type
created_atDateTimeFirst interaction timestamp

Interactive Example​

Query

query GetRecentAccounts($limit: Int!) {
  accounts(
    order_by: { created_at: desc }
    limit: $limit
  ) {
    id
    label
    image
    type
    created_at
  }
}

Variables

Click "Run Query" to execute the GraphQL query and see results

Use Cases​

Search Accounts​

Search accounts by label:

async function searchAccounts(searchTerm: string, limit: number = 20) {
const query = `
query SearchAccounts($search: String!, $limit: Int!) {
accounts(
where: { label: { _ilike: $search } }
order_by: { label: asc }
limit: $limit
) {
id
label
image
type
}
}
`

const data = await client.request(query, {
search: `%${searchTerm}%`,
limit
})

return data.accounts
}

Paginated Account List​

async function getAccountsPaginated(page: number, pageSize: number = 20) {
const query = `
query GetAccountsPaginated($limit: Int!, $offset: Int!) {
accounts(
order_by: { created_at: desc }
limit: $limit
offset: $offset
) {
id
label
image
type
created_at
}
accounts_aggregate {
aggregate {
count
}
}
}
`

const data = await client.request(query, {
limit: pageSize,
offset: (page - 1) * pageSize
})

return {
accounts: data.accounts,
total: data.accounts_aggregate.aggregate.count,
page,
pageSize,
totalPages: Math.ceil(data.accounts_aggregate.aggregate.count / pageSize)
}
}

Filtering Options​

By Type​

# Only AtomWallet accounts
accounts(where: { type: { _eq: "AtomWallet" } })

# Exclude protocol vaults
accounts(where: { type: { _neq: "ProtocolVault" } })

By Label​

# Case-insensitive search
accounts(where: { label: { _ilike: "%vitalik%" } })

# Exact match
accounts(where: { label: { _eq: "vitalik.eth" } })

By Date​

# Accounts created after date
accounts(where: {
created_at: { _gte: "2024-01-01T00:00:00Z" }
})

Best Practices​

  1. Use pagination - Always limit results for large datasets
  2. Include aggregate - Get total count for pagination UI
  3. Use indexes - Filter by indexed fields (type, created_at)
  4. Case-insensitive search - Use _ilike for label searches