These are a couple of common GraphQL queries. Try them out here.
Get a token with its current price, including active listings, active offers, and holders.
query getToken($fa2Address: String!, $tokenId: String!) {
tokens_by_pk(fa2_address: $fa2Address, token_id: $tokenId) {
name
description
artist_address
price
offers(where: {status: {_eq: "active"}}, order_by: {price: desc}) {
type
contract_address
price
buyer_address
}
listings(where: {status: {_eq: "active"}}, order_by: {price: asc}) {
type
contract_address
amount_left
price
seller_address
}
holdings(where: {amount: {_gt: "0"}}) {
holder_address
amount
}
}
}
List all tokens owned by a Tezos account, ordered by the time they were received.
query getHoldings($holderAddress: String!) {
holdings(where: {holder_address: {_eq: $holderAddress}, amount: {_gt: "0"}}, order_by: {last_received_at: desc}) {
amount
last_received_at
token {
token_id
fa2_address
name
description
price
}
}
}
List all tokens created by a Tezos account. Note that this does not include tokens that were created through collab contracts.
query getCreations($artistAddress: String!) {
tokens(where: {artist_address: {_eq: $artistAddress }}, order_by: {minted_at: desc}) {
token_id
fa2_address
platform
name
description
price
minted_at
artifact_uri
}
}
List all tokens that were either created by a certain Tezos account or where the Tezos account is listed as a receiver of royalties. Note that this does not include tokens that were created through collab contracts.
query getCreations($artistAddress: String!) {
tokens(where: { _or: [{artist_address: {_eq: $artistAddress }}, {royalty_receivers: { receiver_address: { _eq: $artistAddress }}}] }, order_by: {minted_at: desc}) {
token_id
fa2_address
artist_address
platform
name
description
price
minted_at
artifact_uri
}
}
Show all tokens listed for sale by a Tezos account.
query getListings($sellerAddress: String!) {
listings(where: { seller_address: { _eq: $sellerAddress }, status: { _eq: "active" }}) {
type
price
amount_left
token {
token_id
fa2_address
name
description
}
}
}
List the tokens of a creator where all editions were burned.
query getBurnedCreations($artistAddress: String!) {
tokens(where: {artist_address: {_eq: $artistAddress}, burned_editions: {_gt: "0"}, editions: {_eq: "0"}}) {
token_id
fa2_address
platform
name
description
editions
burned_editions
}
}
List all tokens owned by a Tezos account that had at least one sale since the beginning of 2023.
query getTokensWithRecentSale($holderAddress: String!) {
holdings(where: {holder_address: {_eq: $holderAddress}, amount: {_gt: "0"}, token: {last_sale_at: {_gte: "2023-01-01" }}}, order_by: {last_received_at: desc}) {
amount
last_received_at
token {
token_id
fa2_address
name
description
price
last_sale_at
last_sales_price
}
}
}
List all tokens owned by a Tezos account that are now listed at least 50% under the price they were last sold for.
query getTokensThatDroppedInValue($holderAddress: String!) {
holdings(where: {holder_address: {_eq: $holderAddress}, amount: {_gt: "0"}, token: {current_price_to_last_sales_price_pct: { _lt: "-50" }}}, order_by: {token: {current_price_to_last_sales_price_pct: asc}}) {
amount
last_received_at
token {
token_id
fa2_address
name
description
price
last_sales_price
current_price_to_last_sales_price_pct
}
}
}
List all tokens in a fxhash collection.
query getFxhashCollection($fxIssuerId: bigint!) {
tokens(where: {fx_issuer_id: {_eq: $fxIssuerId }}, order_by: {minted_at: desc}) {
token_id
fa2_address
platform
name
description
price
minted_at
artifact_uri
fx_issuer_id
}
}
Get the 10 tokens of a contract with the most total sales volume.
query getTokensWithMostVolume($fa2Address: String!) {
tokens(where: {fa2_address: {_eq: $fa2Address}}, order_by: {sales_volume: desc}, limit: 10) {
token_id
fa2_address
platform
name
description
price
minted_at
artifact_uri
sales_volume
sales_count
}
}
Get the cheapest price (floor price) of all tokens in a contract.
query getFloorPrice($fa2Address: String!) {
tokens_aggregate(where: {fa2_address: {_eq: $fa2Address}, price: {_is_null: false}}) {
aggregate {
min {
price
}
}
}
}
Get the raw metadata of a token.
query getMetadataOfToken($fa2Address: String!, $tokenId: String!) {
tokens_by_pk(fa2_address: $fa2Address, token_id: $tokenId) {
metadata {
data
}
}
}
Get tokens that have a certain tag.
query getTokensWithTag($tag: String!) {
tokens(where: {tags: {tag: {_eq: $tag}}}, limit: 10) {
token_id
fa2_address
name
description
tags {
tag
}
}
}
Show the balance history of a token (who owned how many editions at which time).
query getTokenBalanceHistory($fa2Address: String!, $tokenId: String!) {
events(where: {fa2_address: {_eq: $fa2Address}, token_id: {_eq: $tokenId}, type: {_eq: "SET_LEDGER"}}, order_by: {opid: asc}) {
type
level
timestamp
fa2_address
token_id
is_mint
holder_address
amount
}
}
List the 100 most recent sales.
query getRecentSales {
events(where: {implements: {_eq: "SALE"}}, order_by: {opid: desc}, limit: 100) {
type
timestamp
seller_address
buyer_address
price
token {
fa2_address
token_id
name
description
}
}
}
List all sales of a Tezos account.
query getSales($sellerAddress: String!) {
events(where: {implements: {_eq: "SALE"}, seller_address: { _eq: $sellerAddress }}, order_by: {timestamp: asc}) {
type
timestamp
seller_address
buyer_address
price
token {
fa2_address
token_id
name
description
}
}
}
Show the total volume sold by a Tezos account and the number of sales.
query getSaleStats($sellerAddress: String!) {
events_aggregate(where: {implements: {_eq: "SALE"}, seller_address: { _eq: $sellerAddress }}) {
aggregate {
sum {
price
}
count
}
}
}
Show the sales volume and the number of sales of all tokens in a contract, in one month.
query getSalesVolume($fa2Address: String!) {
events_aggregate(where: {implements: {_eq: "SALE"}, fa2_address: { _eq: $fa2Address }, timestamp: {_gte: "2023-01-01", _lt: "2023-02-01"}}) {
aggregate {
sum {
price
}
count
}
}
}
List all sales of all tokens created by a certain Tezos account. For performance reasons, it’s recommended to split this up into two queries. In the first query, you fetch all tokens that were created by an account. In the second query, you then fetch the sale events of those tokens, by creating an or-condition with the contract addresses and the token ids.
query getCreations($artistAddress: String!) {
tokens(where: {artist_address: {_eq: $artistAddress }}) {
fa2_address
token_id
}
}
query getSales {
events(where: {
implements: { _eq: "SALE" },
_or: [
{ fa2_address: { _eq: "KT1EMg1HWiDRsA6K6zXfrxaWPKFkwpFifQgW" }, token_id: { _eq: "1" } },
{ fa2_address: { _eq: "KT1EMg1HWiDRsA6K6zXfrxaWPKFkwpFifQgW" }, token_id: { _eq: "2" } },
{ fa2_address: { _eq: "KT1EMg1HWiDRsA6K6zXfrxaWPKFkwpFifQgW" }, token_id: { _eq: "3" } },
{ fa2_address: { _eq: "KT1EMg1HWiDRsA6K6zXfrxaWPKFkwpFifQgW" }, token_id: { _eq: "4" } },
]
}) {
type
timestamp
seller_address
buyer_address
price
token {
fa2_address
token_id
name
description
}
}
}