Skip to content

rusiqe/rust-backend-for-epic-dapp

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

3 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

Epic DApp - Solana Smart Contract Backend

A Solana smart contract built with the Anchor framework, serving as the blockchain backend for an epic decentralized application. This project demonstrates basic Solana program development using Rust and provides the foundation for building more complex DeFi applications.

πŸš€ Overview

This project contains a Solana program (smart contract) that can be deployed to the Solana blockchain. It's built using the Anchor framework, which provides a higher-level abstraction for Solana program development, making it easier to write, test, and deploy smart contracts.

πŸ—οΈ Project Structure

rust-backend-for-epic-dapp/
β”œβ”€β”€ programs/
β”‚   └── myepicproject/
β”‚       β”œβ”€β”€ src/
β”‚       β”‚   └── lib.rs          # Main program logic
β”‚       β”œβ”€β”€ Cargo.toml          # Program dependencies
β”‚       └── Xargo.toml          # Cross-compilation config
β”œβ”€β”€ tests/
β”‚   └── myepicproject.js        # JavaScript tests
β”œβ”€β”€ migrations/
β”‚   └── deploy.js               # Deployment script
β”œβ”€β”€ Anchor.toml                 # Anchor configuration
β”œβ”€β”€ Cargo.toml                  # Workspace configuration
β”œβ”€β”€ package.json                # Node.js dependencies
└── README.md

πŸ“‹ Prerequisites

Before you begin, ensure you have the following installed:

  • Rust (latest stable version)

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

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

    cargo install --git https://github.com/project-serum/anchor anchor-cli --locked
  • Node.js (v14 or later)

    # Install via nvm (recommended)
    curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.0/install.sh | bash
    nvm install node

πŸ› οΈ Installation

  1. Clone the repository:

    git clone https://github.com/your-username/rust-backend-for-epic-dapp.git
    cd rust-backend-for-epic-dapp
  2. Install JavaScript dependencies:

    npm install
  3. Build the Anchor project:

    anchor build

🚦 Quick Start

1. Configure Solana CLI

# Set to localhost for development
solana config set --url localhost

# Create a new keypair if you don't have one
solana-keygen new

# Check your configuration
solana config get

2. Start Local Validator

In a separate terminal:

solana-test-validator

3. Deploy the Program

# Deploy to local cluster
anchor deploy

4. Run Tests

# Run the test suite
anchor test

# Or run tests manually
node tests/myepicproject.js

πŸ“– Program Details

Smart Contract Functions

  • start_stuff_off(): A basic initialization function that demonstrates the program structure. This is the entry point for interacting with the smart contract.

Program ID

Fg6PaFpoGXkYsidMpWTK6W2BeZ7FEfcYkg476zPFsLnS

Account Structure

Currently implements:

  • StartStuffOff: Basic account structure for the initialization function

πŸ§ͺ Testing

The project includes JavaScript tests using the Anchor testing framework:

  • Test Location: tests/myepicproject.js
  • Test Framework: Mocha + Chai
  • Provider: Anchor Provider with local environment

Running Tests

# Run all tests
anchor test

# Run tests with verbose output
anchor test --skip-local-validator

πŸš€ Deployment

Local Deployment

# Make sure local validator is running
solana-test-validator

# Deploy to local cluster
anchor deploy

Devnet Deployment

# Switch to devnet
solana config set --url devnet

# Airdrop SOL for gas fees
solana airdrop 2

# Deploy to devnet
anchor deploy

Mainnet Deployment

# Switch to mainnet
solana config set --url mainnet-beta

# Deploy (ensure you have sufficient SOL)
anchor deploy

πŸ”§ Development

Project Configuration

  • Anchor Version: 0.19.0
  • Rust Edition: 2018
  • Solana Cluster: Configured for localnet by default

Adding New Functions

  1. Define new instruction handlers in programs/myepicproject/src/lib.rs
  2. Add corresponding account structures
  3. Write tests in tests/myepicproject.js
  4. Build and test: anchor build && anchor test

Code Structure

use anchor_lang::prelude::*;

declare_id!("Your-Program-ID-Here");

#[program]
pub mod myepicproject {
    use super::*;
    
    // Your instruction handlers go here
    pub fn your_function(ctx: Context<YourAccounts>) -> ProgramResult {
        // Implementation
        Ok(())
    }
}

#[derive(Accounts)]
pub struct YourAccounts {
    // Account definitions
}

πŸ› Troubleshooting

Common Issues

  1. "Program not found" error:

    • Ensure solana-test-validator is running
    • Check that the program was deployed successfully
    • Verify the program ID matches in all configuration files
  2. Build errors:

    • Update Rust: rustup update
    • Clear target directory: cargo clean
    • Rebuild: anchor build
  3. Test failures:

    • Ensure local validator is running on the correct port
    • Check that your wallet has sufficient SOL
    • Verify the program ID in tests matches the deployed program

Debug Commands

# Check Solana configuration
solana config get

# Check wallet balance
solana balance

# View program logs
solana logs

# Get program account info
solana account <PROGRAM_ID>

🀝 Contributing

  1. Fork the repository
  2. Create a feature branch: git checkout -b feature/amazing-feature
  3. Make your changes and add tests
  4. Ensure all tests pass: anchor test
  5. Commit your changes: git commit -m 'Add amazing feature'
  6. Push to the branch: git push origin feature/amazing-feature
  7. Open a Pull Request

πŸ“š Resources

πŸ“„ License

This project is licensed under the MIT License - see the LICENSE file for details.

πŸš€ Next Steps

  • Add more sophisticated smart contract functions
  • Implement proper state management
  • Add comprehensive error handling
  • Create frontend integration examples
  • Add CI/CD pipeline
  • Implement security best practices
  • Add performance optimizations

Built with ❀️ using Solana and Anchor

About

The backend for the panda gif project. in Rust-lang

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published