> For the complete documentation index, see [llms.txt](https://solieum.gitbook.io/solieum/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://solieum.gitbook.io/solieum/archive-solve-framework.md).

# archive solve framework

<figure><img src="https://content.gitbook.com/content/9sknVijWtYbZXNBeIcYM/blobs/7gCsAyjWQ02Bl36VWcpy/Screenshot_15.png" alt="Solve Framework Logo"><figcaption><p>Building secure smart contracts with the Solve Framework</p></figcaption></figure>

[Visit Official Website](https://solvelang.com/)

## 🌟 Overview

Solve is a cutting-edge programming framework designed specifically for constructing efficient and secure Solieum & Solana programs (smart contracts). It streamlines the entire development lifecycle from coding to testing and deployment, helping developers focus on business logic rather than low-level implementation details.

## 💡 What is Solve Language?

The Solve framework empowers developers to create production-ready applications faster while eliminating potential risks through built-in security safeguards. By handling boilerplate code and applying standard security checks automatically, it allows developers to design, test, and deploy Solana applications more quickly and securely.

Solve generates boilerplate Rust code using advanced macros and traits, enabling programmers to concentrate on application functionality rather than low-level concerns.

![Solve Benefits](https://content.gitbook.com/content/9sknVijWtYbZXNBeIcYM/blobs/A07BWlkGVbIBx8p2cwTG/image.png)

## ✨ Key Advantages

#### 🏗️ Simplified Structure

Solve offers a clear framework for organizing Solana programs, improving readability, maintainability, and collaboration.

#### 🛡️ Built-in Security

Guarantees that Solana applications are protected through standard security checks and provides facilities to specify and enforce additional validation.

#### ⚡ Increased Productivity

Automatically handles (de)serialization of accounts and instruction data, significantly reducing the amount of code developers need to write.

#### 🔄 Full-Stack Integration

Provides a TypeScript client library that streamlines interaction with Solana programs from the client-side in JavaScript or TypeScript.

## 🧩 Structure of a Solve Program

| Component                | Description                                                                                        |
| ------------------------ | -------------------------------------------------------------------------------------------------- |
| **Program Module**       | Specifies the instructional logic of the program and defines the core functionality.               |
| **Accounts**             | Indicates the accounts needed for instructions and defines the data structures for on-chain state. |
| **Instructions**         | Defines the activities that may be performed on the program and the entry points for interaction.  |
| **Tools & Abstractions** | Offers a range of utilities helping to create Solana programs more naturally and safely.           |

#### 💡 Helpful Analogy

Think of Solve as Next.js for blockchain development. Just as Next.js lets developers build websites using React rather than depending solely on HTML and JavaScript, Solve provides a higher-level abstraction for Solana program development, reducing complexity and improving productivity.

## 🛠️ Technical Implementation

### Setting Up a Solve Project

{% stepper %}
{% step %}

## Install the Solve CLI

```bash
# Install Solve CLI
npm install -g @solieum/solve-cli
```

{% endstep %}

{% step %}

## Create a new Solve project

```bash
# Create a new Solve project
solve new my-solieum-app
cd my-solieum-app
```

{% endstep %}

{% step %}

## Build the project

```bash
# Build the project
solve build
```

{% endstep %}
{% endstepper %}

### Implementing a Simple Token Contract

Here's an example of how to create a basic token contract using the Solve framework:

```rust
use solve_macros::program;
use solve_sdk::{
    account::{Account, AccountInfo},
    entrypoint,
    program_error::ProgramError,
    pubkey::Pubkey,
};

// Define the program structure
#[program]
pub mod token_program {
    use super::*;

    // Define token account structure
    #[account]
    pub struct TokenAccount {
        pub owner: Pubkey,
        pub balance: u64,
    }

    // Initialize a new token account
    #[instruction]
    pub fn initialize_account(ctx: Context<InitializeAccount>) -> Result<(), ProgramError> {
        let token_account = &mut ctx.accounts.token_account;
        token_account.owner = *ctx.accounts.owner.key;
        token_account.balance = 0;
        Ok(())
    }

    // Transfer tokens between accounts
    #[instruction]
    pub fn transfer(ctx: Context<Transfer>, amount: u64) -> Result<(), ProgramError> {
        let from_account = &mut ctx.accounts.from;
        let to_account = &mut ctx.accounts.to;
        
        // Check if sender has enough tokens
        if from_account.balance < amount {
            return Err(ProgramError::InsufficientFunds);
        }
        
        // Check if sender is the owner
        if from_account.owner != *ctx.accounts.owner.key {
            return Err(ProgramError::InvalidAccountOwner);
        }
        
        // Transfer tokens
        from_account.balance = from_account.balance.checked_sub(amount)
            .ok_or(ProgramError::InsufficientFunds)?;
        
        to_account.balance = to_account.balance.checked_add(amount)
            .ok_or(ProgramError::Overflow)?;
        
        Ok(())
    }

    // Context for initializing an account
    #[derive(Accounts)]
    pub struct InitializeAccount<'info> {
        #[account(init, payer = owner, space = 8 + 32 + 8)]
        pub token_account: Account<'info, TokenAccount>,
        #[account(mut)]
        pub owner: Signer<'info>,
        pub system_program: Program<'info, System>,
    }

    // Context for transferring tokens
    #[derive(Accounts)]
    pub struct Transfer<'info> {
        #[account(mut)]
        pub from: Account<'info, TokenAccount>,
        #[account(mut)]
        pub to: Account<'info, TokenAccount>,
        pub owner: Signer<'info>,
    }
}

// Entrypoint that handles incoming instructions
entrypoint!(process_instruction);
fn process_instruction(
    program_id: &Pubkey,
    accounts: &[AccountInfo],
    instruction_data: &[u8],
) -> Result<(), ProgramError> {
    token_program::process_instruction(program_id, accounts, instruction_data)
}
```

### Interacting with the Solve Contract from Client-side

The following example shows how to interact with the token program using the Solve TypeScript client:

```typescript
import {
  Connection,
  Keypair,
  PublicKey,
  SystemProgram,
} from '@solieum/web3.js';
import * as solveClient from '@solieum/solve-client';
import { TokenProgram } from './token_program'; // Generated client

// Connect to Solieum Layer 2 network
const connection = new Connection('https://api.testnet.solieum.com');

// Load user wallet
const userWallet = Keypair.generate();

// Program ID of the deployed token program
const programId = new PublicKey('So1VEpRoGrAmID1111111111111111111111111');

// Create program client
const program = new TokenProgram(
  connection,
  programId,
  { commitment: 'confirmed' }
);

// Create a new token account
async function createTokenAccount() {
  const tokenAccount = Keypair.generate();
  
  const tx = await program.methods
    .initializeAccount()
    .accounts({
      tokenAccount: tokenAccount.publicKey,
      owner: userWallet.publicKey,
      systemProgram: SystemProgram.programId,
    })
    .signers([userWallet, tokenAccount])
    .rpc();
    
  console.log(`Token account created: ${tokenAccount.publicKey.toString()}`);
  console.log(`Transaction signature: ${tx}`);
  
  return tokenAccount;
}

// Transfer tokens between accounts
async function transferTokens(
  fromAccount: PublicKey,
  toAccount: PublicKey,
  amount: number
) {
  const tx = await program.methods
    .transfer(amount)
    .accounts({
      from: fromAccount,
      to: toAccount,
      owner: userWallet.publicKey,
    })
    .signers([userWallet])
    .rpc();
    
  console.log(`Transferred ${amount} tokens from ${fromAccount} to ${toAccount}`);
  console.log(`Transaction signature: ${tx}`);
}

// Example usage
(async () => {
  const account1 = await createTokenAccount();
  const account2 = await createTokenAccount();
  
  // You would need to fund account1 with tokens first
  // ...
  
  // Then transfer tokens
  await transferTokens(account1.publicKey, account2.publicKey, 100);
})();
```

### Deploying to Solieum Layer 2

{% stepper %}
{% step %}

## Build the program

```bash
# Build the program
solve build
```

{% endstep %}

{% step %}

## Deploy to Solieum Layer 2 testnet

```bash
# Deploy to Solieum Layer 2 testnet
solve deploy --network solieum-testnet
```

{% endstep %}

{% step %}

## Verify the deployment

```bash
# Verify the deployment
solve verify <PROGRAM_ID> --network solieum-testnet
```

{% endstep %}
{% endstepper %}

## 📐 Solve Framework Architecture

<figure><img src="https://content.gitbook.com/content/9sknVijWtYbZXNBeIcYM/blobs/7vhcIHtiApDQmLXcHbMk/image.png" alt="Solve Framework Architecture"><figcaption><p>Architectural overview of the Solve Framework</p></figcaption></figure>

The Solve framework follows the CRADLE (Comprehensive Rust Architecture for Decentralized Ledger Engineering) design pattern, which emphasizes:

1. **Clear separation of concerns**

   Programs, accounts, and instructions are clearly defined and isolated.
2. **Automatic security validations**

   Pre-checks account permissions and ownership to prevent common vulnerabilities.
3. **Declarative programming model**

   Reduce boilerplate with annotations and macros for a cleaner codebase.
4. **Lightweight execution**

   Optimized for the SVM (Solana Virtual Machine) environment.
5. **Elegant error handling**

   Comprehensive error system with detailed information for developers.

This architecture enables developers to build robust and secure applications on the Solieum Layer 2 platform with significantly less code than traditional Solana development approaches.

## 📊 Solve Framework in Action

#### Code Comparison: Traditional vs. Solve

**Traditional Solana Program (150+ lines)**

```
// Complex account validation
// Manual serialization/deserialization
// Error-prone state management
// Verbose instruction handling
// Manual security checks
// ...and much more boilerplate
```

**Solve Framework (50+ lines)**

```rust
#[program]
pub mod token_program {
    #[account]
    pub struct TokenAccount { /* ... */ }
#[instruction]pub fn transfer(ctx, amount) {    // Business logic only    // Security handled automatically}
}
```

## 🔗 Integration with Other Solieum Tools

#### 🧰 Solieum SPK

Solve Framework integrates seamlessly with the Solieum Programme Kit for a complete development experience.

[Learn more →](file:///solieum/solieum-programme-kit-spk.md)

#### 🌉 Wallet Bridge

Easily develop bridge-compatible applications using Solve for cross-chain functionality.

[Learn more →](file:///solieum/wallet-bridge.md)

#### 🔄 Layer 2 Solutions

Build applications specifically optimized for Solieum's Layer 2 scaling solutions.

[Learn more →](file:///solieum/solana-rollups-rollapps-layer-2-solutions.md)
