Summary
This page explains how to connect to Fantom Opera through an RPC endpoint, including chain settings, public and private RPC options, and common debugging steps. It helps developers configure wallets, deploy contracts, and choose the right infrastructure for production workloads.
Quick Recommendation: Choose the Right Fantom Endpoint for Your Use Case
Before diving into configuration, decide which type of Fantom endpoint fits your workload. If you are building a prototype, testing a dApp, or making occasional calls, a public endpoint is sufficient. For production applications that require consistent performance, higher rate limits, or access to historical data, consider a dedicated node or a premium RPC service.
- Public endpoint: Good for development and light usage. May be subject to rate limits and shared bandwidth.
- Private RPC endpoint: Provides a dedicated URL, often with higher throughput and more reliability. Suitable for production dApps and services.
- Dedicated node: Gives you full control over the node, including the ability to run archive mode or customize settings. Best for high-traffic applications or specialized needs.
For a quick start, you can use the public Fantom endpoint provided by OnFinality: https://fantom.api.onfinality.io/public. However, for production, we recommend exploring dedicated node options or RPC pricing to find a solution that matches your requirements.
Fantom Opera Chain Settings at a Glance
When connecting to Fantom, you need the correct network parameters. Here are the essential details for Fantom Opera (mainnet):
| Parameter | Value |
|---|---|
| Network Name | Fantom Opera |
| Chain ID | 250 |
| Native Currency | FTM (Fantom) |
| Symbol | FTM |
| Decimals | 18 |
| Block Explorer | https://ftmscan.com |
| RPC Endpoint (Public) | https://fantom.api.onfinality.io/public |
These settings are used when adding Fantom to a wallet or configuring a dApp. Make sure to use the correct chain ID to avoid transaction errors.
How to Configure a Fantom Endpoint in Wallets and dApps
Whether you are setting up MetaMask, a custom wallet, or a backend service, the process is similar. Below are examples for common scenarios.
Adding Fantom to MetaMask
- Open MetaMask and click the network dropdown at the top.
- Click "Add Network" or "Custom RPC".
- Fill in the details:
- Network Name: Fantom Opera
- New RPC URL:
https://fantom.api.onfinality.io/public - Chain ID: 250
- Currency Symbol: FTM
- Block Explorer URL: https://ftmscan.com
- Save and switch to the Fantom network.
Configuring a Web3 Provider in JavaScript
Using ethers.js or viem, you can set up a provider with the Fantom endpoint.
ethers.js example:
const { ethers } = require("ethers");
const provider = new ethers.providers.JsonRpcProvider("https://fantom.api.onfinality.io/public");
async function getBlockNumber() {
const blockNumber = await provider.getBlockNumber();
console.log("Current block number:", blockNumber);
}
getBlockNumber();
viem example:
import { createPublicClient, http } from 'viem';
import { fantom } from 'viem/chains';
const client = createPublicClient({
chain: fantom,
transport: http('https://fantom.api.onfinality.io/public')
});
const blockNumber = await client.getBlockNumber();
console.log(blockNumber);
Making JSON-RPC Calls to a Fantom Endpoint
Fantom supports the Ethereum JSON-RPC standard. You can interact with the endpoint using curl or any HTTP client.
Basic curl Example
curl https://fantom.api.onfinality.io/public \
-X POST \
-H "Content-Type: application/json" \
-d '{"jsonrpc":"2.0","method":"eth_blockNumber","params":[],"id":1}'
This returns the latest block number. Other common methods include eth_getBalance, eth_call, and eth_getLogs.
Checking FTM Balance
curl https://fantom.api.onfinality.io/public \
-X POST \
-H "Content-Type: application/json" \
-d '{"jsonrpc":"2.0","method":"eth_getBalance","params":["0xYourAddress","latest"],"id":1}'
Replace 0xYourAddress with a valid Fantom address.
Debugging Common Fantom Endpoint Issues
When working with Fantom endpoints, you may encounter errors. Here are common symptoms and how to resolve them.
| Symptom | Possible Cause | Fix |
|---|---|---|
connection refused or timeout | Endpoint is down or network issue | Check your internet, try again, or use a different endpoint. |
invalid chain id | Wallet or dApp configured with wrong chain ID | Ensure chain ID is 250. |
rate limit exceeded | Too many requests to public endpoint | Use a private endpoint or dedicated node, or implement backoff. |
method not found | Using unsupported JSON-RPC method | Verify method is part of Ethereum JSON-RPC spec. |
response too large | Requesting too many logs or blocks | Narrow your query parameters. |
Debugging with curl and WebSocket
For real-time data, you can use WebSocket subscriptions. Here is an example using wscat:
wscat -c wss://fantom.api.onfinality.io/public
Then send a subscription request:
{"jsonrpc":"2.0","method":"eth_subscribe","params":["newHeads"],"id":1}
If you do not receive responses, check that your client supports WebSocket and that the endpoint URL is correct.
Public vs. Private Fantom Endpoints: What to Consider
Public endpoints are convenient but shared. For production, you need to evaluate the tradeoffs.
- Throughput: Public endpoints may throttle heavy usage. Private endpoints offer higher rate limits.
- Reliability: Public endpoints can be less predictable. A dedicated node provides consistent performance.
- Data access: If you need archive data or custom tracing, a dedicated node is often required.
OnFinality offers dedicated nodes that can be tailored to your needs, including archive mode and custom configurations. You can also compare RPC pricing to understand cost implications.
Production Readiness Checklist for Fantom Endpoints
Before launching your application, review this checklist:
- Use a private or dedicated endpoint, not a public one.
- Implement retry logic and fallback endpoints.
- Monitor your endpoint's health and performance.
- Set up alerts for rate limit errors.
- Ensure your chain ID and network settings are correct.
- Test with both HTTP and WebSocket connections.
- Consider using an archive node if you need historical data.
Key Takeaways
- Fantom Opera uses chain ID 250 and FTM as its native currency.
- The public endpoint
https://fantom.api.onfinality.io/publicis suitable for development and testing. - For production, evaluate private RPC or dedicated node options to ensure reliability and performance.
- Use standard Ethereum JSON-RPC methods to interact with Fantom.
- Debug common issues by checking chain ID, rate limits, and endpoint availability.
Frequently Asked Questions
What is a Fantom endpoint?
A Fantom endpoint is a URL that allows you to interact with the Fantom blockchain via JSON-RPC. It is used to send transactions, query data, and deploy smart contracts.
How do I get a free Fantom endpoint?
You can use the public endpoint https://fantom.api.onfinality.io/public for development. For production, consider a paid plan.
What is the Fantom chain ID?
The Fantom Opera chain ID is 250.
Can I use WebSocket with Fantom?
Yes, Fantom supports WebSocket for real-time subscriptions. Check with your provider for the WebSocket URL.
How do I choose between a public and a dedicated Fantom node?
If you need high throughput, reliability, or archive data, a dedicated node is recommended. For simple testing, a public endpoint is fine.
For more information, visit the Fantom network page or explore supported networks.