Hello World
The shortest path from zero to a transaction running inside a NorthStar session. Five steps; ~30 lines of code.
What we're going to build
Open a session, transfer SOL between two accounts inside the ER, settle back. Nothing fancy — but every step that matters is in there: session lifecycle, account delegation, ER-side execution, atomic settle-back.
Setup
import { NorthStarSDK } from "@sonicsvm/northstar-sdk";
import {
Connection,
Keypair,
PublicKey,
SystemProgram,
Transaction,
} from "@solana/web3.js";
const PORTAL = new PublicKey("74iiMCqFw1afWyp3tdh9pUqfRfCRq7gfdC2YZoNGpovt");
const L1_RPC = new Connection("https://api.devnet.sonic.game", "confirmed");
const ER_RPC = new Connection("https://ephemeral.devnet.sonic.game", "confirmed");
const sdk = new NorthStarSDK({
portalProgramId: PORTAL,
customEndpoints: { solana: L1_RPC, ephemeralRollup: ER_RPC },
});
const owner = Keypair.generate();
const recipient = Keypair.generate();
// Fund the owner — devnet faucet, ~5 SOL is comfortable for the session.
// In your dev workflow, prefer the deploy payer at ~/.config/solana/id.json.Step 1: Open a session
The Portal program creates a session PDA derived from (portal, owner, gridId). From here, anything you delegate to this session is locked on L1 and writable on the ER.
Step 2: Delegate the recipient account
The Portal records that recipient is now bound to this session. After this returns, the account is read-only on L1 and writable inside the ER.
Step 3: Run the transaction inside the ER
Same SystemProgram.transfer instruction you'd send to L1 — different RPC. The ER processes it locally; confirmation lands in milliseconds (see Real-time confirmation).
Step 4: Settle back
CloseSession undelegates every account bound to this session in one atomic step. Recipient's new balance shows up on L1.
Step 5: Verify
What just happened
Five operations, two RPCs, one Transfer ix that runs identically to how it would on L1.
Where to go from here
Recipes — patterns for agents, oracles, orderbooks.
Concepts: sessions — the formal model.
Migrate to NorthStar — for an existing Solana program.
Last updated
