Skip to main content

SNS index canister

Advanced
Governance
Concept

Overview

The index canister fetches transactions from the ledger canister and indexes them by account. It allows to query the transactions of an account in descending order from the ledger chain, and the list of accounts that belongs to a principal. An index canister is always deployed as part of an SNS project.

This canister is useful for applications that want to show the transactions of a specific account.

Regularly (at each heartbeat), the index canister will query the transactions from the ledger canister and then build the index of known transaction per account.

Initialization

This sections explains how to deploy an index canister in isolation. When the NNS creates a new SNS for a dapp, it will automatically be deployed with an SNS index canister.

The index canister initialization requires the principal of the ICRC-1 ledger canister that should be indexed:

type InitArgs = record {
ledger_id : principal;
};

Example with dfx:

dfx deploy icrc1-index --argument "(record {
ledger_id = principal \"rrkah-fqaaa-aaaaa-aaaaq-cai\"
}
)"

Usage

The provided methods are:

get_account_transactions : (GetAccountTransactionsArgs) -> (GetTransactionsResult);
  • This method returns the transactions for a given account. Transactions are returned in descending id order. Optionally, the user can specify a starting transaction id allowing to only query for transactions before this id. If no start is specified, the last transaction is used.
ledger_id : () -> (principal) query;
  • This method returns the principal of the ledger canister being indexed.
list_subaccounts : (ListSubaccountsArgs) -> (vec SubAccount) query;
  • This method lists all indexed subaccounts for a principal.

Candid reference file

Please check the Candid file of the index canister for the interface details.