Eclipse Documentation
HomeBridge
  • 🐮Users
    • Getting Started
      • 1. Set Up Your Eclipse Wallet
      • 2. Bridge Assets for Gas and Transactions
      • 3. Explore the Eclipse Ecosystem
      • 4. Engage with the Community on Discord
    • User Resources
    • tETH
    • tUSD
  • 🛠️Developers
    • Getting Started
    • Wallet
      • Mainnet Wallets
      • Testnet & Devnet Wallets
        • Adding Eclipse Wallet to dApp
        • Custom Wallets
    • RPC & Block Explorers
      • Dragon's Mouth gRPC Subscriptions
    • Bridges
      • Eclipse Canonical Bridge
      • Hyperlane
    • Oracles
      • Pyth Network
      • Switchboard
    • NFTs
      • Metaplex
      • Nifty Asset
      • Libreplex (Token-2022)
    • Developer Tooling
      • Faucet
      • Benchmarking
        • Running AMM benchmarking tests
      • Decentralized Identities
        • AllDomains
      • OpenBook Quickstart
      • Multisig
    • Eclipse Bug Bounty Program
    • Eclipse Status Page
    • Frequently Asked Questions
    • Differences Between Eclipse and Solana
    • Eclipse Program Registry Guide
  • 📖Tutorials & Guides
    • Developer Guides
      • Quick Start: "Hello World"
        • Deployment Walkthrough
      • Reading from the blockchain
      • Modifying a Solana dApp to Support Eclipse: "Chomping Glass"
        • Developing on the Solana Virtual Machine (SVM)
        • Multi-chain toggle frontend component
      • Dapp Deployment Tutorial - Eclipse Devnet
        • ⚙️Install Dependencies - Windows
          • Step 1: Install Visual Studio Code (VSC)
          • Step 2: Install Rust and Cargo
          • Step 3: Download Visual Studio C++ Build Tools
          • Step 4: Download Node.js
          • Step 5: Install Git on Windows
          • Step 6: Install the Solana CLI
          • Step 7: Install WSL on Visual Studio Code and Upgrade to WSL2
          • Step 8: Set Up Development Environment in Ubuntu WSL
          • Step 9: Install Anchor on Windows and WSL
        • 🏝️Solana CLI & Solana Keypair
          • Step 1: Set Solana CLI to Use Eclipse Devnet
          • Step 2: Verify Solana CLI Configuration
          • Step 3: Generate a New Solana Keypair
          • Step 4: Claim Devnet ETH for Transaction Fees
          • Optional Step: View Balance on Devnet Explorer
        • 🖥️Creating an Anchor Project in Visual Studio Code
          • Step 1: Initialize Anchor Project
          • Step 2: Update the lib.rs File with Smart Contract Code
          • Step 3: Update the Smart Contract's Cargo.toml File
          • Step 4: Update the Project's Root Cargo.toml File
          • Step 5: Compile Your Program with anchor build
          • Step 6: Deploy Your Project to the Eclipse Devnet
          • Step 7: Verify Program Deployment on the Eclipse Devnet Explorer
        • ✨Building a React App Front-End
          • Step 1: Create a New React Project with TypeScript
          • Step 2: Install Solana Web3.js and Wallet Adapter Dependencies
          • Step 3: Install Additional Dependencies for Enhanced Functionality and Compatibility
          • Step 4: Configure Webpack for Browser Compatibility
          • Step 5: Start the Development Server and Verify Setup
          • Step 6: Implement the UI for Your NFT Minter in App.tsx with Updated Code
      • Eclipse Testnet ETH Transfer Transaction Fee Estimator
        • Program Breakdown
        • Program JSX & CSS
        • Program Execution
      • Pyth: How to Use Real-Time Data in Solana Programs
      • Quick Start: User Guide - Testnet
      • cNFTs on Eclipse
        • Create 1 Million NFTs on Eclipse
        • How to Interact with cNFTs
  • 🧠Eclipse Architecture
    • What is Eclipse Mainnet?
      • Settlement - Ethereum
      • Execution - Solana Virtual Machine (SVM)
      • Data Availability - Celestia
      • Proving - RISC Zero
      • Why Eclipse, Why Ethereum, Why Now
    • Lifecycle of an Eclipse Transaction
  • 📚Additional Resources
    • External Documentation
    • Disclosures
