@typechain/ethers-v5
Advanced tools
Comparing version
@@ -31,4 +31,4 @@ "use strict"; | ||
? `overrides?: ${isPayable(fn) | ||
? 'PayableOverrides & { from?: string | Promise<string> }' | ||
: 'Overrides & { from?: string | Promise<string> }'}` | ||
? 'PayableOverrides & { from?: PromiseOrValue<string> }' | ||
: 'Overrides & { from?: PromiseOrValue<string> }'}` | ||
: 'overrides?: CallOverrides'}): ${(_a = options.overrideOutput) !== null && _a !== void 0 ? _a : `Promise<${options.isStaticCall || fn.stateMutability === 'pure' || fn.stateMutability === 'view' | ||
@@ -35,0 +35,0 @@ ? (0, types_1.generateOutputTypes)({ returnResultObject: !!options.returnResultObject, useStructs: true }, fn.outputs) |
@@ -18,3 +18,2 @@ "use strict"; | ||
export interface ${contract.name}Interface extends utils.Interface { | ||
${codegenConfig.discriminateTypes ? `contractName: '${contract.name}';\n` : ``} | ||
functions: { | ||
@@ -111,5 +110,4 @@ ${(0, lodash_1.values)(contract.functions) | ||
'type @ethersproject/providers': ['Listener', 'Provider'], | ||
}, source) + | ||
'\n' + | ||
(0, typechain_1.createImportTypeDeclaration)(events_1.EVENT_IMPORTS, commonPath); | ||
[`type ${commonPath}`]: [...events_1.EVENT_IMPORTS, 'PromiseOrValue'], | ||
}, source); | ||
return imports + source; | ||
@@ -122,4 +120,4 @@ } | ||
`overrides?: ${((_a = contract.constructor[0]) === null || _a === void 0 ? void 0 : _a.stateMutability) === 'payable' | ||
? 'PayableOverrides & { from?: string | Promise<string> }' | ||
: 'Overrides & { from?: string | Promise<string> }'}`; | ||
? 'PayableOverrides & { from?: PromiseOrValue<string> }' | ||
: 'Overrides & { from?: PromiseOrValue<string> }'}`; | ||
const constructorArgNamesWithoutOverrides = contract.constructor[0] | ||
@@ -164,2 +162,3 @@ ? (0, functions_1.generateParamNames)(contract.constructor[0].inputs) | ||
`; | ||
const commonPath = `${new Array(contract.path.length + 1).fill('..').join('/')}/common`; | ||
const imports = (0, typechain_1.createImportsForUsedIdentifiers)({ | ||
@@ -177,2 +176,3 @@ ethers: [ | ||
'type @ethersproject/providers': ['Provider', 'TransactionRequest'], | ||
[`type ${commonPath}`]: ['PromiseOrValue'], | ||
}, source); | ||
@@ -208,3 +208,3 @@ return imports + source; | ||
const _abi = ${JSON.stringify(abi, null, 2)}; | ||
const _abi = ${JSON.stringify(abi, null, 2)} as const; | ||
`.trim(); | ||
@@ -211,0 +211,0 @@ const body = ` |
@@ -28,16 +28,16 @@ "use strict"; | ||
case 'integer': | ||
return 'BigNumberish'; | ||
return wrapInPromiseOrValue('BigNumberish'); | ||
case 'uinteger': | ||
return 'BigNumberish'; | ||
return wrapInPromiseOrValue('BigNumberish'); | ||
case 'address': | ||
return 'string'; | ||
return wrapInPromiseOrValue('string'); | ||
case 'bytes': | ||
case 'dynamic-bytes': | ||
return 'BytesLike'; | ||
return wrapInPromiseOrValue('BytesLike'); | ||
case 'array': | ||
return generateArrayOrTupleType(generateInputType(options, evmType.itemType), evmType.size); | ||
case 'boolean': | ||
return 'boolean'; | ||
return wrapInPromiseOrValue('boolean'); | ||
case 'string': | ||
return 'string'; | ||
return wrapInPromiseOrValue('string'); | ||
case 'tuple': | ||
@@ -119,2 +119,5 @@ if (evmType.structName && options.useStructs) { | ||
} | ||
function wrapInPromiseOrValue(str) { | ||
return `PromiseOrValue<${str}>`; | ||
} | ||
//# sourceMappingURL=types.js.map |
@@ -11,3 +11,3 @@ { | ||
], | ||
"version": "10.0.0", | ||
"version": "10.2.1", | ||
"license": "MIT", | ||
@@ -26,6 +26,5 @@ "repository": "https://github.com/ethereum-ts/Typechain", | ||
"@ethersproject/abi": "^5.0.0", | ||
"@ethersproject/bytes": "^5.0.0", | ||
"@ethersproject/providers": "^5.0.0", | ||
"ethers": "^5.1.3", | ||
"typechain": "^8.0.0", | ||
"typechain": "^8.1.1", | ||
"typescript": ">=4.3.0" | ||
@@ -40,3 +39,3 @@ }, | ||
"test-utils": "1.0.0", | ||
"typechain": "^8.0.0", | ||
"typechain": "^8.1.1", | ||
"typescript": ">=4.3.0", | ||
@@ -61,4 +60,3 @@ "@types/proxyquire": "^1.3.28", | ||
"test:fix": "pnpm lint:fix && pnpm format:fix && pnpm test && pnpm typecheck" | ||
}, | ||
"readme": "# Typechain target Ethers-v5\n\n<p align=\"center\">\n <img src=\"https://github.com/Neufund/TypeChain/blob/d82f3cc644a11e22ca8e42505c16f035e2f2555d/docs/images/typechain-logo.png?raw=true\" width=\"300\" alt=\"TypeChain\">\n <h3 align=\"center\">TypeChain target Ethers-v5</h3>\n <p align=\"center\">🔌 TypeScript bindings for Ethers 5.x.x smartcontracts</p>\n\n <p align=\"center\">\n <a href=\"https://github.com/ethereum-ts/TypeChain/actions\"><img alt=\"Build Status\" src=\"https://github.com/ethereum-ts/TypeChain/workflows/CI/badge.svg\"></a>\n <img alt=\"Downloads\" src=\"https://img.shields.io/npm/dm/typechain.svg\">\n <a href=\"https://github.com/prettier/prettier\"><img alt=\"Prettier\" src=\"https://img.shields.io/badge/code_style-prettier-ff69b4.svg\"></a>\n <a href=\"/package.json\"><img alt=\"Software License\" src=\"https://img.shields.io/badge/license-MIT-brightgreen.svg?style=flat-square\"></a>\n </p>\n\n <p align=\"center\">\n <a href=\"https://blog.neufund.org/introducing-typechain-typescript-bindings-for-ethereum-smart-contracts-839fc2becf22\">Medium post</a> | <a href=\"https://www.youtube.com/watch?v=9x6AkShGkwU\">DappCon Video</a>\n </p>\n</p>\n\nThis package requires TypeScript >= 4.0. If you need support for earlier TS versions check out: 1.0 version of this\npackage.\n\n## [TypeChain readme](https://github.com/ethereum-ts/TypeChain)\n\n## Contract typings\n\nThe main files generated by this target are `<contract-name>.ts`. They declare typesafe interfaces for your contracts\non top of ethers `Contract` instances:\n\n- typed contract's methods, available both at `contract.someMethod(...)` and `contract.functions.someMethod(...)`\n- typed events in `contract.interface.events.AnEvent` and filters in `contract.filters.AnEvent`\n- typed method gas estimates in `contract.estimateGas.someMethod`\n- overrides for the event listener methods (`on`, `once`, etc) that return the same contract type.\n\nNote: these are just _type declarations_ to help you call the blockchain properly, so they're not available at runtime,\nand all of the contracts are still instances of the same `Contract` class.\n\n## Contract factories\n\nThis target also generates a concrete factory class for each contract, to help you deploy or connect to contract\ninstances. The factory classes are an extension of ethers' `ContractFactory`. They serve two main purposes:\n\n- wrap passing contract ABI and bytecode to the `ContractFactory` class, so you don't have to load and parse the JSON\n manually\n- provide a correctly typed interface to `ContractFactory` (since it returns plain `Contract` instances).\n\nAbstract contracts or solidity interfaces are handled a bit different, because they have no bytecode. For those, a\nsimplified factory is generated that doesn't extends `ContractFactory`, and only includes the static `connect` method,\nso you can easily connect to a deployed instance without having to pass the ABI manually.\n\n## Basic example\n\nSuppose you have an `Erc20Token.sol` solidity interface and a `DummyToken.sol` contract implementing it.\n\n```typescript\nimport { BigNumber } from 'ethers';\nimport { Wallet } from 'ethers';\n\nimport { DummyTokenFactory } from 'typechain-out-dir/DummyTokenFactory';\nimport { DummyToken } from 'typechain-out-dir/DummyToken';\nimport { Erc20TokenFactory } from 'typechain-out-dir/Erc20TokenFactory';\n\nconst provider = getYourProvider(...);\n\n// use the concrete contract factory if you need to operate on the bytecode (ie. deploy)\nasync function deployTestToken(ownerPK: string): Promise<DummyToken> {\n const owner = new Wallet(ownerPK, provider);\n return new DummyTokenFactory(owner).deploy();\n}\n\n// to call existing contracts, a factory for both the concrete contract and for the interface\n// can be used since the ABI is the same\nasync function getTokenBalance(walletAddress: string, tokenAddress: string): Promise<BigNumber> {\n const token = Erc20TokenFactory.connect(tokenAddress, provider);\n return token.balanceOf(walletAddress);\n}\n```\n" | ||
} | ||
} |
@@ -28,1 +28,3 @@ import type { Listener } from '@ethersproject/providers' | ||
export type GetARGsTypeFromFactory<F> = F extends MinEthersFactory<any, any> ? Parameters<F['deploy']> : never | ||
export type PromiseOrValue<T> = T | Promise<T> |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
87474
5.19%7
-12.5%32
3.23%1107
18.14%3
50%