CARV
CARVPlayPortalProtocol
  • Overview
    • Introducing CARV
  • SVM - AI AGENTIC CHAIN
    • Introduction
      • Architecture
      • AI Agent in TEE environment
      • CARV Verifier Nodes
    • Quick Start
      • Bridge Token
      • Explorer
      • Command line tool
      • Reading from CARV SVM Network
      • Writing to the Network
      • Network Info
  • D.A.T.A. - AI FRAMEWORK
    • Introduction
      • DeepSeek Integration
      • D.A.T.A's Core Features
      • How It Empowers AI Agents
      • Driving the Future of AI and Blockchain
      • Leveraging CARV SVM Chain for Privacy and Trustless Data Sharing
    • Quick Start Guide
    • Architecture
    • ERC-7231 (CARV ID)
    • Examples
      • On-Chain Insights
    • Getting Started
      • D.A.T.A Framework Plugin for Eliza
    • Use Cases and Implementation
      • Getting On-Chain Data for AI Agents
      • What's Coming with the D.A.T.A Framework
    • API Documentation
      • News
      • On-chain Data SQL Query
        • Ethereum Schema
        • Bitcoin Schema
        • Base Schema
        • Solana Schema
      • On-chain Data SQL Query by LLM
      • Token Info and Price
      • User Balance by Twitter ID
      • User Balance by Discord ID
  • CARV Ecosystem
    • CARV Play
      • Portal Access
      • Integration Guide
        • .Play Name Service Integration
        • API-Verified Quest (RESTFUL)
        • API-Verified Quest (GraphQL)
        • CARV ID OAuth 2.0
        • CARV ID Telegram SDK
      • Smart Contracts & Security
    • MOFF Bot & Customer Data Platform
    • CARV Account
      • ERC 7231
    • Verifier Nodes
      • How to Purchase Nodes
      • Buyback Program
      • Why Verifier Nodes
      • How do Verifier Nodes Work
        • CARV/veCARV Token
        • CARV Vault
        • CARV NFT License
        • CARV Protocol Service
        • Trusted Execution Environment (TEE)
        • Verifier Node
        • Attestation
        • Delegation
        • Rewards
        • SGX Attestation Verification
      • Verifier Node Sale Dynamics
      • Smart Contract Addresses
      • License Key (NFT)
      • Delegation
      • Node Rewards
      • Join Mainnet Verifier Nodes
        • Prerequisites
        • Delegation Tutorial
        • Operating a Verifier Node
          • Running in VPS
          • Running in CLI
            • Using Source Code
            • Using Docker
            • Gasless Server API
          • Running in Desktop App
      • Explorer
      • FAQ
        • Node Sale
        • Node Operation
  • CARV LABS
    • Introduction
    • Working with CARV Labs
  • Tokenomics
    • Utility
      • veCARV(s)
    • Distribution & Vesting
  • DECENTRALIZED GOVERNANCE
    • ⚔️Universal Guardian Program
    • 📔DAO Governance
    • 🌏Community Programs & Activities
  • Resources
    • 🗜️Writings
    • 🗞️CARV in the News
    • 🫶Social & Community Links
    • 🅰️Brand Guideline
    • 💰Job Openings
Powered by GitBook
On this page
  • Read a Basic Account
  • Explore Token Accounts
  1. SVM - AI AGENTIC CHAIN
  2. Quick Start

Reading from CARV SVM Network

PreviousCommand line toolNextWriting to the Network

Last updated 2 months ago

Let’s dive into how data operates on the CARV SVM Network. On CARV SVM, all data is organized within accounts—unique containers that store either data or program code. This guide will walk you through understanding and accessing the various types of accounts.

Read a Basic Account

Let’s start with the simplest type of account on the CARV SVM Chain—your wallet. Open the following example and connect to the CARV SVM Chain using the RPC endpoint :

// Connect to CARV SVM Chain's RPC endpointconst rpcUrl = "https://rpc.testnet.carv.io/rpc";
const connection = new pg.Connection(rpcUrl);

// Get your wallet's public key - this is your account's addressconst address = pg.wallet.publicKey;

// Fetch the account's information from the networkconst accountInfo = await connection.getAccountInfo(address);

// Display the account's detailsconsole.log("Your Wallet Account Info:");
console.log("======================");
console.log("Address:", address.toBase58());
console.log("Balance:", accountInfo.lamports / 1000000000, "SOL");
console.log("Owner:", accountInfo.owner.toBase58());
console.log("Executable:", accountInfo.executable);
console.log("Data length:", accountInfo.data.length);

