Using External Libraries

Sending raw RPC requests can be error-prone and sometimes overwhelming. This guide will list some common external libraries for the Ethereum ecosystem that are compatible with the Stargazer ChainProvider.

The ethers.jsarrow-up-right package is a general purpose library for interacting with the ethereum ecosystem. It offers different features from contract interaction to EIP-712arrow-up-right message signing for wallets.

In ethers.jsarrow-up-right there are different types of providers, the Stargazer ChainProvider is compatible with ethers.jsarrow-up-right Web3Providerarrow-up-right.

import * as ethers from "ethers";

const ethProvider = window.stargazer.getProvider("ethereum");

const ethersProvider = new ethers.providers.Web3Provider(ethProvider);

Once the ethers.jsarrow-up-right Web3Providerarrow-up-right is created you can start interacting with the network using this library.

// get balance from address
await ethersProvider.getBalance("0xEb14c9bb6C2DEc2eCb9B278C9fa1EC763B04d545");
// { BigNumber: "36428926959297445147" }
// get current block number
await ethersProvider.getBlockNumber();
// 14983198
// get current gas price
await ethersProvider.getGasPrice();
// { BigNumber: "23610503242" }

The web3.jsarrow-up-right library offers a simple but powerful API to interact with the ethereum ecosystem using EIP-1193arrow-up-right, HTTP, IPC or WebSocket providers.

The web3.jsarrow-up-right library reveals the Web3arrow-up-right class which is compatible with the Stargazer ChainProvider.

Once the web3.jsarrow-up-right Web3arrow-up-right object is created you can start interacting with the network using this library.

Last updated

Was this helpful?