Logo
RPC Assistant

What Is Stellar RPC and How to Use It for Your dApp?

摘要

Stellar RPC refers to the remote procedure call interface that allows applications to interact with the Stellar blockchain. Unlike Ethereum, Stellar uses a different API called Horizon, which provides RESTful endpoints for querying the ledger, submitting transactions, and managing accounts. For developers, finding a reliable Stellar RPC provider is key to building production dApps without running full nodes. OnFinality offers Stellar RPC endpoints that abstract infrastructure complexity, giving you scalable access to the Stellar network.

When choosing a Stellar RPC provider, consider factors like rate limits, uptime, and support for Horizon-specific features like streaming endpoints. OnFinality provides both shared and dedicated Stellar nodes, with transparent pricing and multi-region availability, making it a strong choice for developers scaling their Stellar projects.

Stellar RPC Decision Checklist

Before integrating Stellar RPC into your project, evaluate the following points:

  • Horizon vs. Core API: Stellar's primary RPC interface is Horizon, a RESTful API. Ensure your provider offers full Horizon coverage, including streaming endpoints.
  • Rate limits: Check free tier limits and whether paid plans scale with your transaction volume.
  • Network support: Confirm availability for both Stellar Mainnet and Testnet (including the SDF testnet).
  • Node diversity: Running a single Stellar Core node can be a single point of failure. Use a provider that offers load-balanced endpoints.
  • Latency and region: If your dApp is global, choose a provider with multi-region endpoints to reduce latency.
  • Dev tooling: Some providers offer Horizon-specific debugging features like transaction simulation and fee estimation.

What Is Stellar RPC?

Stellar RPC refers to the mechanism by which external applications communicate with the Stellar blockchain. Unlike Ethereum's JSON-RPC, Stellar relies on an API layer called Horizon, which exposes RESTful endpoints for reading ledger state, submitting transactions, and managing accounts. Horizon acts as a bridge between client applications and the Stellar Core network.

If you are building a wallet, decentralized exchange, or payment app on Stellar, you will interact primarily through Horizon. Running your own Horizon instance requires operating a Stellar Core node and additional infrastructure — which many teams prefer to outsource to a managed RPC provider like OnFinality.

Stellar RPC Endpoints and Network Settings

Stellar provides two primary networks: Mainnet and Testnet. The Testnet is ideal for development and testing, while Mainnet handles real assets.

NetworkHorizon URLNetwork Passphrase
Mainnethttps://horizon.stellar.orgPublic Global Stellar Network ; September 2015
Testnethttps://horizon-testnet.stellar.orgTest SDF Network ; September 2015

When using a managed provider like OnFinality, you will receive a custom endpoint that may include load balancing and caching. For example, an OnFinality Stellar endpoint might look like:

https://stellar.onfinality.io/api/v1/horizon

Always verify the exact endpoint from your provider's dashboard.

How to Use Stellar RPC with JavaScript

To interact with Stellar via Horizon, you typically use the stellar-sdk JavaScript library. Here is a basic example of fetching account details:

const StellarSdk = require('stellar-sdk');

// Use your provider's Horizon URL
const server = new StellarSdk.Server('https://stellar.onfinality.io/api/v1/horizon');

async function getAccount(publicKey) {
  try {
    const account = await server.loadAccount(publicKey);
    console.log('Balances:', account.balances);
  } catch (e) {
    console.error('Error loading account:', e);
  }
}

getAccount('G...');

For submitting a transaction:

const StellarSdk = require('stellar-sdk');
const server = new StellarSdk.Server('https://stellar.onfinality.io/api/v1/horizon');

async function submitTx() {
  const account = await server.loadAccount('G...');
  const transaction = new StellarSdk.TransactionBuilder(account, {
    fee: StellarSdk.BASE_FEE,
    networkPassphrase: StellarSdk.Networks.PUBLIC
  })
    .addOperation(StellarSdk.Operation.payment({
      destination: 'G...',
      asset: StellarSdk.Asset.native(),
      amount: '10'
    }))
    .setTimeout(30)
    .build();

  // Sign with your secret key (not shown for security)
  // Send to network
  const result = await server.submitTransaction(transaction);
  console.log('Transaction hash:', result.hash);
}

Stellar Faucet for Testnet

To test your dApp on the Stellar Testnet, you need free test lumens (XLM). The Stellar Development Foundation (SDF) provides a faucet:

  • Friendbot API: https://friendbot.stellar.org/?addr=YOUR_PUBLIC_KEY

Example curl request:

curl "https://friendbot.stellar.org/?addr=G..."

This will fund the account with 10,000 test XLM. Managed RPC providers may also offer their own faucet endpoints for their testnet nodes—check your provider's documentation.

Choosing a Stellar RPC Provider

While running your own Horizon + Stellar Core node is possible, most teams prefer a managed RPC provider to avoid operational overhead. Here's a comparison table to evaluate providers:

