@typechain/ethers-v5
Advanced tools
Comparing version 2.0.0 to 3.0.0
@@ -48,2 +48,4 @@ "use strict"; | ||
return generateTupleType(evmType, generateInputType); | ||
case 'unknown': | ||
return 'any'; | ||
} | ||
@@ -77,2 +79,4 @@ } | ||
return generateOutputTupleType(evmType); | ||
case 'unknown': | ||
return 'any'; | ||
} | ||
@@ -79,0 +83,0 @@ } |
@@ -11,3 +11,3 @@ { | ||
], | ||
"version": "2.0.0", | ||
"version": "3.0.0", | ||
"license": "MIT", | ||
@@ -37,3 +37,3 @@ "repository": "https://github.com/ethereum-ts/Typechain", | ||
"peerDependencies": { | ||
"typechain": "^3.0.0", | ||
"typechain": "^4.0.0", | ||
"ethers": "^5.0.0" | ||
@@ -66,6 +66,3 @@ }, | ||
"typescript": "3.9.0-beta" | ||
}, | ||
"dependencies": { | ||
"ethers": "^5.0.2" | ||
} | ||
} |
@@ -24,1 +24,47 @@ # Typechain target Ethers-v5 | ||
## [TypeChain readme](https://github.com/ethereum-ts/TypeChain) | ||
## Contract typings | ||
The main files generated by this target are `<contract-name>.d.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. | ||
```typescript | ||
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); | ||
} | ||
``` |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
45694
2
522
70
+ Addedts-essentials@7.0.3(transitive)
+ Addedtypechain@4.0.3(transitive)
- Removedethers@^5.0.2
- Removedts-essentials@6.0.7(transitive)
- Removedtypechain@3.0.0(transitive)