Reading from Network

Let's explore how data works on Lucent Network. All data is stored in accounts - think of these as unique containers that can hold either data or program code. In this guide, we'll learn to read and understand different types of accounts.

Read a Basic Account

First, let's examine the simplest type of account - your own wallet. Open this example:

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

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

// Display the account's details
console.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 changes
console.log("\nWatching for balance changes...");
const subscriptionId = pg.connection.onAccountChange(
    address,
    (updatedInfo, context) => {
        console.log("\nBalance updated!");
        console.log("New balance:", updatedInfo.lamports / 1000000000, "SOL");
    }
);

When you run this code, you'll see something like:

Understanding the output:

  • The Address is your unique identifier on Lucent Network

  • Balance shows your holdings in SOL (1 SOL = 1,000,000,000 lamports)

  • Owner (all 1's) is the System Program that manages basic accounts

  • Executable: false means this account stores data, not program code

  • Data length: 0 is normal - basic accounts only store SOL balances

Explore Token Accounts

Now let's look at something more complex - token accounts:

The output shows:

Notice how the Token Program:

  • Is executable: true because it contains program code

  • Has a large data size (133352 bytes) storing its instructions

  • Your wallet starts with no token accounts - these get created when you start using tokens

Find Program Accounts

Want to see all accounts owned by a program? Try this:

Monitor Network Activity

Real-time monitoring is crucial for responsive applications:

Run this code and you'll see:

  • Real-time balance updates when your account changes

  • Transaction confirmations as they happen

  • Network slot numbers showing when events occur

Next Steps

Now that you understand how to read different types of accounts on Lucent Network, you're ready to learn how to write data through transactions. Continue to the next section to start sending your own transactions.

Last updated