CriterionWhat to checkWhy it matters
Uptime SLAPublished uptime guarantees and compensation policiesEnsures your dApp remains available; missing SLAs indicate risk
Rate limitsRequests per second (RPS) and daily/monthly capsHigh-traffic apps need scalable limits
Endpoint diversitySupport for both Mainnet and Testnet, plus custom endpointsSimplifies development and production parity
Horizon feature setFull Horizon endpoints (payments, trades, account details)Missing endpoints break app functionality
Geo-distributionGlobal load balancing or regional optionsReduces latency for users worldwide
Streaming supportServer-sent events (SSE) for real-time updatesEssential for payment tracking and order books
Debugging toolsTransaction simulation, fee estimation endpointsSpeeds up development and error resolution

OnFinality, for example, supports Stellar with dedicated nodes and shared endpoints, offering customizable rate limits and multi-region infrastructure. You can review the full list of supported networks on our networks page and pricing.

Common Pitfalls and Debugging

  • Incorrect network passphrase: Using Mainnet passphrase on Testnet (or vice versa) causes transaction failures. Always double-check.
  • Account not funded: On Testnet, you must fund accounts via Friendbot before using them.
  • Horizon sync delay: Newly submitted transactions may take a few seconds to appear. Use streaming endpoints for real-time feedback.
  • Rate limiting: Free tiers often have low RPS. Monitor your usage and upgrade if needed.

Debugging tip: Use Horizon's transaction submission endpoint to inspect error codes. For example, a 400 response with op_underfunded means the source account lacks XLM.

Key Takeaways

  • Stellar RPC is powered by Horizon, a RESTful API that provides access to the Stellar network.
  • For production dApps, use a managed RPC provider to handle node operations, load balancing, and uptime.
  • Evaluate providers based on endpoint coverage, rate limits, geographic distribution, and support for streaming.
  • Always test on Stellar Testnet using Friendbot before deploying to Mainnet.
  • OnFinality offers Stellar RPC endpoints as part of a broader multi-chain RPC service with transparent pricing.

Frequently Asked Questions

Can I use Ethereum JSON-RPC to interact with Stellar? No. Stellar uses the Horizon REST API, not Ethereum's JSON-RPC. You must use Horizon endpoints and the stellar-sdk or raw REST calls.

Does OnFinality support Stellar Testnet? Yes, OnFinality provides endpoints for both Stellar Mainnet and Testnet. Check the network details page for exact URLs.

How do I get free XLM for testing? Use the SDF Friendbot or your provider's own faucet. OnFinality does not currently offer a faucet but supports the public Friendbot.

What are the rate limits for free Stellar RPC? Free tiers typically allow a few requests per second. For higher limits, consider a dedicated node plan. See our pricing page for details.

Can I run a dedicated Stellar node with OnFinality? Yes, OnFinality offers dedicated Stellar nodes with custom configurations and priority support.

RPC 知识库

相关 RPC 内容

Rpc Provider Selection

能否比较一下Solana RPC服务的专用节点与共享节点接入方案?

# 能否比较一下Solana RPC服务的专用节点与共享节点接入方案? 共享Solana RPC是许多团队的实际起点,因为它采用更快且运营成本更低。专用Solana节点接入在应用需要隔离、可预测吞吐量或运营控制时是更强的选择。决策应基于工作负载形态,而不仅仅是预期的请求数量。...

Rpc Provider Selection

Sui RPC 节点:端点设置、提供商选择与最佳实践

Sui RPC 节点是一个 API 端点,允许您的应用程序在不运行自己的全节点的情况下读取和写入 Sui 区块链。本文介绍如何连接到 Sui RPC 端点、选择提供商时需要注意的事项,以及生产环境中应避免的常见陷阱。...

Network Rpc

关于xx网络,我需要了解什么?

# 关于xx网络,我需要了解什么? xx网络是一个抗量子计算的Layer 1区块链,集成了去中心化混合网络(cMix)用于私密通信。由密码学先驱David Chaum创立,采用提名权益证明(NPoS)共识机制,为dApp和消息传递提供低费用、可扩展的基础设施。对于开发者而言,可靠的RPC端点和专用节...

Testnet Rpc

团队应如何使用 Polygon 测试网 RPC 进行发布?

# 团队应如何使用 Polygon 测试网 RPC 进行发布? Polygon 测试网 RPC 之所以重要,是因为 Web3 应用依赖稳定的端点访问来进行读取、交易、仪表盘和后端工作流。正确的设置应匹配你的工作负载,支持你所需的网络和测试网,使限制可见,并在共享 RPC 不再足够时提供扩展路径。 对...

Rpc Provider Selection

如何为生产级 dApp 选择合适的 Avalanche RPC 提供商

选择合适的 Avalanche RPC 提供商对于 dApp 的性能、可靠性和成本至关重要。本文涵盖了关键评估标准——延迟、吞吐量、归档支持和定价模型——并帮助您比较 C 链、X 链、P 链和子网的提供商。无论您需要共享公共端点还是专用节点,我们都会概述在投入生产基础设施之前需要检查的内容。...

Testnet Rpc

什么是BNB Chain测试网,如何在开发中使用它?

BNB Chain测试网(链ID 97)是一个公共的EVM兼容测试网络,镜像了BNB Smart Chain主网。开发者可以在不冒真实资金风险的情况下部署和测试智能合约、dApp以及跨链集成。本文涵盖链配置、水龙头、RPC端点、常见陷阱以及决策清单,帮助您快速上手。...

永远不用担心基础设施

OnFinality 消除了 DevOps 的繁重工作,让您能够更聪明、更快地构建。

开始