Powered by GitBook
On this page
  • Sub Page - Development guide with examples
  • How to use the Solana CLI​
  • Setting up your Development Environment​
  • Creating Your First Solana Smart Contract​
  • Deploying Smart Contracts on the Solana Blockchain​
  • Interacting with Smart Contracts​
  • Advanced Smart Contract Development Techniques​
  • Testing and Debugging Smart Contracts​

Was this helpful?

Edit on GitHub
  1. Tutorials & Guides
  2. Developer Guides
  3. Modifying a Solana dApp to Support Eclipse: "Chomping Glass"

Developing on the Solana Virtual Machine (SVM)

PreviousModifying a Solana dApp to Support Eclipse: "Chomping Glass"NextMulti-chain toggle frontend component

Last updated 18 days ago

Was this helpful?

What is Solana?

Solana is a high-performance blockchain platform designed for decentralized applications (dApps) and crypto-native projects. It distinguishes itself by offering fast transaction speeds, low fees, and scalability without sacrificing decentralization. At the core of Solana uses a proof-of-stake architecture, which allows for high throughput and efficiency.

Solana Programs

In the context of Solana, a "program" refers to a smart contract or application deployed on the Solana blockchain. Solana programs are typically written in Rust or C, and they execute within the Solana Virtual Machine (SVM). Each program is associated with a specific address on the blockchain and contains the logic for handling transactions, updating state, and interacting with other programs.

Developing on Solana

Developing on Solana involves writing smart contracts or programs that run on the Solana blockchain. Unlike traditional centralized applications, Solana development requires understanding blockchain concepts such as consensus mechanisms, transaction processing, and decentralized data storage. Developers use programming languages like Rust or C to write Solana programs, and they interact with the blockchain using the Solana Command Line Tool (CLI) or specialized SDKs.

SVM vs. EVM?

Parallel Execution Capability:

The SVM executes transactions in parallel, while the EVM processes them sequentially. This parallel execution of SVM addresses gas cost issues, especially during concurrent transactions.

Mitigation of Gas Costs:

EVM's sequential processing can lead to increased gas costs for unrelated transactions due to congestion. In contrast, SVM's parallel execution ensures that highly contested applications don't impact others, mitigating the "noisy neighbor problem."

State Handling:

EVM allows unrestricted state access per transaction, potentially causing slower lookups as the rollup state expands. SVM requires specifying necessary state for each transaction, offering a more efficient approach.

Performance:

Leveraging Solana's execution engine within the Ethereum ecosystem represents a significant enhancement in scalability and performance for decentralized applications deployed on the Eclipse rollup.

How does the SVM fit into the Eclipse workflow?

Within the Eclipse workflow, transactions are processed using the Solana Virtual Machine (SVM). Unlike the traditional Ethereum rollups that rely on the Ethereum Virtual Machine (EVM), Eclipse leverages Solana's execution engine for transaction execution.

The SVM is distinguished by its capability to execute transactions in parallel, without overlapping states. This stands in contrast to the sequential processing nature of the EVM. With SVM's parallel execution, multiple transactions can occur simultaneously, addressing potential gas cost issues and enhancing overall efficiency.

SVM requires specific state specification for each transaction, ensuring efficient processing. In contrast, the EVM allows unrestricted state access per transaction, which can lead to slower processing as the rollup state expands. By mandating precise state specification, SVM optimizes transaction execution within the Eclipse workflow.

As transactions are dispatched to a sequencer within Eclipse, they are subsequently processed using SVM. The parallel execution capability of SVM contributes to the scalability and performance of the Eclipse rollup. This integration showcases the innovative potential of combining Solana's execution engine with Ethereum's ecosystem, ultimately enhancing the functionality and efficiency of decentralized applications deployed on the Eclipse platform.

Sub Page - Development guide with examples

The Solana Command Line Interface (CLI) is a powerful tool that allows developers and users to interact with the Solana blockchain. It provides a comprehensive set of commands for various tasks such as deploying smart contracts, managing accounts, and monitoring network activity. Here's a hands-on guide to using the Solana CLI:

Usage:

Once installed, you can use the Solana CLI to interact with the Solana blockchain. Here are some common commands:

