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
Edit on GitHub
  1. Tutorials & Guides
  2. Developer Guides
  3. Dapp Deployment Tutorial - Eclipse Devnet
  4. Creating an Anchor Project in Visual Studio Code

Step 2: Update the lib.rs File with Smart Contract Code

In this step, you'll define the functionality for NFT minting within your project by updating the lib.rs file with provided Rust code. This smart contract code includes the structure and logic necessary for creating NFTs.

Instructions

  1. Access the lib.rs File:

    • Use Visual Studio Code to navigate to programs/nftminter/src/ in your project's directory.

    • Open the lib.rs file. Initially, this contains Anchor's default scaffolded code.

  2. Update the File with Provided Code:

    • Erase the existing content and insert the following example code or your own code:

      use anchor_lang::prelude::*;
      use anchor_spl::token::{self, MintTo, Token, TokenAccount};
      
      declare_id!("28yv9AxVwUtw1HtDYin7JS3F3x1Z2G9cqAdowUb3iCs6");
      
      #[program]
      pub mod nftminter {
          use super::*;
          pub fn mint_nft(ctx: Context<MintNft>, name: String, description: String, image_uri: String) -> Result<()> {
              let nft_info = &mut ctx.accounts.nft_info;
              nft_info.name = name;
              nft_info.description = description;
              nft_info.image_uri = image_uri;
              Ok(())
          }
      }
      
      #[derive(Accounts)]
      pub struct MintNft<'info> {
          #[account(init, payer = user, space = 1024)]
          pub nft_info: Account<'info, NftInfo>,
          #[account(mut)]
          pub user: Signer<'info>,
          pub system_program: Program<'info, System>,
      }
      
      #[account]
      pub struct NftInfo {
          pub name: String,
          pub description: String,
          pub image_uri: String,
      }
    • This code establishes the functionality for your NFT minter, including the mint_nft function and the NftInfo structure to hold NFT metadata

  3. Key Components Overview:

    • The use statements bring necessary modules into scope.

    • declare_id! uniquely identifies your smart contract on the blockchain.

    • The #[program] attribute and subsequent module define the contract's executable functions.

    • #[derive(Accounts)] specifies the accounts context required for the mint_nft function.

    • NftInfo struct holds the NFT's metadata.

If you already have your own code that differs from this NFT example, feel free to paste that instead.

Next Steps

  • With the smart contract code in place, you're set to further develop, test, and eventually deploy your NFT minter.

PreviousStep 1: Initialize Anchor ProjectNextStep 3: Update the Smart Contract's Cargo.toml File

Last updated 1 year ago

📖
🖥️