Skip to main content
Glama
buildwithgrove

Grove's MCP Server for Pocket Network

get_solana_balance

Retrieve SOL token balance for any Solana address on mainnet or testnet networks using Grove's blockchain data access.

Instructions

Get SOL balance for a Solana address

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
addressYesSolana address
networkNoNetwork type (defaults to mainnet)

Implementation Reference

  • Handler execution logic for the 'get_solana_balance' tool within the handleSolanaTool switch statement, which extracts input parameters, calls SolanaService.getBalance, and formats the response.
    case 'get_solana_balance': {
      const address = args?.address as string;
      const network = (args?.network as 'mainnet' | 'testnet') || 'mainnet';
    
      const result = await solanaService.getBalance(address, network);
    
      return {
        content: [
          {
            type: 'text',
            text: JSON.stringify(result, null, 2),
          },
        ],
        isError: !result.success,
      };
    }
  • Tool registration definition for 'get_solana_balance', returned by registerSolanaHandlers and included in the server's tools list.
    {
      name: 'get_solana_balance',
      description: 'Get SOL balance for a Solana address',
      inputSchema: {
        type: 'object',
        properties: {
          address: {
            type: 'string',
            description: 'Solana address',
          },
          network: {
            type: 'string',
            enum: ['mainnet', 'testnet'],
            description: 'Network type (defaults to mainnet)',
          },
        },
        required: ['address'],
      },
    },
  • Core implementation in SolanaService.getBalance: retrieves Solana RPC service, calls 'getBalance' RPC method, converts lamports to SOL, and returns formatted response.
    async getBalance(
      address: string,
      network: 'mainnet' | 'testnet' = 'mainnet'
    ): Promise<EndpointResponse> {
      const service = this.blockchainService.getServiceByBlockchain('solana', network);
    
      if (!service) {
        return {
          success: false,
          error: `Solana service not found for ${network}`,
        };
      }
    
      const result = await this.blockchainService.callRPCMethod(
        service.id,
        'getBalance',
        [address]
      );
    
      if (result.success && result.data?.value !== undefined) {
        const lamports = result.data.value;
        const sol = lamports / 1e9; // 1 SOL = 1 billion lamports
    
        return {
          success: true,
          data: {
            address,
            lamports,
            sol,
          },
          metadata: result.metadata,
        };
      }
    
      return result;
    }

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/buildwithgrove/mcp-pocket'

If you have feedback or need assistance with the MCP directory API, please join our Discord server