Check Cluster Status:

solana cluster-version

Create a Wallet:

solana-keygen new --outfile ~/my-wallet.json

Show Account Balance:

solana balance <account_address>

Send SOL to Another Account:

solana transfer <recipient_address> <amount>

Deploy a Smart Contract:

solana deploy <program_binary>

Interact with a Smart Contract:

solana program <program_address>

View Transaction Logs:

solana logs

Before you can start developing smart contracts for SVM, you need to set up your development environment. This involves installing the necessary tools and libraries. Follow the instructions in this section to get started.

  • Install Rust and Cargo, the package manager for Rust, by following the official Rust installation guide: rustup.rs.

  • Install the Solana Command Line Tool (CLI) by following the instructions in the Solana documentation: solana.com/docs/.

  • Install the Solana SDK for Rust by adding the following dependency to your Cargo.toml file:

[dependencies]
solana-sdk = "1.9.0"
  • Initialize a new Rust project using Cargo

cargo new my_project
cd my_project
  • All set, now you can begin writing out the smart contract

In this section, you will learn how to create a simple Solana smart contract using Rust. Follow these steps to create a basic "Hello, World!" smart contract:

  • Create a new Rust file in your project directory:

touch src/lib.rs
  • Open src/lib.rs in your favorite text editor and add the following code:

#![cfg_attr(not(feature = "std"), no_std)]

use solana_program::{
    account_info::{next_account_info, AccountInfo},
    entrypoint,
    entrypoint::ProgramResult,
    msg,
    pubkey::Pubkey,
};

entrypoint!(process_instruction);

pub fn process_instruction(
    _program_id: &Pubkey,
    accounts: &[AccountInfo],
    _instruction_data: &[u8],
) -> ProgramResult {
    msg!("Hello, Solana!");
    Ok(())
}
  • Save the file and exit your text editor.

Once you've created your smart contract, the next step is to deploy it on the Solana blockchain.

Follow these steps to deploy your contract using the Solana CLI:

  • Build your smart contract:

cargo build-bpf
  • Deploy your smart contract:

solana deploy target/deploy/my_project.so

Your smart contract is now deployed on the Solana blockchain!

Now that your smart contract is deployed, you can interact with it using various tools and libraries. Here are some common ways to interact with Solana smart contracts:

  • Using the Solana CLI:

solana program call <contract_address> <instruction_data>

In this section, you will learn advanced techniques for developing smart contracts on Solana, including:

  • State management: Let us see how to use account states efficiently, minimizing storage costs and implement state transitions carefully to maintain data consistency.

pub struct MyContractState {
    pub balance: u64,
}

impl MyContractState {
    pub fn new(balance: u64) -> Self {
        Self { balance }
    }

    pub fn update_balance(&mut self, amount: u64) {
        self.balance += amount;
    }
}
  • Event handling: You can emit events from your smart contract to notify external systems about state changes or other important events.

  • Here is a simple example:

use solana_program::program::invoke;

fn emit_event() {
    // Emit event
    let event_data = vec![1, 2, 3]; // Example event data
    let event_instruction = solana_program::system_instruction::log(&event_data);
    invoke(&event_instruction, &[]).unwrap();
}
  • Error handling: You can define custom error types and handle errors gracefully in your smart contracts.

#[derive(Debug)]
pub enum MyError {
    InsufficientFunds,
    InvalidInstruction,
}

pub fn process_instruction(
    instruction_data: &[u8],
) -> Result<(), MyError> {
    if instruction_data.len() < 4 {
        return Err(MyError::InvalidInstruction);
    }

    // Check for sufficient funds
    if balance < amount {
        return Err(MyError::InsufficientFunds);
    }

    Ok(())
}
  • Gas optimization: You can optimize gas usage by batching operations and minimizing storage costs.

// gas optimization by batching operations
let mut ix_batch = Vec::new();
for (account, amount) in transfers.iter() {
    let ix = solana_program::system_instruction::transfer(source, account, *amount);
    ix_batch.push(ix);
}
let batch_instruction = solana_program::instruction::Instruction::new_batch(&ix_batch);
invoke(&batch_instruction, &[]).unwrap();
  • Upgrading smart contracts safely: You can implement a safe upgrade mechanism to update your smart contract's program ID without losing data or funds.