// Set up a listener for account changesconsole.log("\nWatching for balance changes...");
const subscriptionId = connection.onAccountChange(
    address,(updatedInfo, context) => {console.log("\nBalance updated!");console.log("New balance:", updatedInfo.lamports / 1000000000, "SOL");
    }
);

Example Output:

Your Wallet Account Info:
======================
Address: ATxydRH5uT8xivYQGH7e6KgFNkPvEn7UKMmABtFpgNkz
Balance: 1 SOL
Owner: 11111111111111111111111111111111Executable: falseData length: 0

Understanding the Output:

  • Address: Your unique identifier on the CARV SVM Chain.

  • Balance: Displays holdings in SOL (1 SOL = 1,000,000,000 lamports).

  • Owner: All 1s represent the System Program, which manages basic accounts.

  • Executable: false indicates this account stores data, not code.

  • Data length: 0 is standard for accounts holding only SOL balances.

Explore Token Accounts

Now, let’s examine token accounts on the CARV SVM Chain:

import { TOKEN_PROGRAM_ID } from "@solana/spl-token";

// Fetch information about the Token Programconsole.log("Token Program Info:");
console.log("=================");
const tokenProgramInfo = await connection.getAccountInfo(TOKEN_PROGRAM_ID);
console.log("Is executable:", tokenProgramInfo.executable);
console.log("Data length:", tokenProgramInfo.data.length);

// Fetch all token accounts owned by your walletconsole.log("\nYour Token Accounts:");
console.log("==================");
const tokenAccounts = await connection.getTokenAccountsByOwner(
    pg.wallet.publicKey,
    { programId: TOKEN_PROGRAM_ID }
);

if (tokenAccounts.value.length === 0) {console.log("No token accounts found - try creating one first!");
} else {
    tokenAccounts.value.forEach((account, i) => {console.log(`\nToken Account ${i + 1}:`);console.log("Address:", account.pubkey.toBase58());console.log("Data size:", account.account.data.length);
    });
}

Example Output:

Token Program Info:
=================
Is executable: true
Data length: 133352

Your Token Accounts:
==================
No token accounts found - try creating one first!

Understanding the Output:

  • Token Program:

    • Is executable: true because it contains the program code.

    • Data length: Indicates the size of program instructions.

  • Token Accounts:

    • Lists all token accounts owned by your wallet.

    • If none are found, you'll need to create one first.


Find Program Accounts

You can also query all accounts owned by a specific program on the CARV SVM Chain:

import { TOKEN_PROGRAM_ID } from "@solana/spl-token";
import { PublicKey } from "@solana/web3.js";

async function scanProgramAccounts(programId) {
    console.log(`Scanning accounts owned by program: ${programId.toString()}`);
    console.log("==========================================");
    const accounts = await connection.getProgramAccounts(programId, {
        dataSlice: { offset: 0, length: 0 }, filters: []
    });
    console.log(`Found ${accounts.length} accounts\n`);
    accounts.slice(0, 5).forEach((account, i) => {
        console.log(`Account ${i + 1}:`); 
        console.log("Address:", account.pubkey.toBase58()); 
        console.log("Balance:", account.account.lamports / 1000000000, "SOL"); 
        console.log("Data length:", account.account.data.length); console.log("-------------------");
    });
}

// Look at Token Program accountsawait scanProgramAccounts(TOKEN_PROGRAM_ID);

Example Output:

  • Accounts Owned: Displays the number of accounts a program owns.

  • Account Details: Shows their addresses, balances, and data sizes.


Monitor Network Activity

Real-time monitoring is essential for responsive applications. Use the following code to track changes in account balances and transactions:

console.log("Starting transaction and account monitoring...");
console.log("============================================");

// Watch for account balance changes
const accountSub = connection.onAccountChange(
    pg.wallet.publicKey, (accountInfo, context) => {
        console.log("\nAccount Updated!");
        console.log("New balance:", accountInfo.lamports / 1000000000, "SOL");
        console.log("Slot:", context.slot);
    }
);

// Watch for transaction confirmations
const signatureSub = connection.onSignature(
    await connection.requestAirdrop(pg.wallet.publicKey, 1000000000), (signatureResult, context) => {
        console.log("\nTransaction Confirmed!");
        console.log("Signature:", signatureResult);
        console.log("Slot:", context.slot);
    }
);

console.log("Monitoring active - try requesting an airdrop to see updates!");

Example Output:

  • Real-time balance updates when account changes occur.

  • Transaction confirmations with signature and slot details.


Next Steps

Now that you understand how to read and monitor accounts on the CARV SVM Chain, you're ready to explore writing data through transactions. Continue to the next section to start deploying your own projects on the network.

https://rpc.testnet.carv.io/rpc