This is RPC tester and get best RPC for ETH or Fork. All chain RPC got from Chainlist.org.
This library moved to live-evm-rpc
- Via NPM :
npm i get-fastest-rpc
- Via Yarn :
yarn add get-fastest-rpc
- CJS :
const { testAllRpc, testRpc, getBestRpc, testAllRpcByChainId, getBestRpcByChainId } = require('get-fastest-rpc')
- ESM :
import { testAllRpc, testRpc, getBestRpc, testAllRpcByChainId, getBestRpcByChainId } from 'get-fastest-rpc'
import { testAllRpcByChainId } from 'get-fastest-rpc';
// if use commonjs use this :
// const { testAllRpcByChainId } = require('get-fastest-rpc');
// example chainId
const chainId = 80001;
// example function for test
async test(){
console.log(await testAllRpcByChainId(chainId));
}
test();
// result will be like
// [
// { rpc: 'https://polygon-testnet.public.blastapi.io', ms: 230 },
// { rpc: 'https://matic-testnet-archive-rpc.bwarelabs.com', ms: 272 },
// { rpc: 'https://matic-mumbai.chainstacklabs.com', ms: 588 },
// { rpc: 'https://polygontestapi.terminet.io/rpc', ms: 138 },
// { rpc: 'https://rpc.ankr.com/polygon_mumbai', ms: 490 },
// { rpc: 'https://rpc-mumbai.maticvigil.com', ms: 647 }
// ]
Default timeout is 3000ms, you can update timeout by calling function like this testAllRpcByChainId(chainId, 5000)
.
import { getBestRpcByChainId } from 'get-fastest-rpc';
// if use commonjs use this :
// const { getBestRpcByChainId } = require('get-fastest-rpc');
// example chainId
const chainId = 80001;
// example function for test
async test(){
console.log(await getBestRpcByChainId(chainId));
}
test();
// result will be like
// https://polygon-testnet.public.blastapi.io
Default timeout is 3000ms, you can update timeout by calling function like this getBestRpcByChainId(chainId, 5000)
.
import { testRpc } from 'get-fastest-rpc';
// if use commonjs use this :
// const { testRpc } = require('get-fastest-rpc');
// example rpc
const rpc = "https://rpc-mumbai.maticvigil.com";
// example function for test
async test(){
console.log(await testRpc(rpc));
}
test();
// result will be like
// { rpc: 'https://rpc-mumbai.maticvigil.com', ms: 234 }
Default timeout is 3000ms, you can update timeout by calling function like this testRpc(rpc, 5000)
.
import { testAllRpc } from 'get-fastest-rpc';
// if use commonjs use this :
// const { testAllRpc } = require('get-fastest-rpc');
// example rpcs
const rpc = [
"https://polygon-testnet.public.blastapi.io",
"https://matic-testnet-archive-rpc.bwarelabs.com",
"https://matic-mumbai.chainstacklabs.com",
"https://polygontestapi.terminet.io/rpc",
"https://rpc.ankr.com/polygon_mumbai",
"https://rpc-mumbai.maticvigil.com",
];
// example function for test
async test(){
console.log(await testAllRpc(rpc));
}
test();
// result will be like
// [
// { rpc: 'https://polygon-testnet.public.blastapi.io', ms: 230 },
// { rpc: 'https://matic-testnet-archive-rpc.bwarelabs.com', ms: 272 },
// { rpc: 'https://matic-mumbai.chainstacklabs.com', ms: 588 },
// { rpc: 'https://polygontestapi.terminet.io/rpc', ms: 138 },
// { rpc: 'https://rpc.ankr.com/polygon_mumbai', ms: 490 },
// { rpc: 'https://rpc-mumbai.maticvigil.com', ms: 647 }
// ]
Default timeout is 3000ms, you can update timeout by calling function like this testAllRpc(rpc, 5000)
.
import { getBestRpc } from 'get-fastest-rpc';
// if use commonjs use this :
// const { getBestRpc } = require('get-fastest-rpc');
// example rpcs
const rpc = [
"https://polygon-testnet.public.blastapi.io",
"https://matic-testnet-archive-rpc.bwarelabs.com",
"https://matic-mumbai.chainstacklabs.com",
"https://polygontestapi.terminet.io/rpc",
"https://rpc.ankr.com/polygon_mumbai",
"https://rpc-mumbai.maticvigil.com",
];
// example function for test
async test(){
console.log(await getBestRpc(rpc));
}
test();
// result will be like
// https://polygon-testnet.public.blastapi.io
Default timeout is 3000ms, you can update timeout by calling function like this getBestRpc(rpc, 5000)
.