重要前提
安装AI Skills的关键前提是:必须科学上网,且开启TUN模式,这一点至关重要,直接决定安装能否顺利完成,在此郑重提醒三遍:科学上网,科学上网,科学上网。查看完整安装教程 →
magicblock by sendaifun/skills
npx skills add https://github.com/sendaifun/skills --skill magicblock一份关于使用 MagicBlock 瞬态 Rollup 构建高性能 Solana 应用程序的全面指南——实现低于 10 毫秒的延迟和无 Gas 交易。
MagicBlock 瞬态 Rollup 是专门的 SVM 运行时,通过以下功能增强 Solana:
┌─────────────────────────────────────────────────────────────┐
│ 您的应用程序 │
├─────────────────────────────────────────────────────────────┤
│ 基础层 (Solana) │ 瞬态 Rollup (ER) │
│ - 初始化账户 │ - 执行操作 │
│ - 委托账户 │ - 以约 10-50 毫秒处理 │
│ - 最终状态提交 │ - 零 Gas 费用 │
│ - 约 400 毫秒最终确认 │ - 将状态提交至 Solana │
└─────────────────────────────────────────────────────────────┘
广告位招租
在这里展示您的产品或服务
触达数万 AI 开发者,精准高效
# 所需版本
Solana: 2.3.13
Rust: 1.85.0
Anchor: 0.32.1
Node: 24.10.0
# 安装 Anchor (如果需要)
cargo install --git https://github.com/coral-xyz/anchor anchor-cli
[dependencies]
anchor-lang = "0.32.1"
ephemeral-rollups-sdk = { version = "0.6.5", features = ["anchor", "disable-realloc"] }
use anchor_lang::prelude::*;
use ephemeral_rollups_sdk::anchor::{delegate_account, commit_accounts, ephemeral};
use ephemeral_rollups_sdk::cpi::DelegationProgram;
declare_id!("YourProgramId111111111111111111111111111111");
#[ephemeral] // 必需:启用 ER 支持
#[program]
pub mod my_program {
use super::*;
pub fn initialize(ctx: Context<Initialize>) -> Result<()> {
ctx.accounts.state.value = 0;
Ok(())
}
#[delegate] // 自动注入委托账户
pub fn delegate(ctx: Context<Delegate>) -> Result<()> {
Ok(())
}
pub fn increment(ctx: Context<Update>) -> Result<()> {
ctx.accounts.state.value += 1;
Ok(())
}
#[commit] // 自动注入提交账户
pub fn undelegate(ctx: Context<Undelegate>) -> Result<()> {
Ok(())
}
}
import { Connection, PublicKey } from "@solana/web3.js";
import { AnchorProvider, Program } from "@coral-xyz/anchor";
import { DELEGATION_PROGRAM_ID } from "@magicblock-labs/ephemeral-rollups-sdk";
// 关键:为每一层使用独立的连接
const baseConnection = new Connection("https://api.devnet.solana.com");
const erConnection = new Connection("https://devnet.magicblock.app");
// 创建提供者
const baseProvider = new AnchorProvider(baseConnection, wallet, { commitment: "confirmed" });
const erProvider = new AnchorProvider(erConnection, wallet, {
commitment: "confirmed",
skipPreflight: true, // ER 必需
});
// 检查委托状态
async function isDelegated(pubkey: PublicKey): Promise<boolean> {
const info = await baseConnection.getAccountInfo(pubkey);
return info?.owner.equals(DELEGATION_PROGRAM_ID) ?? false;
}
委托将 PDA 所有权转移给委托程序,允许瞬态验证器处理交易。
#[derive(Accounts)]
pub struct Delegate<'info> {
#[account(mut)]
pub payer: Signer<'info>,
/// CHECK: Will be delegated
#[account(mut, del)] // 'del' 标记为待委托
pub state: AccountInfo<'info>,
pub delegation_program: Program<'info, DelegationProgram>,
}
提交将 PDA 状态从 ER 更新到基础层,而无需取消委托。
use ephemeral_rollups_sdk::anchor::commit_accounts;
pub fn commit(ctx: Context<Commit>) -> Result<()> {
commit_accounts(
&ctx.accounts.payer,
vec![&ctx.accounts.state.to_account_info()],
&ctx.accounts.magic_context,
&ctx.accounts.magic_program,
)?;
Ok(())
}
将 PDA 所有权归还给您的程序,同时提交最终状态。
#[commit] // 处理提交 + 取消委托
pub fn undelegate(ctx: Context<Undelegate>) -> Result<()> {
Ok(())
}
| 区域 | 验证器身份 |
|---|---|
| 亚洲 | MAS1Dt9qreoRMQ14YQuhg8UTZMMzDdKhmkZMECCzk57 |
| 欧盟 | MEUGGrYPxKk17hCr7wpT6s8dtNokZj5U2L57vjYMS8e |
| 美国 | MUS3hc9TCw4cGC12vHNoYcCGzJG1txjgQLZWVoeNHNd |
| TEE | FnE6VJT5QNZdedZPnCoLsARgBwoE6DeJNjBs2H1gySXA |
Magic 路由器 (自动选择最佳): https://devnet-router.magicblock.app
skipPreflight: trueAccountInfo| 产品 | 描述 |
|---|---|
| 瞬态 Rollup | 高性能、无 Gas 交易 |
| 私有瞬态 Rollup | 使用 Intel TDX 进行隐私保护计算 |
| VRF | 用于链上随机性的可验证随机函数 |
| BOLT 框架 | 用于完全链上游戏的 ECS 架构 |
| Solana 插件 | 用于增强功能的应用程序特定扩展 |
Solana 插件是模块化功能,可以添加到您的 dApp 中以扩展 Solana 上的可能性。将它们视为您的自定义工具包:在需要时插入所需的功能。
| 插件 | 描述 | 使用场景 |
|---|---|---|
| 可验证随机性 | 可证明公平的链上随机性 | 游戏、抽奖、NFT 空投 |
| 实时价格源 | 毫秒级更新的市场数据 | DEX、交易机器人、DeFi |
| AI 预言机 | 直接从智能合约调用 AI 模型 | 动态 NFT、AI 代理 |
import { requestRandomness, getRandomnessResult } from "@magicblock-labs/vrf-sdk";
// 请求随机性
const requestTx = await requestRandomness({
payer: wallet.publicKey,
seed: Buffer.from("my_game_seed"),
});
// 确认后获取结果
const result = await getRandomnessResult(requestId);
console.log("Random value:", result.randomness);
MagicBlock 通过在 Intel TDX 上的可信执行环境中运行的瞬态 Rollup,为任何 Solana 程序状态账户启用隐私。这允许:
magicblock/
├── SKILL.md # 本文件
├── resources/
│ ├── api-reference.md # 完整的 API 参考
│ └── program-ids.md # 所有程序 ID 和常量
├── examples/
│ ├── anchor-counter/README.md # 带委托的基础计数器
│ ├── delegation-flow/README.md # 完整的委托生命周期
│ ├── vrf-randomness/README.md # VRF 集成
│ └── crank-automation/README.md # 计划任务
├── templates/
│ ├── program-template.rs # Rust 程序启动模板
│ └── client-template.ts # TypeScript 客户端启动模板
└── docs/
├── advanced-patterns.md # 复杂模式
└── troubleshooting.md # 常见问题
每周安装量
54
代码仓库
GitHub 星标数
68
首次出现
2026 年 1 月 24 日
安全审计
安装于
opencode51
codex51
gemini-cli50
github-copilot47
amp46
kimi-cli46
A comprehensive guide for building high-performance Solana applications with MagicBlock Ephemeral Rollups - enabling sub-10ms latency and gasless transactions.
MagicBlock Ephemeral Rollups (ER) are specialized SVM runtimes that enhance Solana with:
┌─────────────────────────────────────────────────────────────┐
│ Your Application │
├─────────────────────────────────────────────────────────────┤
│ Base Layer (Solana) │ Ephemeral Rollup (ER) │
│ - Initialize accounts │ - Execute operations │
│ - Delegate accounts │ - Process at ~10-50ms │
│ - Final state commits │ - Zero gas fees │
│ - ~400ms finality │ - Commit state to Solana │
└─────────────────────────────────────────────────────────────┘
# Required versions
Solana: 2.3.13
Rust: 1.85.0
Anchor: 0.32.1
Node: 24.10.0
# Install Anchor (if needed)
cargo install --git https://github.com/coral-xyz/anchor anchor-cli
[dependencies]
anchor-lang = "0.32.1"
ephemeral-rollups-sdk = { version = "0.6.5", features = ["anchor", "disable-realloc"] }
use anchor_lang::prelude::*;
use ephemeral_rollups_sdk::anchor::{delegate_account, commit_accounts, ephemeral};
use ephemeral_rollups_sdk::cpi::DelegationProgram;
declare_id!("YourProgramId111111111111111111111111111111");
#[ephemeral] // Required: enables ER support
#[program]
pub mod my_program {
use super::*;
pub fn initialize(ctx: Context<Initialize>) -> Result<()> {
ctx.accounts.state.value = 0;
Ok(())
}
#[delegate] // Auto-injects delegation accounts
pub fn delegate(ctx: Context<Delegate>) -> Result<()> {
Ok(())
}
pub fn increment(ctx: Context<Update>) -> Result<()> {
ctx.accounts.state.value += 1;
Ok(())
}
#[commit] // Auto-injects commit accounts
pub fn undelegate(ctx: Context<Undelegate>) -> Result<()> {
Ok(())
}
}
import { Connection, PublicKey } from "@solana/web3.js";
import { AnchorProvider, Program } from "@coral-xyz/anchor";
import { DELEGATION_PROGRAM_ID } from "@magicblock-labs/ephemeral-rollups-sdk";
// CRITICAL: Separate connections for each layer
const baseConnection = new Connection("https://api.devnet.solana.com");
const erConnection = new Connection("https://devnet.magicblock.app");
// Create providers
const baseProvider = new AnchorProvider(baseConnection, wallet, { commitment: "confirmed" });
const erProvider = new AnchorProvider(erConnection, wallet, {
commitment: "confirmed",
skipPreflight: true, // Required for ER
});
// Check delegation status
async function isDelegated(pubkey: PublicKey): Promise<boolean> {
const info = await baseConnection.getAccountInfo(pubkey);
return info?.owner.equals(DELEGATION_PROGRAM_ID) ?? false;
}
Delegation transfers PDA ownership to the delegation program, allowing the Ephemeral Validator to process transactions.
#[derive(Accounts)]
pub struct Delegate<'info> {
#[account(mut)]
pub payer: Signer<'info>,
/// CHECK: Will be delegated
#[account(mut, del)] // 'del' marks for delegation
pub state: AccountInfo<'info>,
pub delegation_program: Program<'info, DelegationProgram>,
}
Commits update PDA state from ER to base layer without undelegating.
use ephemeral_rollups_sdk::anchor::commit_accounts;
pub fn commit(ctx: Context<Commit>) -> Result<()> {
commit_accounts(
&ctx.accounts.payer,
vec![&ctx.accounts.state.to_account_info()],
&ctx.accounts.magic_context,
&ctx.accounts.magic_program,
)?;
Ok(())
}
Returns PDA ownership to your program while committing final state.
#[commit] // Handles commit + undelegate
pub fn undelegate(ctx: Context<Undelegate>) -> Result<()> {
Ok(())
}
| Region | Validator Identity |
|---|---|
| Asia | MAS1Dt9qreoRMQ14YQuhg8UTZMMzDdKhmkZMECCzk57 |
| EU | MEUGGrYPxKk17hCr7wpT6s8dtNokZj5U2L57vjYMS8e |
| US | MUS3hc9TCw4cGC12vHNoYcCGzJG1txjgQLZWVoeNHNd |
| TEE | FnE6VJT5QNZdedZPnCoLsARgBwoE6DeJNjBs2H1gySXA |
Magic Router (auto-selects best): https://devnet-router.magicblock.app
skipPreflight: true for all ER transactionsAccountInfo for delegated accounts in Rust| Product | Description |
|---|---|
| Ephemeral Rollup (ER) | High-performance, gasless transactions |
| Private ER (PER) | Privacy-preserving computation with Intel TDX |
| VRF | Verifiable random function for on-chain randomness |
| BOLT Framework | ECS architecture for fully on-chain games |
| Solana Plugins | App-specific extensions for enhanced capabilities |
Solana Plugins are modular capabilities that can be added to your dApp to extend what's possible on Solana. Think of them as your custom toolkit: plug in what you need, when you need it.
| Plugin | Description | Use Cases |
|---|---|---|
| Verifiable Randomness (VRF) | Provably fair on-chain randomness | Games, lotteries, NFT drops |
| Real-Time Price Feeds | Up-to-the-millisecond market data | DEXs, trading bots, DeFi |
| AI Oracles | Call AI models directly from smart contracts | Dynamic NFTs, AI agents |
import { requestRandomness, getRandomnessResult } from "@magicblock-labs/vrf-sdk";
// Request randomness
const requestTx = await requestRandomness({
payer: wallet.publicKey,
seed: Buffer.from("my_game_seed"),
});
// Get result after confirmation
const result = await getRandomnessResult(requestId);
console.log("Random value:", result.randomness);
MagicBlock enables privacy in any Solana program state account through Ephemeral Rollups running in Trusted Execution Environments (TEE) on Intel TDX. This allows:
magicblock/
├── SKILL.md # This file
├── resources/
│ ├── api-reference.md # Complete API reference
│ └── program-ids.md # All program IDs and constants
├── examples/
│ ├── anchor-counter/README.md # Basic counter with delegation
│ ├── delegation-flow/README.md # Full delegation lifecycle
│ ├── vrf-randomness/README.md # VRF integration
│ └── crank-automation/README.md # Scheduled tasks
├── templates/
│ ├── program-template.rs # Rust program starter
│ └── client-template.ts # TypeScript client starter
└── docs/
├── advanced-patterns.md # Complex patterns
└── troubleshooting.md # Common issues
Weekly Installs
54
Repository
GitHub Stars
68
First Seen
Jan 24, 2026
Security Audits
Gen Agent Trust HubFailSocketPassSnykWarn
Installed on
opencode51
codex51
gemini-cli50
github-copilot47
amp46
kimi-cli46
React 组合模式指南:Vercel 组件架构最佳实践,提升代码可维护性
125,600 周安装