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
    • Unified Restaking Tokens (URTs)
  • 🛠️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
  • Prerequisites​
  • Switching to the Eclipse Devnet​
  • Writing the smart contract:​
Edit on GitHub
  1. Developers
  2. Developer Tooling

OpenBook Quickstart

PreviousAllDomainsNextMultisig

Last updated 23 days ago

The goal of this section is to develop a smart contract to interact with the OpenBook deployment on the Eclipse Devnet

Prerequisites

Install and configure Rust

curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh

Check if Rust is installed

rustc --version
cargo --version

WARNING

Make sure you add the Rust toolchain to your PATH

Make sure you add the Rust toolchain to your PATH

Finally, let's go ahead and install the Solana CLI tools

sh -c "$(curl -sSfL https://release.solana.com/stable/install)"

Switching to the Eclipse Devnet

Now set your solana cli to the Eclipse Devnet

solana config set --url https://staging-rpc.dev2.eclipsenetwork.xyz

Tokens

solana airdrop 10

  • We need our smart contract to connect with the OpenBook deployment on Eclipse

  • OpenBook essentially allows us keep records of the trades and transactions that take place on our network.

  • The Eclipse OpenBook deployment has its own API which is essential for us to interact with it.

  • We will mostly follow the standard deployment process for any Solana app

  • We will also need the programId for the OpenBook deployment on the Eclipse Devnet, which is as follows: xY9r3jzQQLYuxBycxfT31xytsPDrpacWnyswMskn16s

  • Let's begin by writing out our lib.rs file.

  • First we need to include the anchor crates and declare the programId

use anchor_lang::prelude::*;

declare_id!("<smart_contract_programId>");

...
  • Now let's go ahead and write the logic for our smart contract here.

  • Since everything is an account on Solana, we need to define our accounts here.

  • We can also add any required function and its logic here

...

#[program]
pub mod my_smart_contract {
    use super::*;

    #[derive(Accounts)]
    pub struct MyAccounts<'info> {
    }

    #[access_control(allow)]
    pub fn trade(ctx: Context<MyAccounts>) -> ProgramResult {
        Ok(())
    }
}
...
  • Now let's go ahead and interact with the OpenBook deployment.

  • First let's connect to the Eclipse devnet by supplying the RPC url

  • Now we can use the programId to connect to the OpenBook deployment

  • After this we can write whatever API calls we need

...

#[tokio::main]
async fn main() {
    let ecl_rpc = "https://staging-rpc.dev2.eclipsenetwork.xyz";
    let provider = Provider::new(ecl_rpc).await.unwrap();

    let dex_program_id = Pubkey::from_str("xY9r3jzQQLYuxBycxfT31xytsPDrpacWnyswMskn16s").unwrap();
    // First we need to perform authorization based on the token. This is the first account.
    struct Identity;

    impl Identity {
      fn prepare_pda<'info>(acc_info: &AccountInfo<'info>) -> AccountInfo<'info> {
        let mut acc_info = acc_info.clone();
        acc_info.is_signer = true;
        acc_info
      }
  }
    // Now to interact with the deployment
  impl MarketMiddleware for Identity {
    // Here is an example API call
        fn new_order_v3(&self, ctx: &mut Context, _ix: &mut NewOrderInstructionV3) -> ProgramResult {
        verify_and_strip_auth(ctx)
    }
    // Note that these calls are based on the public crate that is available for the deployment. This example assumes the availability of the default crates from a standard openbook deployment.
  }
}

...
  • To deploy the smart contract with anchor we can just do the following:

  anchor build

And then

  anchor deploy
  • Using this template you can write your own trade functions and deploy it on the Eclipse Devnet.

Now you should be good to go!

Writing the smart contract:

Interfacing with OpenBook

Deploying the smart contract:

🛠️
​
​
​
​
​
​
​
​
​
​
​