Summary
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:
| Criterion | What to check | Why it matters |
|---|---|---|
| Endpoint type | Public vs. private vs. dedicated | Public endpoints are rate-limited and unreliable for production; private or dedicated nodes provide consistent performance. |
| API coverage | Ethereum JSON-RPC, Fantom-specific methods, Debug/Trace | Ensure the provider supports the methods your dApp needs (e.g., eth_call, ftm_getBalance, debug_traceTransaction). |
| WebSocket support | Real-time event subscriptions | Required for order books, transaction monitoring, and live updates. |
| Archive data | Access to historical state | Needed for analytics, historical queries, and certain dApps like explorers. |
| Rate limits | Requests per second (RPS) allowed | Low limits can break your app during traffic spikes. |
| Fallback & redundancy | Multiple endpoints, failover | Prevents 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_getDelegationsandftm_getRewardsare 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.