helius
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseHelius Solana Infrastructure Expert
Helius Solana基础设施专家
Helius provides high-performance Solana RPC, real-time data streaming, and developer APIs.
Helius提供高性能的Solana RPC、实时数据流以及开发者API。
When to Use
适用场景
- Setting up Solana RPC infrastructure
- Querying NFT/token metadata (DAS API)
- Real-time blockchain data (LaserStream, WebSockets, webhooks)
- Transaction optimization and priority fees
- ZK Compression for cost reduction
- 搭建Solana RPC基础设施
- 查询NFT/代币元数据(DAS API)
- 获取实时区块链数据(LaserStream、WebSocket、Webhooks)
- 交易优化与优先费用设置
- 利用ZK压缩降低成本
Quick Start
快速开始
- Get API key: https://dashboard.helius.dev
- Use RPC URL:
https://mainnet.helius-rpc.com/?api-key=YOUR_API_KEY
bash
curl https://mainnet.helius-rpc.com/?api-key=YOUR_KEY \
-X POST -H "Content-Type: application/json" \
-d '{"jsonrpc":"2.0","id":1,"method":"getBalance","params":["YOUR_WALLET"]}'- 获取API密钥:https://dashboard.helius.dev
- 使用RPC URL:
https://mainnet.helius-rpc.com/?api-key=YOUR_API_KEY
bash
curl https://mainnet.helius-rpc.com/?api-key=YOUR_KEY \
-X POST -H "Content-Type: application/json" \
-d '{"jsonrpc":"2.0","id":1,"method":"getBalance","params":["YOUR_WALLET"]}'Core Services
核心服务
RPC Endpoints
RPC节点
javascript
// Mainnet
const RPC_URL = `https://mainnet.helius-rpc.com/?api-key=${API_KEY}`;
// Devnet
const DEVNET_URL = `https://devnet.helius-rpc.com/?api-key=${API_KEY}`;javascript
// 主网
const RPC_URL = `https://mainnet.helius-rpc.com/?api-key=${API_KEY}`;
// 测试网
const DEVNET_URL = `https://devnet.helius-rpc.com/?api-key=${API_KEY}`;Digital Asset Standard (DAS) API
Digital Asset Standard (DAS) API
Query NFT and token metadata - handles both regular and compressed NFTs.
Get Single Asset:
javascript
const response = await fetch(RPC_URL, {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({
jsonrpc: '2.0',
id: 1,
method: 'getAsset',
params: { id: 'ASSET_MINT_ADDRESS' }
})
});Get Assets by Owner:
javascript
const response = await fetch(RPC_URL, {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({
jsonrpc: '2.0',
id: 1,
method: 'getAssetsByOwner',
params: {
ownerAddress: 'WALLET_ADDRESS',
page: 1,
limit: 100
}
})
});DAS Methods:
| Method | Description |
|---|---|
| Single asset metadata |
| Batch asset retrieval |
| All assets for wallet |
| Assets by creator |
| Assets in collection |
查询NFT和代币元数据 - 支持常规NFT和压缩NFT。
获取单个资产:
javascript
const response = await fetch(RPC_URL, {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({
jsonrpc: '2.0',
id: 1,
method: 'getAsset',
params: { id: 'ASSET_MINT_ADDRESS' }
})
});按所有者获取资产:
javascript
const response = await fetch(RPC_URL, {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({
jsonrpc: '2.0',
id: 1,
method: 'getAssetsByOwner',
params: {
ownerAddress: 'WALLET_ADDRESS',
page: 1,
limit: 100
}
})
});DAS方法:
| 方法 | 说明 |
|---|---|
| 单资产元数据 |
| 批量资产获取 |
| 钱包下所有资产 |
| 按创作者筛选资产 |
| 集合内资产 |
Enhanced Transactions API
增强型交易API
Pre-parsed transaction data in human-readable format.
javascript
const response = await fetch(RPC_URL, {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({
jsonrpc: '2.0',
id: 1,
method: 'getTransactionsForAddress',
params: [
'WALLET_ADDRESS',
{
transactionDetails: 'full',
sortOrder: 'desc',
limit: 10
}
]
})
});提供预解析的人类可读格式交易数据。
javascript
const response = await fetch(RPC_URL, {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({
jsonrpc: '2.0',
id: 1,
method: 'getTransactionsForAddress',
params: [
'WALLET_ADDRESS',
{
transactionDetails: 'full',
sortOrder: 'desc',
limit: 10
}
]
})
});Priority Fee API
Priority Fee API
Get optimal priority fees for fast transaction landing.
javascript
const response = await fetch(RPC_URL, {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({
jsonrpc: '2.0',
id: 1,
method: 'getPriorityFeeEstimate',
params: [{
accountKeys: ['PROGRAM_ID', 'ACCOUNT_1', 'ACCOUNT_2']
}]
})
});
const { priorityFeeEstimate } = await response.json();
// Returns: { low, medium, high, veryHigh } in microlamports获取最优优先费用,确保交易快速上链。
javascript
const response = await fetch(RPC_URL, {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({
jsonrpc: '2.0',
id: 1,
method: 'getPriorityFeeEstimate',
params: [{
accountKeys: ['PROGRAM_ID', 'ACCOUNT_1', 'ACCOUNT_2']
}]
})
});
const { priorityFeeEstimate } = await response.json();
// 返回结果:{ low, medium, high, veryHigh },单位为微lamportLaserStream (Real-Time gRPC)
LaserStream(实时gRPC)
Ultra-low latency blockchain streaming. Drop-in replacement for Yellowstone gRPC.
typescript
import { LaserStream } from '@helius-labs/laserstream';
const stream = new LaserStream({
apiKey: 'YOUR_API_KEY',
region: 'fra' // fra, ams, tyo, sg, ewr, pitt, slc, lax, lon
});
// Subscribe to account changes
stream.subscribeAccount('ACCOUNT_ADDRESS', (update) => {
console.log('Account updated:', update);
});
// Subscribe to program transactions
stream.subscribeProgram('PROGRAM_ID', (tx) => {
console.log('Program transaction:', tx);
});Regions: FRA, AMS, TYO, SG, EWR, PITT, SLC, LAX, LON
超低延迟区块链流服务,可直接替代Yellowstone gRPC。
typescript
import { LaserStream } from '@helius-labs/laserstream';
const stream = new LaserStream({
apiKey: 'YOUR_API_KEY',
region: 'fra' // fra, ams, tyo, sg, ewr, pitt, slc, lax, lon
});
// 订阅账户变更
stream.subscribeAccount('ACCOUNT_ADDRESS', (update) => {
console.log('账户更新:', update);
});
// 订阅程序交易
stream.subscribeProgram('PROGRAM_ID', (tx) => {
console.log('程序交易:', tx);
});可用区域: FRA、AMS、TYO、SG、EWR、PITT、SLC、LAX、LON
Webhooks
Webhooks
Event-driven notifications for blockchain activity.
javascript
// Create webhook via API
const webhook = await fetch('https://api.helius.xyz/v0/webhooks', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'Authorization': `Bearer ${API_KEY}`
},
body: JSON.stringify({
webhookURL: 'https://your-server.com/webhook',
transactionTypes: ['NFT_SALE', 'TOKEN_TRANSFER'],
accountAddresses: ['ADDRESS_TO_WATCH']
})
});Webhook Types:
- Account changes
- Transaction confirmations
- Program events
- NFT activity
针对区块链活动的事件驱动通知。
javascript
// 通过API创建Webhook
const webhook = await fetch('https://api.helius.xyz/v0/webhooks', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'Authorization': `Bearer ${API_KEY}`
},
body: JSON.stringify({
webhookURL: 'https://your-server.com/webhook',
transactionTypes: ['NFT_SALE', 'TOKEN_TRANSFER'],
accountAddresses: ['ADDRESS_TO_WATCH']
})
});Webhook类型:
- 账户变更
- 交易确认
- 程序事件
- NFT活动
ZK Compression
ZK压缩
Reduce on-chain storage costs by up to 98%.
javascript
// Get compressed account
const response = await fetch(RPC_URL, {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({
jsonrpc: '2.0',
id: 1,
method: 'getCompressedAccount',
params: { address: 'COMPRESSED_ACCOUNT' }
})
});
// Get compressed token balances
const balances = await fetch(RPC_URL, {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({
jsonrpc: '2.0',
id: 1,
method: 'getCompressedTokenBalancesByOwner',
params: { owner: 'WALLET_ADDRESS' }
})
});可将链上存储成本降低高达98%。
javascript
// 获取压缩账户
const response = await fetch(RPC_URL, {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({
jsonrpc: '2.0',
id: 1,
method: 'getCompressedAccount',
params: { address: 'COMPRESSED_ACCOUNT' }
})
});
// 获取压缩代币余额
const balances = await fetch(RPC_URL, {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({
jsonrpc: '2.0',
id: 1,
method: 'getCompressedTokenBalancesByOwner',
params: { owner: 'WALLET_ADDRESS' }
})
});Pricing & Rate Limits
定价与速率限制
| Plan | Price | Credits | Rate Limit | DAS Limit |
|---|---|---|---|---|
| Free | $0/mo | 1M | 10 RPS | 2 RPS |
| Developer | $49/mo | 10M | 50 RPS | 10 RPS |
| Business | $499/mo | 100M | 200 RPS | 50 RPS |
| Professional | $999/mo | 200M | 500 RPS | 100 RPS |
Feature Availability:
| Feature | Free | Developer | Business | Professional |
|---|---|---|---|---|
| Shared RPC | Yes | Yes | Yes | Yes |
| LaserStream (Devnet) | - | Yes | Yes | Yes |
| LaserStream (Mainnet) | - | - | - | Yes |
| Enhanced WebSockets | - | - | Yes | Yes |
| 方案 | 价格 | 调用额度 | 速率限制 | DAS调用限制 |
|---|---|---|---|---|
| 免费版 | $0/月 | 100万次 | 10次/秒 | 2次/秒 |
| 开发者版 | $49/月 | 1000万次 | 50次/秒 | 10次/秒 |
| 企业版 | $499/月 | 1亿次 | 200次/秒 | 50次/秒 |
| 专业版 | $999/月 | 2亿次 | 500次/秒 | 100次/秒 |
功能可用性:
| 功能 | 免费版 | 开发者版 | 企业版 | 专业版 |
|---|---|---|---|---|
| 共享RPC | 是 | 是 | 是 | 是 |
| LaserStream(测试网) | - | 是 | 是 | 是 |
| LaserStream(主网) | - | - | - | 是 |
| 增强型WebSocket | - | - | 是 | 是 |
Error Handling
错误处理
javascript
try {
const response = await fetch(RPC_URL, { method: 'POST', ... });
// Check rate limits
const remaining = response.headers.get('X-RateLimit-Remaining');
const reset = response.headers.get('X-RateLimit-Reset');
if (response.status === 429) {
// Rate limited - wait and retry
await new Promise(r => setTimeout(r, 1000));
return retry();
}
const data = await response.json();
if (data.error) {
console.error(`RPC Error ${data.error.code}: ${data.error.message}`);
}
return data.result;
} catch (err) {
// Network error - retry with backoff
}javascript
try {
const response = await fetch(RPC_URL, { method: 'POST', ... });
// 检查速率限制
const remaining = response.headers.get('X-RateLimit-Remaining');
const reset = response.headers.get('X-RateLimit-Reset');
if (response.status === 429) {
// 触发速率限制 - 等待后重试
await new Promise(r => setTimeout(r, 1000));
return retry();
}
const data = await response.json();
if (data.error) {
console.error(`RPC错误 ${data.error.code}: ${data.error.message}`);
}
return data.result;
} catch (err) {
// 网络错误 - 退避重试
}Best Practices
最佳实践
DO:
- Use commitment for faster responses
confirmed - Use DAS API for NFT queries (not raw )
getAccountInfo - Simulate transactions before sending
- Use for dynamic fees
getPriorityFeeEstimate - Check rate limit headers
DON'T:
- Poll for real-time data (use WebSockets/LaserStream)
- Hardcode priority fees
- Ignore rate limits
- Skip transaction simulation
建议:
- 使用提交方式以获得更快响应
confirmed - 查询NFT时使用DAS API(而非原生)
getAccountInfo - 发送前模拟交易
- 使用设置动态费用
getPriorityFeeEstimate - 检查速率限制头信息
不建议:
- 轮询获取实时数据(使用WebSocket/LaserStream)
- 硬编码优先费用
- 忽略速率限制
- 跳过交易模拟
Common Patterns
常见模式
Wallet Portfolio
钱包资产组合
javascript
async function getWalletPortfolio(wallet) {
// Get all assets (NFTs + tokens)
const assets = await fetch(RPC_URL, {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({
jsonrpc: '2.0',
id: 1,
method: 'getAssetsByOwner',
params: { ownerAddress: wallet, page: 1, limit: 1000 }
})
}).then(r => r.json());
// Get SOL balance
const balance = await fetch(RPC_URL, {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({
jsonrpc: '2.0',
id: 1,
method: 'getBalance',
params: [wallet]
})
}).then(r => r.json());
return {
solBalance: balance.result.value / 1e9,
assets: assets.result.items
};
}javascript
async function getWalletPortfolio(wallet) {
// 获取所有资产(NFT+代币)
const assets = await fetch(RPC_URL, {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({
jsonrpc: '2.0',
id: 1,
method: 'getAssetsByOwner',
params: { ownerAddress: wallet, page: 1, limit: 1000 }
})
}).then(r => r.json());
// 获取SOL余额
const balance = await fetch(RPC_URL, {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({
jsonrpc: '2.0',
id: 1,
method: 'getBalance',
params: [wallet]
})
}).then(r => r.json());
return {
solBalance: balance.result.value / 1e9,
assets: assets.result.items
};
}Transaction with Priority Fee
带优先费用的交易
javascript
async function sendWithPriorityFee(transaction, accounts) {
// Get priority fee estimate
const feeEstimate = await fetch(RPC_URL, {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({
jsonrpc: '2.0',
id: 1,
method: 'getPriorityFeeEstimate',
params: [{ accountKeys: accounts }]
})
}).then(r => r.json());
// Add compute budget instruction with priority fee
const priorityFee = feeEstimate.result.priorityFeeEstimate.high;
// Simulate first
const simulation = await fetch(RPC_URL, {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({
jsonrpc: '2.0',
id: 1,
method: 'simulateTransaction',
params: [transaction, { commitment: 'confirmed' }]
})
}).then(r => r.json());
if (simulation.result.err) {
throw new Error(`Simulation failed: ${JSON.stringify(simulation.result.err)}`);
}
// Send transaction
return fetch(RPC_URL, {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({
jsonrpc: '2.0',
id: 1,
method: 'sendTransaction',
params: [transaction, { skipPreflight: true }]
})
}).then(r => r.json());
}javascript
async function sendWithPriorityFee(transaction, accounts) {
// 获取优先费用预估
const feeEstimate = await fetch(RPC_URL, {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({
jsonrpc: '2.0',
id: 1,
method: 'getPriorityFeeEstimate',
params: [{ accountKeys: accounts }]
})
}).then(r => r.json());
// 添加计算预算指令并设置优先费用
const priorityFee = feeEstimate.result.priorityFeeEstimate.high;
// 先模拟交易
const simulation = await fetch(RPC_URL, {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({
jsonrpc: '2.0',
id: 1,
method: 'simulateTransaction',
params: [transaction, { commitment: 'confirmed' }]
})
}).then(r => r.json());
if (simulation.result.err) {
throw new Error(`模拟失败: ${JSON.stringify(simulation.result.err)}`);
}
// 发送交易
return fetch(RPC_URL, {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({
jsonrpc: '2.0',
id: 1,
method: 'sendTransaction',
params: [transaction, { skipPreflight: true }]
})
}).then(r => r.json());
}Resources
资源
- Helius Docs: https://www.helius.dev/docs
- Dashboard: https://dashboard.helius.dev
- Discord: https://discord.gg/helius
- Helius文档: https://www.helius.dev/docs
- 控制台: https://dashboard.helius.dev
- Discord社区: https://discord.gg/helius
Pull Local Docs
拉取本地文档
bash
pipx install docpull
docpull https://www.helius.dev/docs -o .claude/skills/helius/docsbash
pipx install docpull
docpull https://www.helius.dev/docs -o .claude/skills/helius/docs