Logo
新用户订阅 RPC,首月享 6.5 折优惠查看优惠
RPC Assistant

Fantom API: Methods, Endpoints, and How to Start Building

摘要

The Fantom API provides JSON-RPC methods for interacting with the Fantom Opera blockchain, covering balances, transactions, event logs, gas estimation, and debugging. This reference covers public endpoints, supported methods, and how to connect reliably for production dApps.

Fantom API Decision Checklist

Before integrating the Fantom API, evaluate these key factors:

CriterionWhat to checkWhy it matters
Endpoint typePublic vs. private vs. dedicatedPublic endpoints are rate-limited and unreliable for production; private or dedicated nodes provide consistent performance.
API coverageEthereum JSON-RPC, Fantom-specific methods, Debug/TraceEnsure the provider supports the methods your dApp needs (e.g., eth_call, ftm_getBalance, debug_traceTransaction).
WebSocket supportReal-time event subscriptionsRequired for order books, transaction monitoring, and live updates.
Archive dataAccess to historical stateNeeded for analytics, historical queries, and certain dApps like explorers.
Rate limitsRequests per second (RPS) allowedLow limits can break your app during traffic spikes.
Fallback & redundancyMultiple endpoints, failoverPrevents downtime if one endpoint goes offline.

What Is the Fantom API?

The Fantom API refers to the set of RPC (Remote Procedure Call) interfaces used to interact with the Fantom Opera blockchain. Because Fantom is Ethereum Virtual Machine (EVM) compatible, its API is largely identical to the standard Ethereum JSON-RPC API, with a few Fantom-specific extensions. Developers use these methods to read blockchain state, send transactions, deploy smart contracts, and subscribe to events.

Fantom also provides a GraphQL API (see fantom-api-graphql on GitHub) for aggregated chain data, but the JSON-RPC API remains the primary interface for direct node interaction.

Fantom API Endpoints

Public Endpoints

Fantom offers free public endpoints for testing and light usage:

  • HTTPS: https://rpc.fantom.network
  • WebSocket: wss://ws.fantom.network

These are shared and rate-limited (typically around 10–100 requests per second). They often fail under heavy load or during network congestion. For production apps, you should use a private endpoint from an RPC provider or run your own node.

Private / Dedicated Endpoints

RPC providers like OnFinality offer dedicated Fantom API endpoints with:

  • Higher or clear rate limits
  • Archive data support
  • WebSocket connections
  • Global load balancing

You can find Fantom among the supported networks on OnFinality's network page.

Fantom API Methods

Fantom supports standard Ethereum JSON-RPC methods plus Fantom-specific ones. Below are the most commonly used categories.

Account & Balance

  • eth_getBalance – Returns the FTM balance of an address.
  • eth_getTransactionCount – Returns the number of transactions sent from an address.
  • ftm_getAccount (Fantom-specific) – Returns full account state including delegations.

Block & Chain Information

  • eth_blockNumber – Latest block number.
  • eth_getBlockByNumber / eth_getBlockByHash – Block details.
  • eth_chainId – Returns chain ID (250 for Fantom mainnet).

Transactions & Execution

  • eth_sendRawTransaction – Submits a signed transaction.
  • eth_getTransactionReceipt – Gets receipt for a transaction.
  • eth_call – Executes a read-only contract call.
  • eth_estimateGas – Estimates gas for a transaction.

Events & Logs

  • eth_getLogs – Retrieves event logs matching a filter.
  • eth_newFilter / eth_getFilterChanges – Polling-based event subscriptions.

Debug & Trace

  • debug_traceTransaction – Full EVM execution trace (if provider supports it).
  • debug_traceBlockByNumber – Traces all transactions in a block.
  • trace_call / trace_replayTransaction (OpenEthereum-style trace) – Available on some providers.

Getting Started with the Fantom API

1. Choose Your Connection Method

You can call the API via HTTPS or WebSocket. Below is a Node.js example using axios.

const axios = require('axios');

const endpoint = 'https://rpc.fantom.network'; // Replace with your private endpoint

async function getBalance(address) {
  const payload = {
    jsonrpc: '2.0',
    method: 'eth_getBalance',
    params: [address, 'latest'],
    id: 1
  };

  try {
    const response = await axios.post(endpoint, payload);
    const balanceWei = response.data.result;
    const balanceFtm = parseInt(balanceWei, 16) / 1e18;
    console.log(`Balance: ${balanceFtm} FTM`);
  } catch (error) {
    console.error('Error:', error);
  }
}

getBalance('0x...');

2. Connect via WebSocket (for real-time events)

const WebSocket = require('ws');

const ws = new WebSocket('wss://ws.fantom.network'); // Replace with your WebSocket endpoint

ws.on('open', function open() {
  ws.send(JSON.stringify({
    jsonrpc: '2.0',
    method: 'eth_subscribe',
    params: ['newHeads'],
    id: 1
  }));
});

ws.on('message', function incoming(data) {
  console.log('New block:', JSON.parse(data).params.result);
});

Fantom API vs. Ethereum API

