Skip to content

Commit

Permalink
Add getTokenAccounts Method (#75)
Browse files Browse the repository at this point in the history
  • Loading branch information
0xIchigo authored Mar 29, 2024
1 parent f272772 commit b36bb6a
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 0 deletions.
25 changes: 25 additions & 0 deletions src/RpcClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<DAS.GetTokenAccountsResponse>}
* @throws {Error}
*/
async getTokenAccounts(
params: DAS.GetTokenAccountsRequest
): Promise<DAS.GetTokenAccountsResponse> {
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}`)
}
}
}
31 changes: 31 additions & 0 deletions src/types/das-types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

0 comments on commit b36bb6a

Please sign in to comment.