-
Hi viem developers and viem users, I've been encountering issues with the default Mainnet RPC in viem. It seems to be either down or heavily rate-limited. My dAPP, which had been running smoothly before, started failing with errors related to RPC availability. Switching to another public RPC provider resolved the issue. Here’s what I was doing with the default setup: import { createPublicClient, http } from 'viem';
import { mainnet } from 'viem/chains';
const client = createPublicClient({
chain: mainnet,
transport: http(),
});
// Example query
async function getBlockNumber() {
const blockNumber = await client.getBlockNumber();
console.log('Current block number:', blockNumber);
}
getBlockNumber(); With the default Mainnet RPC, I noticed frequent failures, and I suspect it's due to rate-limiting or downtime on the public endpoint. After switching to another public RPC (e.g.,Ankr), everything worked fine: const client = createPublicClient({
chain: mainnet,
transport: http('https://rpc.ankr.com/eth'),
}); This immediately resolved the issue. Questions for the Community
Thanks in advance for your help! |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments
-
When you don't provide your own RPC URL (e.g. |
Beta Was this translation helpful? Give feedback.
-
Thanks for the quick response. |
Beta Was this translation helpful? Give feedback.
When you don't provide your own RPC URL (e.g.
http()
), Viem uses the default public RPC URL. These are shared resources so they can be okay for prototyping, but should not be used for production applications.