Options
All
  • Public
  • Public/Protected
  • All
Menu

@web3-systems/multichain-providers

Multichain Database

CI TS GPLv3 license Version Downloads/week

💾 Installation

npm install @web3-systems/multichain-providers
yarn add @web3-systems/multichain-providers
git clone https://github.com/web3-systems/multichain-providers

🏎️  Quickstart

The MultichainProvider class wraps the @ethersproject/providers Provider class.

Updating function signatures with chainId to specify a target network.

Example

provider.getBalance('0x000.0000')

is now...

multiprovider.getBalance('0x000.0000', 1);

The function signature (as you can see) now consumes chainId in the first argument position. If a provider has been configured for the chainId the provider will be used when fetching the balance.

Connect New Provider

import { MultichainProviders } from '@web3-systems/multichain-providers';
let client = new MultichainProviders(); // by default connect to Ethereum mainnet via Infura
let jsonRpcURL = 'localhost:8545'
client.connect(1, jsonRpcURL); // sets chainId to use localhost as the endpoint

Get Balance

import { BigNumber } from '@ethersproject/bignumber';
import { MultichainProviders } from '@web3-systems/multichain-providers';
const client = new MultichainProviders();
const balance:BigNumber = await client.getBalance('0x000...000', 1);

Get Provider

import { Provider } from '@ethersproject/providers';
import { MultichainProviders } from '@web3-systems/multichain-providers';
const client = new MultichainProviders();
const provider:Provider = await client.getProvider(1);

Get Transaction History using EtherscanProvider

import { Transactions } from '@ethersproject/contracts';
import { MultichainProviders } from '@web3-systems/multichain-providers';
let apikey = 'etherscan/polygonscan/snowtrace-apikey'
let client = new MultichainProviders(1, apikey, 'chainscan');
const transactions: Transactions[] = await client.getTransactions('0x000...000', 1);

📖  Overview

Coming soon...

🧩  Examples

Utlity Functions

Utility functions like getTransactions (specific to Etherscan) and getLogsDecoded have been included to simplify common method chaining and developer objectives.

For example, instead of fetching event logs and decoding separately, a single function can be called.

const events = await client.getLogsDecoded(1,filter,contract,fragment);
/*
[
{
log: {...},
parsed: {...}
},
{
log: {...},
parsed: {...}
},
]
*/

💻  Developer Experience

The package is setup using the TSDX zero-config CLI which includes:

  • Typescript
  • Rollup
  • Jest
  • Prettier
  • ESLint

Generated using TypeDoc