11.1.2 • Published 1 year ago

@typechain/ethers-v5 v11.1.2

Weekly downloads
12,613
License
MIT
Repository
github
Last release
1 year ago

Typechain target Ethers-v5

This package requires TypeScript >= 4.0. If you need support for earlier TS versions check out: 1.0 version of this package.

TypeChain readme

Contract typings

The main files generated by this target are <contract-name>.ts. They declare typesafe interfaces for your contracts on top of ethers Contract instances:

  • typed contract's methods, available both at contract.someMethod(...) and contract.functions.someMethod(...)
  • typed events in contract.interface.events.AnEvent and filters in contract.filters.AnEvent
  • typed method gas estimates in contract.estimateGas.someMethod
  • overrides for the event listener methods (on, once, etc) that return the same contract type.

Note: these are just type declarations to help you call the blockchain properly, so they're not available at runtime, and all of the contracts are still instances of the same Contract class.

Contract factories

This target also generates a concrete factory class for each contract, to help you deploy or connect to contract instances. The factory classes are an extension of ethers' ContractFactory. They serve two main purposes:

  • wrap passing contract ABI and bytecode to the ContractFactory class, so you don't have to load and parse the JSON manually
  • provide a correctly typed interface to ContractFactory (since it returns plain Contract instances).

Abstract contracts or solidity interfaces are handled a bit different, because they have no bytecode. For those, a simplified factory is generated that doesn't extends ContractFactory, and only includes the static connect method, so you can easily connect to a deployed instance without having to pass the ABI manually.

Basic example

Suppose you have an Erc20Token.sol solidity interface and a DummyToken.sol contract implementing it.

import { BigNumber } from 'ethers';
import { Wallet } from 'ethers';

import { DummyTokenFactory } from 'typechain-out-dir/DummyTokenFactory';
import { DummyToken } from 'typechain-out-dir/DummyToken';
import { Erc20TokenFactory } from 'typechain-out-dir/Erc20TokenFactory';

const provider = getYourProvider(...);

// use the concrete contract factory if you need to operate on the bytecode (ie. deploy)
async function deployTestToken(ownerPK: string): Promise<DummyToken> {
    const owner = new Wallet(ownerPK, provider);
    return new DummyTokenFactory(owner).deploy();
}

// to call existing contracts, a factory for both the concrete contract and for the interface
// can be used since the ABI is the same
async function getTokenBalance(walletAddress: string, tokenAddress: string): Promise<BigNumber> {
    const token = Erc20TokenFactory.connect(tokenAddress, provider);
    return token.balanceOf(walletAddress);
}
vitacontractsassetma@blockswaplab/cip-sdk@bojinovic/test-package@sirenprotocol/contractsdtrade-jsdtrade-ts@sonicswap/contracts-dev@bond-labs/contract-librarylot-ref@meetusvr/smart-contracts@infinitebrahmanuniverse/nolb-_typec@ponder/ponder@bojinovic/filecoin-solidity@everything-registry/sub-chunk-944messina-sdk@indid-tmp/indid-typechainspacked-solidity-arrayswepublic-contractsweb3mredstone-evm-connectorredstone-flash-storagetemp-emojisun-dd-clitemp-poolz-helper-v2temp-project-atemplate-sdk-namestash-aa-tsstash-fe-scripttest-zk-jssdktestsdkv1tetu_converterthorn-aa-sdk@mstable/metavaultsjaskaran-commonlit-swap-sdklevygo-generator-wallet-reactmeerchangelit-listener-sdkkongtama_corehardhat-celohblues-dapp-templatehammurabi-contractshandle-sdkhandle-sdk-reactmymultisig-contractp-utilityonthis-libraryouter-mint-sdkoz-customs-contractomnite-sdkpresent-contractsnftstarsdknse-testnoir-zidensoulswap-hardhat-configstn-sdk-litestn5_membershipsmart-trade-networks-contractssimple-dvt-v1sishiswap-v1-coresovryn-perp-utilsufomarketplace-sdk-newudonswap-routing-apitoken-registry-testtinyroutes@anticxyz/dal@anticxyz/so-widget@ape.swap/governance-sdk@arx-research/ers-contracts@aragon/govern-contract-utils@angleprotocol/sdk@asheliahut/hardhat-demo@aurigami/smart-contracts@athenalend/core-v3@algo-foundry/messina-sdk@alpaca-finance/alpaca-money-market@aztec/bridge-clients@blockswaplab/lsd-wizard@blockswaplab/mpc-js@blockapex-labs/stash-aa-sdk@biconomy/common@catalabs/catalyst-sdk@chung0807/ziden-noir@cloud8little/latticexyz-cli@1o1art/sdk@aaiello/arkive-hardhat@aaiello/hardhat@aaaaaimtesting/package-test@dcspark/milkomeda-liquid-staking@dcnsdomains/function@defiedge/sdk@congson1907/sunswap-core@dany-armstrong/hardhat-compound@dany-armstrong/hardhat-erc20@darenft/dare-protocol-contractsxzx-test-osp-walletunibaseiouxd-evm-client
11.1.1

1 year ago

11.1.2

1 year ago

11.1.0

1 year ago

11.0.1

1 year ago

10.2.1

2 years ago

11.0.0

2 years ago

10.2.0

2 years ago

10.1.1

2 years ago

10.1.0

3 years ago

10.0.0

3 years ago

9.0.0

3 years ago

8.0.5

3 years ago

8.0.4

3 years ago

8.0.3

3 years ago

8.0.2

3 years ago

8.0.1

3 years ago

8.0.0

3 years ago

7.2.0

3 years ago

7.1.2

3 years ago

7.1.1

3 years ago

7.1.0

3 years ago

7.0.1

4 years ago

7.0.0

4 years ago

6.0.5

4 years ago

6.0.4

4 years ago

6.0.3

4 years ago

6.0.2

4 years ago

6.0.1

4 years ago

6.0.0

4 years ago

5.0.0

4 years ago

4.0.0

4 years ago

3.0.0

4 years ago

2.0.0

4 years ago

1.0.0

4 years ago

0.0.4

4 years ago

0.0.3

4 years ago

0.0.2

4 years ago

0.0.1

4 years ago