Socket
Socket
Sign inDemoInstall

ethers-axios-provider

An ethers-compatible JSONRPC provider powered by Axios


Version published
Maintainers
1
0

Weekly downloads

Readme

Source

ethers-axios-provider

Build Status NPM Package Version NPM Package Downloads Known Vulnerabilities GitHub Views GitHub Clones License: MIT

About

Fastest, fault tolerant multi node ethers.js compatible JSONRPC provider

AxiosProvider is an easy to use ethers.js v5 compatible Ethereum Javascript (Typescript) JSONRPC API Provider powered by a powerful Axios HTTP client wrapped by axios-auto library to help your automated error handling & Promise.any powered client-side load balancing feature.

Features:

  • Provides much better error handling & timeouts for public RPC nodes the most widely used HTTP client Axios.
  • Supports custom http.agent / https.Agent via Axios (Node.js feature to support Tor, Socks5, Https proxy connection)
  • Client side load-balancer using Promise.any() to resolve fastest query result from the fastest node connection.
  • Sends a query to multiple nodes (like Promise.all but without waiting for every promise to resolve)
  • Advanced retries for server-side error using axios-auto
  • Return cached eth_chainId value since network doesn't change for RPC nodes for most cases.

Installation

Node.js

# Wouldn't work without axios or ethers installed
npm i --save axios ethers ethers-axios-provider

Documentation

https://ayanamitech.github.io/ethers-axios-provider

Usage

Browser

Every release of ethers-axios-provider will have new build of ./dist/browser/index.js for use in the browser. To get access to module classes use AxiosProvider global variable.

WARN: We recommend hosting and controlling your own copy for security reasons

<!-- Since Browser bundle comes with axios-auto built in, no need to add additional axios or axios-auto dependency -->
<script src="https://cdn.jsdelivr.net/npm/ethers-axios-provider@latest"></script>
<!-- Since Browser bundle comes with axios-auto built in, no need to add additional axios or axios-auto dependency -->
<script src="https://unpkg.com/ethers-axios-provider@latest"></script>

Note that it would be helpful to setup the Subresource Integrity hash to ensure that the imported library has the desired codes.

For more info, see https://www.srihash.org/.

Node.js

// CommonJS
const AxiosProvider = require('ethers-axios-provider');

// ModuleJS / TypeScript
import AxiosProvider from 'ethers-axios-provider';

const provider = new AxiosProvider('rpc-host-here');

provider.getBlockNumber().then(blockNumber => {
  // Will return something like 10000
  console.log(blockNumber);
});

Keywords

FAQs

Last updated on 14 Jul 2022

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc