Lucent Network Documentation
  • Overview
    • Introducing Lucent Network
  • Lucent Network Upgrade
    • Setting up a Solana Wallet
  • Upgrading $CLV to $LUX
  • Network Upgrade Portal FAQ
  • Support for Coinbase Wallet
  • Core Technology
    • SVM Architecture
    • AI Infrastructure
  • USING LUCENT
    • RPC Setup
    • Reading from Network
    • Writing to Network
    • Network Information
    • Wallet
    • Explorer
    • Agent Interaction
  • ECONOMICS
    • Tokenomics
  • DECENTRALIZED AUTONOMOUS ORGANIZATION
    • Governance
  • Community & Support
    • Link
Powered by GitBook
On this page
  • Transfer SOL
  • Create a Token
  • Understand Transaction Confirmations
  • Next Steps
  1. USING LUCENT

Writing to Network

Now that we understand how to read data from the Lucent Network, let's learn how to write data to it. We interact with the Lucent network by sending transactions made up of instructions. These transactions benefit from Lucent's Layer 2 architecture, offering faster finality and lower costs while maintaining Ethereum's security guarantees.

Let's walk through how to transfer SOL to understand how transactions work on the Network.

Transfer SOL

First, let's send a simple SOL transfer from your wallet to another account. This requires invoking the transfer instruction on the System Program:

import {
    LAMPORTS_PER_SOL,
    SystemProgram,
    Transaction,
    sendAndConfirmTransaction,
    Keypair,
} from "@solana/web3.js";

// Get our sender's keypair from the playground wallet
const sender = pg.wallet.keypair;

// Generate a new keypair for the receiver
const receiver = new Keypair();

// Create the transfer instruction
const transferInstruction = SystemProgram.transfer({
    fromPubkey: sender.publicKey,
    toPubkey: receiver.publicKey,
    lamports: 0.01 * LAMPORTS_PER_SOL,  // Transfer 0.01 SOL
});

// Add the instruction to a new transaction
const transaction = new Transaction().add(transferInstruction);

// Send and confirm the transaction
const transactionSignature = await sendAndConfirmTransaction(
    pg.connection,
    transaction,
    [sender],
);

// Log the transaction URL
console.log(
    "Transaction Signature:",
    `https://explorer.fc.devnet.soo.network/tx/${transactionSignature}`
);

This code demonstrates several key concepts:

  • Creating an instruction (the transfer)

  • Building a transaction from that instruction

  • Sending and confirming the transaction

  • Using explorer to verify the result

When you run this code, you'll see the transaction signature and a link to view it in the explorer. Click the link to see details about your transaction, including its rapid confirmation time - a benefit of Layer 2 architecture.

Create a Token

Now let's try something more complex - creating a new token. This requires multiple instructions working together:

import {
    MINT_SIZE,
    TOKEN_2022_PROGRAM_ID,
    createInitializeMint2Instruction,
    getMinimumBalanceForRentExemptMint,
} from "@solana/spl-token";

// Generate a new keypair for the mint account
const mint = new Keypair();

// Calculate rent-exempt balance for mint account
const rentLamports = await getMinimumBalanceForRentExemptMint(pg.connection);

// Create instruction for new account
const createAccountInstruction = SystemProgram.createAccount({
    fromPubkey: pg.wallet.publicKey,
    newAccountPubkey: mint.publicKey,
    space: MINT_SIZE,
    lamports: rentLamports,
    programId: TOKEN_2022_PROGRAM_ID,
});

// Create instruction to initialize the mint
const initializeMintInstruction = createInitializeMint2Instruction(
    mint.publicKey,     // mint account
    2,                  // decimals
    pg.wallet.publicKey, // mint authority
    pg.wallet.publicKey, // freeze authority
    TOKEN_2022_PROGRAM_ID
);

// Combine both instructions into one transaction
const transaction = new Transaction().add(
    createAccountInstruction,
    initializeMintInstruction
);

// Send and confirm the transaction
const transactionSignature = await sendAndConfirmTransaction(
    pg.connection,
    transaction,
    [pg.wallet.keypair, mint]  // Both keypairs needed
);

console.log(
    "\nTransaction Signature:",
    `https://explorer.fc.devnet.soo.network/tx/${transactionSignature}`
);

console.log(
    "\nMint Account:",
    `https://explorer.fc.devnet.soo.network/address/${mint.publicKey}`
);

This example shows how to:

  • Calculate space and rent for a new account

  • Create and initialize a mint account

  • Combine multiple instructions in one transaction

  • Sign with multiple keypairs

When you run the code, you'll get two links:

  • One for the transaction details

  • One for the newly created mint account

Understand Transaction Confirmations

Transactions confirm quickly thanks to Layer 2 architecture, but they inherit Ethereum's security through rollup design. When you see "confirmed" status, it means:

  • The transaction has been processed by the network

  • The transaction is included in a rollup batch

  • The transaction data is available for verification

This gives you both speed and security - fast confirmations backed by Ethereum's consensus.

Next Steps

Now that you understand how to write data to the Network through transactions, you're ready to:

  • Deploy your own programs

  • Create more complex transactions

  • Build applications that leverage Layer 2 performance

PreviousReading from NetworkNextNetwork Information

Last updated 4 months ago