Fantom is EVM-compatible, so the vast majority of Ethereum methods work unchanged. However, there are a few differences:

  • Gas model: Fantom uses a fixed gas price (usually 1 gwei) and lower gas limits.
  • Finality: Fantom achieves finality in ~1 second, so transaction receipts are available almost immediately.
  • Staking: Fantom-specific methods like ftm_getDelegations and ftm_getRewards are not part of the Ethereum API.
  • Chain ID: 250 (mainnet), 4002 (testnet).

Choosing a Fantom API Provider

Public vs. Private vs. Dedicated

  • Public endpoints – Free but unreliable for production. Use for quick prototyping only.
  • Private shared endpoints – Provided by services like OnFinality as part of an RPC plan. Higher rate limits and better uptime.
  • Dedicated nodes – A full Fantom node provisioned just for your project. Maximum performance and customization.

To evaluate providers, compare the criteria from the checklist above. For production, look for providers that support WebSocket, archive data, and trace methods if needed. OnFinality offers both shared and dedicated Fantom endpoints. Check current pricing and network availability.

Common Issues and Troubleshooting

Rate Limiting

Public endpoints return 429 Too Many Requests when exceeded. Solution: upgrade to a private endpoint or implement retry logic.

WebSocket Disconnections

Public WebSocket endpoints may drop idle connections. Use keep-alive pings or your own WebSocket management.

Missing Methods

Not all providers enable Debug/Trace methods. Verify your provider's supported methods list.

Chain ID Mismatch

Ensure your wallet or dApp is configured to chain ID 250 (Fantom mainnet) and not 4002 (testnet) or another chain.

Key Takeaways

  • The Fantom API is EVM-compatible but includes unique methods for staking and fast finality.
  • Public endpoints are only suitable for testing; use private or dedicated endpoints for production.
  • WebSocket support is essential for real-time applications.
  • Evaluate providers on rate limits, archive data, WebSocket, and Debug/Trace support.

Frequently Asked Questions

What is the Fantom API? The Fantom API is a JSON-RPC interface for interacting with the Fantom Opera blockchain. It includes standard Ethereum methods and Fantom-specific extensions.

Is the Fantom API free? Public endpoints are free but rate-limited. For production, you typically pay for a private endpoint or dedicated node.

Does Fantom support WebSocket? Yes. WebSocket endpoints are available for real-time subscriptions (e.g., eth_subscribe).

What is the chain ID for Fantom mainnet? 250.

Can I use Ethereum libraries (ethers.js, web3.js) with Fantom? Yes. Because Fantom is EVM-compatible, you can use the same libraries after changing the RPC endpoint and chain ID.

How do I get Fantom testnet tokens? The Fantom testnet faucet is available at faucet.fantom.network.

What providers offer Fantom API access? Many RPC providers support Fantom, including OnFinality. Visit OnFinality's network list to see current support.

RPC 知识库

相关 RPC 内容

区块链基础设施Efinity

什么是TON全节点,何时应该运行一个?

TON全节点存储完整的区块链状态并验证The Open Network的交易。运行一个全节点可以让您直接访问TON数据,无需中间人,但需要大量的硬件、存储和持续的维护。本文解释了TON全节点的功能、运行与租用基础设施的权衡,以及如何决定哪种方法适合您的项目。...

RPC 提供商选择Efinity

评估以太坊 RPC 节点提供商时应该考虑哪些方面?

以太坊 RPC 节点提供商负责运行和维护以太坊节点,使你的应用可以通过 JSON-RPC 读取链上状态并广播交易,而无需自行运行客户端软件。合适的提供商取决于你的工作负载:读密集型 dapp、索引器、交易机器人和跨链桥各自对不同的方法和传输方式有不同压力。OnFinality 提供以太坊 RPC A...

网络 RPCpeaq

Peaq RPC:如何连接DePIN Layer 1

# Peaq RPC:如何连接DePIN Layer 1 Peaq 是一个基于 Substrate 构建的 Layer 1 区块链,作为 Polkadot 平行链运行,专为去中心化物理基础设施网络(DePIN)和机器经济设计。它提供双执行环境——兼容 EVM 的智能合约和 Substrate pal...

RPC 提供商选择Solana

哪些 Solana RPC 提供商为生产应用提供专用节点?

Solana 的吞吐量和账户模型对 RPC 基础设施造成了异常压力,因此那些超出共享端点承载能力的团队通常会转向专用节点。专用 Solana 节点为您自己的工作负载提供隔离的计算和带宽,而不是在共享池中与其他租户竞争。本文解释了如何评估提供专用 Solana 节点的提供商、在承诺之前需要测试什么,以...

网络 RPCAvalanche

Sonic 网络 RPC:链设置、端点和提供商选择

Sonic 是一个高性能的 EVM 兼容 Layer-1 区块链,具有亚秒级最终性。本页涵盖官方 Sonic 网络 RPC 设置、如何连接您的钱包或 dApp,以及如何评估用于生产环境的 RPC 提供商。我们还解释了何时选择托管或专用的 Sonic RPC 端点是正确的选择。...

网络 RPCSORA

什么是SORA网络?

SORA是一个专注于创建去中心化货币系统的区块链网络。它使用XOR代币和链上治理,让代币持有者决定如何分配资源。该网络正在演变为基于Hyperledger Iroha 3构建的SORA Nexus,旨在为CBDC和DeFi实现快速最终性和互操作性。对于开发者来说,访问可靠的RPC端点是构建在SORA...

永远不用担心基础设施

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

开始