Subgraph Interactions
Toucan SDK offers a lot of pre-defined queries. Try them out! In case you don't find what you are looking for, you can also create a custom query.
The
fetchTokenPriceOnDex
function fetches the price of a token on a DEX (decentralized exchange).function fetchTokenPriceOnDex(pool: PoolSymbol): Promise<TokenPrice>;
Name | Type | Description |
---|---|---|
pool | PoolSymbol | The pool token to fetch the price for, e.g. "NCT". |
The
fetchUserBatches
function fetches the batches of a user. It returns an array of BatchTokens (they contain different properties of the Batch)function fetchUserBatches(walletAddress: string): Promise<Batch[]>;
Name | Type | Description |
---|---|---|
walletAddress | string | The address of the user to fetch batches for . |
The
fetchTCO2TokenById
function fetches the TCO2 token by its ID. It returns a TCO2 Detail object with properties of the TCO2 (name, address, etc).function fetchTCO2TokenById(id: number): Promise<TCO2Token | undefined>;
Name | Type | Description |
---|---|---|
id | number | ID of the TCO2 to query for; the id happens to be the same as the address e.g.: "0x004090eef602e024b2a6cb7f0c1edda992382994" |
The
fetchTCO2TokenByFullSymbol
function fetches properties of a TCO2 by its full symbol. It returns a TCO2Detail object with properties of the TCO2 (name, address, etc).function fetchTCO2TokenByFullSymbol(
symbol: string
): Promise<TCO2Token | undefined>;
Name | Type | Description |
---|---|---|
fullSymbol | string | Full symbol of the TCO2 token to be fetched, e.g.: "TCO2-VCS-1718-2013". |
The
fetchAllTCO2Tokens
function fetches TCO2 Details of all TCO2 tokens. It returns array of TCO2 Detail objects with properties of the TCO2s (name, address, etc).function fetchAllTCO2Tokens(): Promise<TCO2Token[]>;
The
fetchBridgedBatchTokens
function fetches data about BatchTokens that have been bridged. It returns an array of BatchTokens containing different properties like id, serialNumber or quantity.function fetchBridgedBatchTokens(): Promise<BridgedBatchToken[]>;
The
fetchUserRetirements
function fetches all retirements made by a user. It returns an array of objects containing properties of the retirements like id, creationTx, amount and more.function fetchUserRetirements(
walletAddress,
first = 100,
skip = 0
): Promise<Retirement[]>;
Name | Type | Description |
---|---|---|
walletAddress | string | The address of the user to fetch retirements. |
first | number | How many retirements you want fetched; defaults to 100. |
skip | number | How many (if any) retirements you want skipped; defaults to 0. |
The
fetchRedeems
function fetches redeems of a given pool. It returns an array of objects with properties of the redeems like id, amount, timestamp and more.function fetchRedeems(
pool: PoolSymbol,
first = 100,
skip = 0
): Promise<RedeemEvent[]>;
Name | Type | Description |
---|---|---|
pool | PoolSymbol | The pool token to fetch the price for (e.g. "NCT"). |
first | number | How many redeems you want fetched; defaults to 100. |
skip | number | How many (if any) redeems you want skipped; defaults to . |
The
fetchUserRedeems
function fetches all redeems of a given pool of a specific user. It returns an array of objects with properties of the redeems like id, amount, timestamp and more.function fetchUserRedeems(
walletAddress: string,
pool: PoolSymbol,
first = 100,
skip = 0
): Promise<RedeemEvent[]>;
Name | Type | Description |
---|---|---|
walletAddress | string | The address of the user to query for. |
pool | PoolSymbol | The pool token to fetch the user redeems for (e.g. "NCT"). |
first | number | How many redeems you want fetched; defaults to 100. |
skip | number | How many (if any) redeems you want skipped; defaults to . |
Promise<RedeemEvent[]>
: An array of all redeem events for the specified user.The
fetchPoolContents
function fetches TCO2 tokens that are part of the given pool. It returns an array of objects representing TCO2 tokens and containing properties like name, amount, methodology and more.function fetchPoolContents(
pool: PoolSymbol,
first = 1000,
skip = 0
): Promise<PoolContent[]>;
Name | Type | Description |
---|---|---|
pool | PoolSymbol | The pool token to fetch the content for (e.g. "NCT"). |
first | number | How many TCO2 tokens you want fetched; defaults to 100. |
skip | number | How many (if any) TCO2 tokens you want skipped; defaults to . |
The
fetchProjectById
function fetches the Toucan project by its ID. It returns an object with properties of the Project like projectId, region, standard and more.function fetchProjectById(id: string): Promise<Project | undefined>;
Name | Type | Description |
---|---|---|
id | string | ID of the project to be fetched, e.g.: "10". |
The
fetchAggregations
function fetches all aggregations (including, for example, tco2TotalRetired or totalCarbonBridged). It returns an array of Aggregation objects containing properties like id, key, value.function fetchAggregations(): Promise<Aggregation[]>;
RegistryContract
: The registry contract instance.In case you don't find what you are looking for in the pre-build queries, you can create your own with the
fetchCustomQuery
method.This allows you to fetch with your own queries and can be very powerful if you know graphQL. You can also check out a lot of example queries in our subgraph playgrounds.
import { gql } from "@urql/core";
const query = gql`
query ($id: String) {
project(id: $id) {
projectId
region
standard
methodology
vintages {
id
}
}
}
`;
const result = await toucan.fetchCustomQuery(query, { id: "1" });
Last modified 2d ago