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 内容

RPC 提供商选择Solana

Solana RPC 提供商对比:您应该关注什么?

选择 Solana RPC 提供商意味着要根据您的应用需求权衡吞吐量、可靠性、数据访问和成本。本对比聚焦于区分公共、共享和专用 Solana RPC 服务的关键技术和运营因素,帮助您根据对生产工作负载真正重要的标准来评估提供商。...

区块链基础设施Kusama

Kusama 验证人:要求、设置和运营权衡

了解运行 Kusama 验证人所需的条件,从硬件和质押要求到节点设置和持续运营。比较自托管与托管基础设施,并了解风险,包括削减和佣金。为新手和经验丰富的验证人提供实用指导。...

网络 RPCAvalanche

Crust Network 质押:GPoS 如何运作以及质押 CRU 前需要检查什么

Crust Network 是一个基于 Substrate 的 layer-1 区块链,提供去中心化的 IPFS 存储。其 GPoS(担保权益证明)共识将质押权力与存储资源挂钩,因此验证人和担保人质押 CRU 来保护网络安全并获得奖励。本文解释了质押如何运作、在选择验证人或提供商之前需要评估什么,以...

网络 RPCOptimism

选择 Optimism RPC 提供商时应该关注什么?

# 选择 Optimism RPC 提供商时应该关注什么? Optimism RPC 提供商之所以重要,是因为 Web3 应用依赖稳定的端点访问来进行读取、交易、仪表盘和后端工作流。合适的设置应匹配你的工作负载,支持你所需的网络和测试网,让限制透明可见,并在共享 RPC 不再够用时提供扩展路径。 对...

网络 RPCCelo

Celo 主网和测试网的 RPC 端点是什么?

Celo RPC 端点允许开发者连接到 Celo 区块链。主网链 ID 为 42220,测试网(Celo Sepolia)链 ID 为 11142220。存在免费的公共端点,但有速率限制;对于生产应用,请考虑使用如 OnFinality 等专用 RPC 提供商。...

RPC 提供商选择Starknet

如何为你的 dApp 选择合适的 Starknet RPC 提供商

# 如何为你的 dApp 选择合适的 Starknet RPC 提供商 Starknet 是以太坊上的一个有效性 Rollup(ZK-rollup),提供高吞吐量、低 Gas 成本和以太坊级别的安全性。要与 Starknet 交互,你的 dApp 需要一个可靠的 RPC(远程过程调用)提供商。本指南...

永远不用担心基础设施

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

开始