diff --git a/src/RpcClient.ts b/src/RpcClient.ts index 8d8d2a0..f5ac238 100644 --- a/src/RpcClient.ts +++ b/src/RpcClient.ts @@ -398,4 +398,29 @@ export class RpcClient { throw new Error(`Error in getSignaturesForAsset: ${error}`); } } + + /** + * Get information about all token accounts for a specific mint or a specific owner + * @returns {Promise} + * @throws {Error} + */ + async getTokenAccounts( + params: DAS.GetTokenAccountsRequest + ): Promise { + try { + const url = `${this.connection.rpcEndpoint}`; + const response = await axios.post(url, { + jsonrpc: "2.0", + id: this.id, + method: "getTokenAccounts", + params: params, + }, { + headers: { "Content-Type": "application/json" }, + }); + + return response.data.result as DAS.GetTokenAccountsResponse; + } catch (error) { + throw new Error(`Error in getTokenAccounts: ${error}`) + } + } } diff --git a/src/types/das-types.ts b/src/types/das-types.ts index 81f512e..0652fc1 100644 --- a/src/types/das-types.ts +++ b/src/types/das-types.ts @@ -292,5 +292,36 @@ export interface SearchAssetsRequest { seq: number; leaf_id: number; } + + // Get Token Accounts + export interface TokenAccounts { + address?: string; + mint?: string; + owner?: string; + amount?: number; + delegated_amount?: number; + frozen?: boolean; + } + + export interface GetTokenAccountsRequest { + mint?: string; + owner?: string; + page?: number; + limit?: number; + cursor?: string; + before?: string; + after?: string; + options?: { + showZeroBalance?: boolean; + } + } + + export interface GetTokenAccountsResponse { + total?: number; + limit?: number; + page?: number; + cursor?: string; + token_accounts?: TokenAccounts[]; + } // End of DAS }