MultiVM Smart Contract

Details are provisional and may be updated during development.

When to Choose Which VM

One of the most common questions is: "Which VM should I use?" The answer depends on your specific requirements, and Arichain gives you the flexibility to choose the optimal execution environment for each component.

Use Case
Recommended VM
Technical Reason

DeFi Protocols

EVM

Rich library ecosystem (OpenZeppelin, Uniswap), battle-tested patterns, complex state management

Gaming/Real-time

SVM

High TPS, predictable fees, parallel execution, sub-second finality

Payment Systems

SVM

Fixed fee structure, optimized for simple transfers, high throughput

DAO/Governance

EVM

Mature governance frameworks, extensive auditing tools, compliance integrations

High-Frequency Trading

SVM

Ultra-low latency, parallel transaction processing, optimized for speed

Complex Smart Contracts

EVM

Rich tooling ecosystem, extensive libraries, proven security patterns

EVM Deployment Guide

Deploy your existing Ethereum contracts without any modifications. The execution environment is identical to Ethereum mainnet.

// contracts/MyDeFiProtocol.sol - Your existing contract
pragma solidity ^0.8.19;

import "@openzeppelin/contracts/token/ERC20/ERC20.sol";
import "@uniswap/v3-periphery/contracts/interfaces/ISwapRouter.sol";

contract MyDeFiProtocol {
    ISwapRouter public immutable swapRouter;
    
    constructor(address _swapRouter) {
        swapRouter = ISwapRouter(_swapRouter);
    }
    
    function swapTokens(
        address tokenIn,
        address tokenOut,
        uint256 amountIn,
        uint256 amountOutMinimum
    ) external returns (uint256 amountOut) {
        // Your existing DeFi logic - works identically
        // All OpenZeppelin contracts work as-is
        // All Uniswap integrations work as-is
        
        ISwapRouter.ExactInputSingleParams memory params = ISwapRouter.ExactInputSingleParams({
            tokenIn: tokenIn,
            tokenOut: tokenOut,
            fee: 3000,
            recipient: msg.sender,
            deadline: block.timestamp + 300,
            amountIn: amountIn,
            amountOutMinimum: amountOutMinimum,
            sqrtPriceLimitX96: 0
        });
        
        amountOut = swapRouter.exactInputSingle(params);
    }
}
// hardhat.config.js - Just add Arichain network
require("@nomicfoundation/hardhat-toolbox");

module.exports = {
  solidity: "0.8.19",
  networks: {
    // Your existing networks work unchanged
    ethereum: {
      url: process.env.ETHEREUM_RPC_URL,
      accounts: [process.env.PRIVATE_KEY]
    },
    polygon: {
      url: process.env.POLYGON_RPC_URL,
      accounts: [process.env.PRIVATE_KEY]
    },
    // Add Arichain - that's the only change needed
    arichain: {
      url: "https://evm-testnet.arichain.network (TBD)",
      accounts: [process.env.PRIVATE_KEY],
      chainId: 1337
    }
  }
};
# Deploy using your existing commands
npx hardhat compile
npx hardhat deploy --network arichain
npx hardhat verify --network arichain <contract-address>

SVM Deployment Guide

Deploy your existing Solana programs without any modifications. The runtime environment is identical to Solana mainnet.

// programs/my-game/src/lib.rs - Your existing program
use anchor_lang::prelude::*;

declare_id!("YourProgramIdHere");

#[program]
pub mod my_game {
    use super::*;
    
    pub fn initialize_game(ctx: Context<InitializeGame>) -> Result<()> {
        let game_state = &mut ctx.accounts.game_state;
        game_state.players = 0;
        game_state.status = GameStatus::WaitingForPlayers;
        Ok(())
    }
    
    pub fn process_battle(
        ctx: Context<ProcessBattle>,
        actions: Vec<GameAction>
    ) -> Result<()> {
        // Your existing high-performance game logic
        let game_state = &mut ctx.accounts.game_state;
        
        for action in actions.iter() {
            match action {
                GameAction::Attack { target, damage } => {
                    // Process attack with high throughput
                    process_attack(game_state, *target, *damage)?;
                },
                GameAction::Move { position } => {
                    // Process movement with low latency
                    process_movement(game_state, *position)?;
                }
            }
        }
        
        Ok(())
    }
}

#[derive(Accounts)]
pub struct ProcessBattle<'info> {
    #[account(mut)]
    pub player: Signer<'info>,
    
    #[account(mut)]
    pub game_state: Account<'info, GameState>,
    
    pub system_program: Program<'info, System>,
}
# Anchor.toml - Just update cluster
[features]
seeds = false
skip-lint = false

[programs.localnet]
my_game = "YourProgramIdHere"

