Ethers.js: Document how to import types like BigNumber

Created on 3 Jun 2020  路  4Comments  路  Source: ethers-io/ethers.js

Importing base types like Contract or Wallet is trivial:

import { Contract, Wallet } from "ethers";

const myContract: Contract = ...

But I had to dig up the source code to figure out how to import BigNumber:

import { utils } from "ethers";

const myBigNumber: utils.BigNumber = ...

It'd be nice to have this explained in the docs.

documentation

Most helpful comment

I've been mulling back-and-forth how to add this to the new docs, especially since many things are available from their sub-modules too.

I'll work on this on the next docs pass.

All 4 comments

I've been mulling back-and-forth how to add this to the new docs, especially since many things are available from their sub-modules too.

I'll work on this on the next docs pass.

To add on to this, how do I import types like Block and Network. They seem to be internal to Ethers.

You can use:

import type { Network } from '@ethersproject/networks';
import type { Block } from '@ethersproject/abstract-provider';

FWIW I am now importing the BigNumber type like this:

import { BigNumber} from "@ethersproject/bignumber";

And I started using Sourcegraph to find where to import types from.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

abhishekp1996 picture abhishekp1996  路  3Comments

dagogodboss picture dagogodboss  路  3Comments

thegostep picture thegostep  路  3Comments

naddison36 picture naddison36  路  3Comments

ricmoo picture ricmoo  路  3Comments