pub fn upgrade_contract(new_program_id: &Pubkey) {
    // Update contract's program ID to new_program_id
}

Testing and debugging are critical aspects of smart contract development. In this section, you will learn how to write tests for your smart contracts and debug common issues using tools like the Solana CLI

  • Debugging: You can use the Solana CLI to debug your smart contracts by inspecting account states and transaction logs.

fn process_instruction(instruction_data: &[u8]) -> ProgramResult {
    msg!("Received instruction: {:?}", instruction_data);
    // Process instruction...
    Ok(())
}
  • Testing: You can write unit tests and integration tests for your smart contracts using the Rust testing framework.

#[cfg(test)]
mod tests {
    use super::*;

    #[test]
    fn test_process_instruction() {
        let instruction_data = vec![1, 2, 3]; // Example instruction data
        assert_eq!(process_instruction(&instruction_data), Ok(()));
    }
}
  • Integration testing: You can write integration tests to deploy and interact with multiple smart contracts in a simulated environment.

#[cfg(test)]
mod integration_tests {
    use super::*;

    #[test]
    fn test_contract_integration() {
        // Deploy and interact with multiple contracts...
    }
}

Anchor is a framework for building Solana smart contracts using the Rust programming language. It simplifies the development process by providing high-level abstractions and utilities for interacting with the Solana blockchain. Here's an overview of using Anchor for Rust development in Solana: Installation:

You can install Anchor using Cargo, the Rust package manager:

cargo install --git https://github.com/project-serum/anchor --tag <latest_version>

Usage:

  • Create a New Anchor Project:

anchor init my_project
cd my_project
  • Define Your Anchor Program:

Anchor programs are defined using a combination of Rust and a domain-specific language (DSL) provided by Anchor. You define your program's state, instructions, and events in Rust structs annotated with Anchor macros.

use anchor_lang::prelude::*;

#[program]
mod my_program {
    use super::*;

    #[state]
    pub struct MyState {
        pub value: u64,
    }

    impl MyState {
        pub fn new(ctx: Context<Initialize>, value: u64) -> Result<Self> {
            let state = &mut ctx.accounts.state;
            state.value = value;
            Ok(())
        }

        pub fn update(ctx: Context<Update>, value: u64) -> Result<()> {
            let state = &mut ctx.accounts.state;
            state.value = value;
            Ok(())
        }
    }
}
  • Build and Deploy Your Program:

anchor build
anchor deploy

Interact with Your Program:

Anchor generates client libraries that you can use to interact with your Solana program from other Rust code or external applications. You can use these libraries to send transactions, call methods, and query state on the blockchain.

use my_project::my_program::MyProgram;
use anchor_lang::prelude::*;

let program_id = Pubkey::new_from_array([0; 32]);
let payer = Keypair::new();
let client = RpcClient::new("https://api.devnet.solana.com".to_string());

let mut transaction = Transaction::new_with_payer(
    &[Instruction::new_with_bincode(
        program_id,
        &MyProgram::Instruction::Update { value: 42 },
        vec![],
    )],
    Some(&payer.pubkey()),
);
transaction.sign(&[&payer], recent_blockhash);
client.send_and_confirm_transaction(&transaction);

In conclusion, understanding how to develop for the Solana Virtual Machine (SVM) within Eclipse will give you significant advantages in the Ethereum ecosystem. By leveraging the SVM's highly performant parallelized architecture, developers can unlock improved scalability, lower fees, and enhanced throughput for their decentralized applications. This not only ensures a smoother user experience but also allows you to build more efficient and scalable applications with Eclipse.

Transaction Execution:

Parallel Transaction Processing:

Efficient State Handling:

Integration with Eclipse's Workflow:

How to use the Solana CLI

Follow this guide to install the Solana CLI on your machine:

Setting up your Development Environment

Creating Your First Solana Smart Contract

Deploying Smart Contracts on the Solana Blockchain

Interacting with Smart Contracts

Advanced Smart Contract Development Techniques

Testing and Debugging Smart Contracts

What is Anchor

📖
​
​
​
​
​
​
​
​
​
​
​
​
​
​
Solana CLI Installation Docs
​
​
​
​
​
​
​