[registry]
url = "TBD"

[provider]
cluster = "https://svm-testnet.arichain.network (TBD)"  # Only change needed
wallet = "~/.config/solana/id.json"

[scripts]
test = "yarn run ts-mocha -p ./tsconfig.json -t 1000000 tests/**/*.ts"
# Deploy using your existing commands
anchor build
anchor deploy
anchor test --skip-local-validator

Your First MultiVM dApp

While your existing code works unchanged, Arichain enables powerful new capabilities by combining both virtual machines in a single application. This section shows how to leverage both EVM and SVM strengths simultaneously.

Hybrid Architecture Pattern

The most powerful pattern on Arichain is using each VM for what it does best:

// Use both VMs in a single application
class HybridDApp {
    constructor() {
        // EVM for complex DeFi logic
        this.evmProvider = new ethers.JsonRpcProvider('https://evm-testnet.arichain.network (TBD)');
        this.defiContract = new ethers.Contract(contractAddress, abi, this.evmProvider);
        
        // SVM for high-performance operations
        this.svmConnection = new Connection('https://svm-testnet.arichain.network (TBD)');
        this.gameProgram = new Program(idl, programId, { connection: this.svmConnection });
        
        // Unified data layer
        this.arichain = new ArichainClient({
            evmRpc: 'https://evm-testnet.arichain.network (TBD)',
            svmRpc: 'https://svm-testnet.arichain.network (TBD)'
        });
    }
    
    async executeHybridOperation(params) {
        // Complex calculation on EVM
        const calculation = await this.defiContract.calculateComplexFormula(params);
        
        // High-frequency execution on SVM
        const result = await this.gameProgram.methods
            .processHighFrequencyOperation(calculation)
            .rpc();
        
        return result;
    }
}

Migration Guide

From Ethereum to Arichain

Your existing Ethereum applications can be deployed on Arichain with minimal changes, while gaining access to SVM capabilities for performance-critical components.

// Step 1: Update network configuration (only change needed)
// hardhat.config.js
module.exports = {
  networks: {
    ethereum: {
      url: process.env.ETHEREUM_RPC_URL,
      accounts: [process.env.PRIVATE_KEY]
    },
    // Add Arichain EVM - identical to Ethereum
    arichain: {
      url: "https://evm-rpc.arichain.network (TBD)",
      accounts: [process.env.PRIVATE_KEY],
      chainId: 1338
    }
  }
};

// Step 2: Deploy unchanged contracts
npx hardhat deploy --network arichain

// Step 3: Optionally enhance with MultiVM features
import { ArichainClient } from '@arichain/sdk';

const arichain = new ArichainClient({
    evmRpc: 'https://evm-rpc.arichain.network (TBD)',
    svmRpc: 'https://svm-rpc.arichain.network (TBD)'
});

// Add unified asset tracking to existing dApp
const enhancedDApp = {
    ...existingDApp,
    
    async getUserAssets(address) {
        // Original function still works
        const evmAssets = await existingDApp.getAssets(address);
        
        // Enhanced with cross-VM capabilities
        const allAssets = await arichain.getUnifiedAssets(address);
        
        return { evmAssets, allAssets };
    }
};

From Solana to Arichain

Your existing Solana programs work identically on Arichain, with the added benefit of EVM integration for complex business logic.

# Step 1: Update cluster configuration (only change needed)
# Anchor.toml
[provider]
cluster = "https://svm-rpc.arichain.network (TBD)"  # Only change
wallet = "~/.config/solana/id.json"

# Step 2: Deploy unchanged programs
anchor deploy

# Step 3: Optionally integrate with EVM
// Enhanced client with EVM integration
class EnhancedSolanaClient {
    constructor() {
        // Your existing Solana connection
        this.connection = new Connection('https://svm-rpc.arichain.network (TBD)');
        this.program = new Program(idl, programId, { connection: this.connection });
        
        // Add EVM capabilities
        this.evmProvider = new ethers.JsonRpcProvider('https://evm-rpc.arichain.network (TBD)');
        this.arichain = new ArichainClient({
            evmRpc: 'https://evm-rpc.arichain.network (TBD)',
            svmRpc: 'https://svm-rpc.arichain.network (TBD)'
        });
    }
    
    async enhancedGamePlay(gameAction) {
        // High-performance game logic on SVM (unchanged)
        const gameResult = await this.program.methods
            .processGameAction(gameAction)
            .rpc();
        
        // Complex reward calculation on EVM (new capability)
        if (gameResult.earnedReward) {
            const evmContract = new ethers.Contract(rewardAddress, abi, this.evmProvider);
            await evmContract.calculateComplexReward(gameResult.playerId, gameResult.score);
        }
        
        return gameResult;
    
}

Last updated