getAccountInfo
Retrieve detailed account information for any Solana address, including balance and data, using specified encoding formats like base58, base64, or jsonParsed.
Instructions
Get detailed account information for a Solana address
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| address | Yes | Solana account address | |
| encoding | No | Data encoding format |
Input Schema (JSON Schema)
{
"$schema": "http://json-schema.org/draft-07/schema#",
"additionalProperties": false,
"properties": {
"address": {
"description": "Solana account address",
"type": "string"
},
"encoding": {
"description": "Data encoding format",
"enum": [
"base58",
"base64",
"jsonParsed"
],
"type": "string"
}
},
"required": [
"address"
],
"type": "object"
}
Implementation Reference
- src/index.ts:149-204 (handler)Handler function that executes the getAccountInfo tool: validates input, calls Solana RPC getAccountInfo, formats data based on encoding (base58/base64), and returns formatted account details or error.async ({ address, encoding = 'base64' }) => { try { const publicKey = new PublicKey(address); const accountInfo = await connection.getAccountInfo( publicKey, 'confirmed' ); if (!accountInfo) { return { content: [ { type: "text", text: `No account found for address: ${address}`, }, ], }; } // Format the data based on encoding let formattedData: string; if (encoding === 'base58') { formattedData = bs58.encode(accountInfo.data); } else if (encoding === 'base64') { formattedData = Buffer.from(accountInfo.data).toString('base64'); } else { // For jsonParsed, we'll still return base64 but note that it's not parsed formattedData = Buffer.from(accountInfo.data).toString('base64'); } return { content: [ { type: "text", text: `Account Information for ${address}: Lamports: ${accountInfo.lamports} (${accountInfo.lamports / LAMPORTS_PER_SOL} SOL) Owner: ${accountInfo.owner.toBase58()} Executable: ${accountInfo.executable} Rent Epoch: ${accountInfo.rentEpoch} Data Length: ${accountInfo.data.length} bytes Data (${encoding}): ${formattedData}`, }, ], }; } catch (err) { const error = err as Error; return { content: [ { type: "text", text: `Failed to retrieve account information: ${error.message}`, }, ], }; } }
- src/index.ts:145-148 (schema)Zod input schema defining parameters for the getAccountInfo tool: required address (string) and optional encoding (enum: base58, base64, jsonParsed).{ address: z.string().describe("Solana account address"), encoding: z.enum(['base58', 'base64', 'jsonParsed']).optional().describe("Data encoding format"), },
- src/index.ts:142-205 (registration)Registration of the getAccountInfo tool using server.tool(), including name, description, schema, and handler function.server.tool( "getAccountInfo", "Get detailed account information for a Solana address", { address: z.string().describe("Solana account address"), encoding: z.enum(['base58', 'base64', 'jsonParsed']).optional().describe("Data encoding format"), }, async ({ address, encoding = 'base64' }) => { try { const publicKey = new PublicKey(address); const accountInfo = await connection.getAccountInfo( publicKey, 'confirmed' ); if (!accountInfo) { return { content: [ { type: "text", text: `No account found for address: ${address}`, }, ], }; } // Format the data based on encoding let formattedData: string; if (encoding === 'base58') { formattedData = bs58.encode(accountInfo.data); } else if (encoding === 'base64') { formattedData = Buffer.from(accountInfo.data).toString('base64'); } else { // For jsonParsed, we'll still return base64 but note that it's not parsed formattedData = Buffer.from(accountInfo.data).toString('base64'); } return { content: [ { type: "text", text: `Account Information for ${address}: Lamports: ${accountInfo.lamports} (${accountInfo.lamports / LAMPORTS_PER_SOL} SOL) Owner: ${accountInfo.owner.toBase58()} Executable: ${accountInfo.executable} Rent Epoch: ${accountInfo.rentEpoch} Data Length: ${accountInfo.data.length} bytes Data (${encoding}): ${formattedData}`, }, ], }; } catch (err) { const error = err as Error; return { content: [ { type: "text", text: `Failed to retrieve account information: ${error.message}`, }, ], }; } } );