1.0.12 • Published 19 days ago

live-evm-rpc v1.0.12

Weekly downloads
-
License
MIT
Repository
github
Last release
19 days ago

live-evm-rpc

Get Public Live EVM RPC url easily.

Install

  1. Via NPM : npm i live-evm-rpc
  2. Via Yarn : yarn add live-evm-rpc

Import

  1. CJS : const { getPublicRpc, testRpc, getLiveRpc, getBestLiveRpc } = require('live-evm-rpc')
  2. ESM : import { getPublicRpc, testRpc, getLiveRpc, getBestLiveRpc } from 'live-evm-rpc'

A. getPublicRpc

    import { getPublicRpc } from 'live-evm-rpc';
    // if use commonjs use this :
    // const { getPublicRpc } = require('live-evm-rpc');

    // example chain
    const chain = 1;

    // example function for test
    async function test(){
        console.log(await getPublicRpc(chain));
    }
    test();

    // result will be like
    // [
    //      'https://api.mycryptoapi.com/eth',
	// 	    'https://cloudflare-eth.com',
    //      ...
    // ]

B. testRpc

    import { testRpc } from 'live-evm-rpc';
    // if use commonjs use this :
    // const { testRpc } = require('live-evm-rpc');

    // example function for test
    async function test(){
        console.log(await testRpc('https://cloudflare-eth.com'));
        // or you can set custom timeout will be like, default timeout is 1500ms
        // console.log(await testRpc('https://cloudflare-eth.com', 3000));
    }
    test();

    // result will be like
    // {
    //     isSyncing: false,
    //     lastBlock: 19089064,
    //     chainId: 1,
    //     ms: 621,
    //     url: 'https://cloudflare-eth.com'
    // }

    // if syncing, result will be like
    // {
    //     isSyncing: true,
    //     lastBlock: 19089064,
    //     chainId: 1,
    //     ms: 621,
    //     url: 'https://cloudflare-eth.com'
    // }

    // if timeout, result will be like
    // {
    //     isSyncing: true,
    //     lastBlock: 'unknown',
    //     chainId: 'unknown',
    //     ms: 621,
    //     url: 'https://cloudflare-eth.com'
    // }

    // if partial timeout, result will be like
    // {
    //     isSyncing: false,
    //     lastBlock: 19089064,
    //     chainId: 'unknown',
    //     ms: 621,
    //     url: 'https://cloudflare-eth.com'
    // }
    // or
    // {
    //     isSyncing: true,
    //     lastBlock: 'unknown',
    //     chainId: 1,
    //     ms: 621,
    //     url: 'https://cloudflare-eth.com'
    // }

C. getLiveRpc

    import { getLiveRpc } from 'live-evm-rpc';
    // if use commonjs use this :
    // const { getLiveRpc } = require('live-evm-rpc');

    // example chain
    const chain = 1;

    // example function for test
    async function test(){
        console.log(await getLiveRpc(chain));
        // or you can set custom timeout will be like, default timeout is 1500ms
        // console.log(await getLiveRpc(1, {timeout: 3000}));
        // or you can set custom rpc if you have premium rpc
        // console.log(await getLiveRpc(
        //     1, {rpcs: ['https://ethereum.g.alchemy.com/v2/demo']}
        // ));
    }
    test();

    // result will be like
    // [
    //     {
    //         isSyncing: false,
    //         lastBlock: 19089064,
    //         chainId: 1,
    //         ms: 621,
    //         url: 'https://cloudflare-eth.com'
    //     },
    //     {
    //         isSyncing: false,
    //         lastBlock: 19089064,
    //         chainId: 1,
    //         ms: 1107,
    //         url: 'https://ethereum.publicnode.com'
    //     },
    //     ...
    // ]

    // if no live rpc detected, result will be like
    // []

D. getBestLiveRpc

    import { getLiveRpc } from 'live-evm-rpc';
    // if use commonjs use this :
    // const { getBestLiveRpc } = require('live-evm-rpc');

    // example chain
    const chain = 1;

    // example function for test
    async function test(){
        console.log(await getBestLiveRpc(chain));
        // or you can set custom timeout will be like, default timeout is 1500ms
        // console.log(await getBestLiveRpc(1, {timeout: 3000}));
        // or you can set custom rpc if you have premium rpc
        // console.log(await getBestLiveRpc(
        //     1, {rpcs: ['https://ethereum.g.alchemy.com/v2/demo']}
        // ));
    }
    test();

    // result will be like
    // {
    //     isSyncing: false,
    //     lastBlock: 19089064,
    //     chainId: 1,
    //     ms: 621,
    //     url: 'https://cloudflare-eth.com'
    // }

    // if no live rpc detected, result will be like
    // []
1.0.12

19 days ago

1.0.11

28 days ago

1.0.9

1 month ago

1.0.10

1 month ago

1.0.8

4 months ago

1.0.7

4 months ago

1.0.6

4 months ago

1.0.5

4 months ago

1.0.4

4 months ago

1.0.3

4 months ago

1.0.2

4 months ago

1.0.1

4 months ago

1.0.0

4 months ago