Quick Start Guide
Build and deploy your first Solana program with Rudy in just 5 minutes.
Let's Build Something!
This guide will walk you through creating a simple counter program that demonstrates the core concepts of Rudy Framework.
Step 1: Create a New Project
Initialize a new Rudy project with the CLI
$ rudy new my_first_program
Step 2: Navigate to Project
Move into your new project directory
$ cd my_first_program
Step 3: Build the Program
Compile your Solana program
$ rudy build
Step 4: Run Tests
Execute the test suite
$ rudy test
Step 5: Deploy to Devnet
Deploy your program to Solana devnet
$ rudy deploy --network devnet
Project Structure
After creating your project, you'll see the following structure:
my_first_program/
├── Cargo.toml # Rust dependencies
├── Rudy.toml # Rudy configuration
├── src/
│ └── lib.rs # Your program code
├── tests/
│ └── integration.rs # Integration tests
└── target/ # Build artifacts
Understanding the Code
Your new project includes a simple counter program. Let's look at the main components:
Program Definition
use rudy::prelude::*;
#[program]
pub mod counter {
use super::*;
pub fn initialize(ctx: Context<Initialize>) -> Result<()> {
let counter = &mut ctx.accounts.counter;
counter.count = 0;
counter.authority = ctx.accounts.authority.key();
msg!("Counter initialized!");
Ok(())
}
pub fn increment(ctx: Context<Increment>) -> Result<()> {
let counter = &mut ctx.accounts.counter;
counter.count += 1;
msg!("Counter incremented to: {}", counter.count);
Ok(())
}
}
Account Structure
#[account]
#[derive(Default)]
pub struct Counter {
pub count: u64,
pub authority: Pubkey,
}
Context Definitions
#[derive(Accounts)]
pub struct Initialize<'info> {
#[account(init, payer = authority, space = 8 + 40)]
pub counter: Account<'info, Counter>,
#[account(mut)]
pub authority: Signer<'info>,
pub system_program: Program<'info, System>,
}
#[derive(Accounts)]
pub struct Increment<'info> {
#[account(mut, has_one = authority)]
pub counter: Account<'info, Counter>,
pub authority: Signer<'info>,
}
Testing Your Program
Rudy includes a powerful testing framework. Here's a simple test:
#[cfg(test)]
mod tests {
use super::*;
use rudy::test::*;
#[tokio::test]
async fn test_counter() {
let mut test = ProgramTest::new();
let counter = test.create_account::<Counter>().await;
// Initialize counter
test.process_transaction(|ctx| {
counter::initialize(ctx, &counter)
}).await.unwrap();
// Increment counter
test.process_transaction(|ctx| {
counter::increment(ctx, &counter)
}).await.unwrap();
// Verify state
let account = test.get_account::<Counter>(&counter).await;
assert_eq!(account.count, 1);
}
}
Run tests with rudy test
to ensure everything works correctly.
What's Next?
Congratulations! You've created, built, and tested your first Rudy program. Here are some next steps:
- •Explore the Core Concepts to understand Rudy's architecture
- •Check out more Examples for real-world patterns
- •Learn about Security Best Practices