Let’s explore how data works on SOON Network. All data on SOON 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 in Solana Playground:
// 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:
Your Wallet Account Info:
======================
Address: ATxydRH5uT8xivYQGH7e6KgFNkPvEn7UKMmABtFpgNkz
Balance: 1 SOL
Owner: 11111111111111111111111111111111
Executable: false
Data length: 0
Understanding the output:
-
The Address
is your unique identifier on SOON 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. Open this example in Solana Playground:
import { TOKEN_PROGRAM_ID } from '@solana/spl-token';
// First, let's examine the Token Program itself
console.log("Token Program Info:");
console.log("=================");
const tokenProgramInfo = await pg.connection.getAccountInfo(TOKEN_PROGRAM_ID);
console.log("Is executable:", tokenProgramInfo.executable);
console.log("Data length:", tokenProgramInfo.data.length);
// Now find all token accounts owned by your wallet
console.log("\nYour Token Accounts:");
console.log("==================");
const tokenAccounts = await pg.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);
});
}
The output shows two important things:
Token Program Info:
=================
Is executable: true
Data length: 133352
Your Token Accounts:
==================
No token accounts found - try creating one first!
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? Open this example in Solana Playground:
import { TOKEN_PROGRAM_ID } from '@solana/spl-token';
import { PublicKey } from '@solana/web3.js';
async function scanProgramAccounts(programId: PublicKey) {
// Log which program we're scanning
console.log(`Scanning accounts owned by program: ${programId.toString()}`);
console.log("==========================================");
// Find all accounts owned by this program
const accounts = await pg.connection.getProgramAccounts(programId, {
dataSlice: { offset: 0, length: 0 }, // Just get metadata for efficiency
filters: []
});
// Display the results
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 accounts
await scanProgramAccounts(TOKEN_PROGRAM_ID);
This code shows you:
-
How many accounts a program owns
-
The first few accounts’ addresses
-
Their SOL balances and data sizes
Monitor Network Activity
Real-time monitoring is crucial for responsive applications. Try this example in Solana Playground:
console.log("Starting transaction and account monitoring...");
console.log("============================================");
// Watch for account balance changes
const accountSub = pg.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 = pg.connection.onSignature(
// Request an airdrop to see this in action
await pg.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!");
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
Try requesting multiple airdrops while this runs to see how the monitoring works!
Next Steps
Now that you understand how to read different types of accounts on SOON Network, you’re ready to learn how to write data through transactions. Continue to the next section to start sending your own transactions.