mcpField
H
helius

helius

github.com/raintree-technology开发70 次安装
代码仓库

关于 helius

面向使用 Helius Solana 基础设施的开发者,介绍 RPC、资产与交易 API、数据流、Webhook 和 ZK Compression,并提供常见链上数据及交易任务的示例与指导。

主要功能

  1. 01Solana RPC 端点
  2. 02通过 DAS 查询 NFT 和代币元数据
  3. 03解析后的交易数据
  4. 04LaserStream 与 WebSocket 实时数据流
  5. 05区块链活动 Webhook
  6. 06ZK Compression

适用场景

  1. 01查询 NFT 和代币资产
  2. 02订阅账户变更数据流
  3. 03接收交易和程序事件通知
  4. 04估算交易优先费

安装

复制下面的命令,在终端中运行。

$npx skills add https://github.com/raintree-technology/claude-starter --skill helius

安装后在 Claude Code 中输入/helius确认已加载。

附带文件.gitignore

详细介绍

Helius Solana 基础设施专家

Helius 提供高性能的 Solana RPC、实时数据流和开发者 API。

使用场景

  • 搭建 Solana RPC 基础设施
  • 查询 NFT/代币元数据(DAS API)
  • 获取实时区块链数据(LaserStream、WebSockets、webhooks)
  • 优化交易和优先费
  • 使用 ZK Compression 降低成本

快速开始

  1. 获取 API 密钥:https://dashboard.helius.dev
  2. 使用 RPC URL:https://mainnet.helius-rpc.com/?api-key=YOUR_API_KEY
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"]}'

核心服务

RPC 端点
// 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}`;
数字资产标准(DAS)API

查询 NFT 和代币元数据,支持常规 NFT 和压缩 NFT。

获取单个资产:

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' }
  })
});

按所有者获取资产:

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集合中的资产
增强型交易 API

提供预解析的交易数据,格式易于阅读。

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
      }
    ]
  })
});
优先费 API

获取最优优先费,加快交易上链。

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
LaserStream(实时 gRPC)

超低延迟的区块链数据流。可直接替代 Yellowstone gRPC。

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);
});

区域: FRA、AMS、TYO、SG、EWR、PITT、SLC、LAX、LON

Webhooks

针对区块链活动的事件驱动通知。

// 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 类型:

  • 账户变更
  • 交易确认
  • 程序事件
  • NFT 活动
ZK Compression

将链上存储成本最多降低 98%。

// 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' }
  })
});

定价与速率限制

方案价格积分速率限制DAS 限制
免费$0/mo1M10 RPS2 RPS
开发者$49/mo10M50 RPS10 RPS
商业$499/mo100M200 RPS50 RPS
专业$999/mo200M500 RPS100 RPS

功能可用性:

功能免费开发者商业专业
共享 RPC是是是是
LaserStream(Devnet)-是是是
LaserStream(Mainnet)---是
增强型 WebSockets--是是

错误处理

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
}

最佳实践

建议:

  • 使用 confirmed commitment 以获得更快响应
  • 使用 DAS API 查询 NFT(不要使用原始 getAccountInfo)
  • 发送交易前先进行模拟
  • 使用 getPriorityFeeEstimate 获取动态费用
  • 检查速率限制标头

避免:

  • 轮询获取实时数据(使用 WebSockets/LaserStream)
  • 对优先费进行硬编码
  • 忽略速率限制
  • 跳过交易模拟

常见模式

钱包资产组合
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
  };
}
带优先费的交易
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());
}

资源

拉取本地文档
pipx install docpull
docpull https://www.helius.dev/docs -o .claude/skills/helius/docs

评论

支持 Markdown