helius

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

Helius 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

快速开始

  1. Get API key: https://dashboard.helius.dev
  2. 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"]}'
  1. 获取API密钥:https://dashboard.helius.dev
  2. 使用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:
MethodDescription
getAsset
Single asset metadata
getAssetBatch
Batch asset retrieval
getAssetsByOwner
All assets for wallet
getAssetsByCreator
Assets by creator
getAssetsByGroup
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方法:
方法说明
getAsset
单资产元数据
getAssetBatch
批量资产获取
getAssetsByOwner
钱包下所有资产
getAssetsByCreator
按创作者筛选资产
getAssetsByGroup
集合内资产

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 },单位为微lamport

LaserStream (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

定价与速率限制

PlanPriceCreditsRate LimitDAS Limit
Free$0/mo1M10 RPS2 RPS
Developer$49/mo10M50 RPS10 RPS
Business$499/mo100M200 RPS50 RPS
Professional$999/mo200M500 RPS100 RPS
Feature Availability:
FeatureFreeDeveloperBusinessProfessional
Shared RPCYesYesYesYes
LaserStream (Devnet)-YesYesYes
LaserStream (Mainnet)---Yes
Enhanced WebSockets--YesYes
方案价格调用额度速率限制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
    confirmed
    commitment for faster responses
  • Use DAS API for NFT queries (not raw
    getAccountInfo
    )
  • Simulate transactions before sending
  • Use
    getPriorityFeeEstimate
    for dynamic fees
  • 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

资源

Pull Local Docs

拉取本地文档

bash
pipx install docpull
docpull https://www.helius.dev/docs -o .claude/skills/helius/docs
bash
pipx install docpull
docpull https://www.helius.dev/docs -o .claude/skills/helius/docs