Socket
Socket
Sign inDemoInstall

@typechain/ethers-v5

Package Overview
Dependencies
Maintainers
2
Versions
38
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@typechain/ethers-v5 - npm Package Compare versions

Comparing version 9.0.0 to 10.0.0

2

dist/codegen/events.d.ts

@@ -9,4 +9,4 @@ import { EventArgDeclaration, EventDeclaration } from 'typechain';

export declare function generateEventArgType(eventArg: EventArgDeclaration): string;
export declare function generateGetEventOverload(event: EventDeclaration): string;
export declare function generateGetEvent(event: EventDeclaration, useSignature: boolean): string;
export declare const EVENT_METHOD_OVERRIDES = "\n queryFilter<TEvent extends TypedEvent>(\n event: TypedEventFilter<TEvent>,\n fromBlockOrBlockhash?: string | number | undefined,\n toBlock?: string | number | undefined,\n ): Promise<Array<TEvent>>\n\n listeners<TEvent extends TypedEvent>(eventFilter?: TypedEventFilter<TEvent>): Array<TypedListener<TEvent>>\n listeners(eventName?: string): Array<Listener>\n removeAllListeners<TEvent extends TypedEvent>(eventFilter: TypedEventFilter<TEvent>): this\n removeAllListeners(eventName?: string): this\n off: OnEvent<this>\n on: OnEvent<this>\n once: OnEvent<this>\n removeListener: OnEvent<this>\n";
export declare const EVENT_IMPORTS: string[];
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.EVENT_IMPORTS = exports.EVENT_METHOD_OVERRIDES = exports.generateGetEventOverload = exports.generateEventArgType = exports.generateEventInputs = exports.generateEventSignature = exports.generateInterfaceEventDescription = exports.generateEventTypeExport = exports.generateEventTypeExports = exports.generateEventFilters = void 0;
exports.EVENT_IMPORTS = exports.EVENT_METHOD_OVERRIDES = exports.generateGetEvent = exports.generateEventArgType = exports.generateEventInputs = exports.generateEventSignature = exports.generateInterfaceEventDescription = exports.generateEventTypeExport = exports.generateEventTypeExports = exports.generateEventFilters = void 0;
const typechain_1 = require("typechain");

@@ -40,3 +40,4 @@ const types_1 = require("./types");

return `
export type ${identifier} = TypedEvent<${arrayOutput}, ${objectOutput}>;
export interface ${identifier}Object ${objectOutput};
export type ${identifier} = TypedEvent<${arrayOutput}, ${identifier}Object>;

@@ -70,6 +71,6 @@ export type ${identifier}Filter = TypedEventFilter<${identifier}>;

exports.generateEventArgType = generateEventArgType;
function generateGetEventOverload(event) {
return `getEvent(nameOrSignatureOrTopic: '${event.name}'): EventFragment;`;
function generateGetEvent(event, useSignature) {
return `getEvent(nameOrSignatureOrTopic: '${useSignature ? generateEventSignature(event) : event.name}'): EventFragment;`;
}
exports.generateGetEventOverload = generateGetEventOverload;
exports.generateGetEvent = generateGetEvent;
function generateEventIdentifier(event, { includeArgTypes } = {}) {

@@ -76,0 +77,0 @@ if (includeArgTypes) {

@@ -11,5 +11,7 @@ import { AbiParameter, CodegenConfig, EventArgDeclaration, FunctionDeclaration } from 'typechain';

export declare function generateInterfaceFunctionDescription(fn: FunctionDeclaration): string;
export declare function generateEncodeFunctionDataOverload(fn: FunctionDeclaration): string;
export declare function generateDecodeFunctionResultOverload(fn: FunctionDeclaration): string;
export declare function generateFunctionNameOrSignature(fn: FunctionDeclaration, useSignature: boolean): string;
export declare function generateGetFunction(args: string[]): string;
export declare function generateEncodeFunctionDataOverload(fn: FunctionDeclaration, useSignature: boolean): string;
export declare function generateDecodeFunctionResultOverload(fn: FunctionDeclaration, useSignature: boolean): string;
export declare function generateParamNames(params: Array<AbiParameter | EventArgDeclaration>): string;
export {};
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.generateParamNames = exports.generateDecodeFunctionResultOverload = exports.generateEncodeFunctionDataOverload = exports.generateInterfaceFunctionDescription = exports.codegenForOverloadedFunctions = exports.codegenFunctions = void 0;
exports.generateParamNames = exports.generateDecodeFunctionResultOverload = exports.generateEncodeFunctionDataOverload = exports.generateGetFunction = exports.generateFunctionNameOrSignature = exports.generateInterfaceFunctionDescription = exports.codegenForOverloadedFunctions = exports.codegenFunctions = void 0;
const typechain_1 = require("typechain");

@@ -61,4 +61,14 @@ const types_1 = require("./types");

exports.generateInterfaceFunctionDescription = generateInterfaceFunctionDescription;
function generateEncodeFunctionDataOverload(fn) {
const methodInputs = [`functionFragment: '${fn.name}'`];
function generateFunctionNameOrSignature(fn, useSignature) {
return useSignature ? (0, typechain_1.getSignatureForFn)(fn) : fn.name;
}
exports.generateFunctionNameOrSignature = generateFunctionNameOrSignature;
function generateGetFunction(args) {
if (args.length === 0)
return '';
return `getFunction(nameOrSignatureOrTopic: ${args.map((s) => `"${s}"`).join(' | ')}): FunctionFragment;`;
}
exports.generateGetFunction = generateGetFunction;
function generateEncodeFunctionDataOverload(fn, useSignature) {
const methodInputs = [`functionFragment: '${useSignature ? (0, typechain_1.getSignatureForFn)(fn) : fn.name}'`];
if (fn.inputs.length) {

@@ -73,4 +83,4 @@ methodInputs.push(`values: [${fn.inputs.map((input) => (0, types_1.generateInputType)({ useStructs: true }, input.type)).join(', ')}]`);

exports.generateEncodeFunctionDataOverload = generateEncodeFunctionDataOverload;
function generateDecodeFunctionResultOverload(fn) {
return `decodeFunctionResult(functionFragment: '${fn.name}', data: BytesLike): Result;`;
function generateDecodeFunctionResultOverload(fn, useSignature) {
return `decodeFunctionResult(functionFragment: '${useSignature ? (0, typechain_1.getSignatureForFn)(fn) : fn.name}', data: BytesLike): Result;`;
}

@@ -77,0 +87,0 @@ exports.generateDecodeFunctionResultOverload = generateDecodeFunctionResultOverload;

@@ -5,2 +5,3 @@ "use strict";

const common_1 = require("../common");
// @todo hardhat helper needs to import _all_ generated contract files except of duplicates
function generateHardhatHelper(contracts) {

@@ -10,3 +11,3 @@ return `

import { ethers } from 'ethers'
import { FactoryOptions, HardhatEthersHelpers as HardhatEthersHelpersBase} from "@nomiclabs/hardhat-ethers/types";
import { FactoryOptions, HardhatEthersHelpers as HardhatEthersHelpersBase} from "@nomiclabs/hardhat-ethers/types";

@@ -13,0 +14,0 @@ import * as Contracts from "."

import { BytecodeWithLinkReferences, CodegenConfig, Contract } from 'typechain';
export declare function codegenContractTypings(contract: Contract, codegenConfig: CodegenConfig): string;
export declare function codegenContractFactory(contract: Contract, abi: any, bytecode?: BytecodeWithLinkReferences): string;
export declare function codegenContractFactory(codegenConfig: CodegenConfig, contract: Contract, abi: any, bytecode?: BytecodeWithLinkReferences): string;
export declare function codegenAbstractContractFactory(contract: Contract, abi: any): string;

@@ -13,2 +13,3 @@ "use strict";

function codegenContractTypings(contract, codegenConfig) {
const { alwaysGenerateOverloads } = codegenConfig;
const source = `

@@ -18,18 +19,17 @@ ${(0, structs_1.generateStructTypes)((0, lodash_1.values)(contract.structs).map((v) => v[0]))}

export interface ${contract.name}Interface extends utils.Interface {
contractName: '${contract.name}';
${codegenConfig.discriminateTypes ? `contractName: '${contract.name}';\n` : ``}
functions: {
${(0, lodash_1.values)(contract.functions)
.map((v) => v[0])
.map(functions_1.generateInterfaceFunctionDescription)
.flatMap((v) => v.map(functions_1.generateInterfaceFunctionDescription))
.join('\n')}
};
${(0, functions_1.generateGetFunction)((0, lodash_1.values)(contract.functions).flatMap((v) => processDeclaration(v, alwaysGenerateOverloads, functions_1.generateFunctionNameOrSignature)))}
${(0, lodash_1.values)(contract.functions)
.map((v) => v[0])
.map(functions_1.generateEncodeFunctionDataOverload)
.flatMap((v) => processDeclaration(v, alwaysGenerateOverloads, functions_1.generateEncodeFunctionDataOverload))
.join('\n')}
${(0, lodash_1.values)(contract.functions)
.map((v) => v[0])
.map(functions_1.generateDecodeFunctionResultOverload)
.flatMap((v) => processDeclaration(v, alwaysGenerateOverloads, functions_1.generateDecodeFunctionResultOverload))
.join('\n')}

@@ -39,4 +39,3 @@

${(0, lodash_1.values)(contract.events)
.map((v) => v[0])
.map(events_1.generateInterfaceEventDescription)
.flatMap((v) => v.map(events_1.generateInterfaceEventDescription))
.join('\n')}

@@ -46,4 +45,3 @@ };

${(0, lodash_1.values)(contract.events)
.map((v) => v[0])
.map(events_1.generateGetEventOverload)
.flatMap((v) => processDeclaration(v, alwaysGenerateOverloads, events_1.generateGetEvent))
.join('\n')}

@@ -55,3 +53,3 @@ }

export interface ${contract.name} extends BaseContract {
contractName: '${contract.name}';
${codegenConfig.discriminateTypes ? `contractName: '${contract.name}';\n` : ``}
connect(signerOrProvider: Signer | Provider | string): this;

@@ -98,4 +96,7 @@ attach(addressOrName: string): this;

}`;
const commonPath = contract.path.length
? `${new Array(contract.path.length).fill('..').join('/')}/common`
: './common';
const imports = (0, typechain_1.createImportsForUsedIdentifiers)({
ethers: [
'type ethers': [
'BaseContract',

@@ -113,11 +114,11 @@ 'BigNumber',

],
'@ethersproject/abi': ['FunctionFragment', 'Result', 'EventFragment'],
'@ethersproject/providers': ['Listener', 'Provider'],
'type @ethersproject/abi': ['FunctionFragment', 'Result', 'EventFragment'],
'type @ethersproject/providers': ['Listener', 'Provider'],
}, source) +
'\n' +
(0, typechain_1.createImportTypeDeclaration)(events_1.EVENT_IMPORTS, './common');
(0, typechain_1.createImportTypeDeclaration)(events_1.EVENT_IMPORTS, commonPath);
return imports + source;
}
exports.codegenContractTypings = codegenContractTypings;
function codegenContractFactory(contract, abi, bytecode) {
function codegenContractFactory(codegenConfig, contract, abi, bytecode) {
var _a;

@@ -146,17 +147,17 @@ const constructorArgs = (contract.constructor[0] ? (0, types_1.generateInputTypes)(contract.constructor[0].inputs, { useStructs: true }) : '') +

export class ${contract.name}${common_1.FACTORY_POSTFIX} extends ContractFactory {
${generateFactoryConstructor(contract, bytecode)}
deploy(${constructorArgs}): Promise<${contract.name}> {
${generateFactoryConstructor(codegenConfig, contract, bytecode)}
override deploy(${constructorArgs}): Promise<${contract.name}> {
return super.deploy(${constructorArgNames}) as Promise<${contract.name}>;
}
getDeployTransaction(${constructorArgs}): TransactionRequest {
override getDeployTransaction(${constructorArgs}): TransactionRequest {
return super.getDeployTransaction(${constructorArgNames});
};
attach(address: string): ${contract.name} {
override attach(address: string): ${contract.name} {
return super.attach(address) as ${contract.name};
}
connect(signer: Signer): ${contract.name}${common_1.FACTORY_POSTFIX} {
override connect(signer: Signer): ${contract.name}${common_1.FACTORY_POSTFIX} {
return super.connect(signer) as ${contract.name}${common_1.FACTORY_POSTFIX};
}
static readonly contractName: '${contract.name}';
public readonly contractName: '${contract.name}';
${codegenConfig.discriminateTypes ? `static readonly contractName: '${contract.name}';\n` : ``}
${codegenConfig.discriminateTypes ? `public readonly contractName: '${contract.name}';\n` : ``}
static readonly bytecode = _bytecode;

@@ -175,7 +176,7 @@ ${body}

'PayableOverrides',
'Overrides',
'BytesLike',
'BigNumberish',
'Overrides',
],
'@ethersproject/providers': ['Provider', 'TransactionRequest'],
'type @ethersproject/providers': ['Provider', 'TransactionRequest'],
}, source);

@@ -189,3 +190,3 @@ return imports + source;

import { Contract, Signer, utils } from "ethers";
import { Provider } from "@ethersproject/providers";
import type { Provider } from "@ethersproject/providers";
${header}

@@ -208,4 +209,5 @@

});
const contractTypesImportPath = [...Array(contract.path.length + 1).fill('..'), ...contract.path, contract.name].join('/');
const header = `
import type { ${[...imports.values()].join(', ')} } from "../${contract.name}";
import type { ${[...imports.values()].join(', ')} } from "${contractTypesImportPath}";

@@ -225,3 +227,3 @@ const _abi = ${JSON.stringify(abi, null, 2)};

}
function generateFactoryConstructor(contract, bytecode) {
function generateFactoryConstructor(codegenConfig, contract, bytecode) {
if (!bytecode.linkReferences) {

@@ -235,3 +237,3 @@ return `

}
this.contractName = '${contract.name}';
${codegenConfig.discriminateTypes ? `this.contractName = '${contract.name}';` : ''}
}

@@ -267,3 +269,3 @@ `;

}
this.contractName = '${contract.name}';
${codegenConfig.discriminateTypes ? `this.contractName = '${contract.name}';` : ''}
}

@@ -313,2 +315,18 @@

}
/**
* Instruments code generator based on the number of overloads and config flag.
*
* @param fns - overloads of the function
* @param forceGenerateOverloads - flag to force generation of overloads.
* If set to true, full signatures will be used even if the function is not overloaded.
* @param stringGen - function generating source code based on the declaration
* @returns generated source code
*/
function processDeclaration(fns, forceGenerateOverloads, stringGen) {
// Function is overloaded, we need unambiguous signatures
if (fns.length > 1) {
return fns.map((fn) => stringGen(fn, true));
}
return [stringGen(fns[0], false), forceGenerateOverloads && stringGen(fns[0], true)].filter(lodash_1.isString);
}
//# sourceMappingURL=index.js.map

@@ -37,12 +37,3 @@ "use strict";

case 'array':
if (evmType.structName && !options.useStructs) {
// This emits right-hand side of struct type declaration.
// Example: `export type Struct3Struct = { input1: BigNumberish[] };`
return `(${generateInputType({ ...options, useStructs: true }, evmType.itemType)})`;
}
else {
return generateArrayOrTupleType(evmType.structName
? evmType.structName.toString() + common_1.STRUCT_INPUT_POSTFIX
: generateInputType({ ...options, useStructs: true }, evmType.itemType), evmType.size);
}
return generateArrayOrTupleType(generateInputType(options, evmType.itemType), evmType.size);
case 'boolean':

@@ -75,10 +66,3 @@ return 'boolean';

case 'array':
if (evmType.structName && !options.useStructs) {
// This emits right-hand side of struct type declaration.
// Example: `export type Struct3StructOutput = [BigNumber[]] & { input1: BigNumber[] };`
return `(${generateOutputType({ ...options, useStructs: true }, evmType.itemType)})`;
}
return generateArrayOrTupleType(evmType.structName
? evmType.structName.toString() + common_1.STRUCT_OUTPUT_POSTFIX
: generateOutputType({ ...options, useStructs: true }, evmType.itemType), evmType.size);
return generateArrayOrTupleType(generateOutputType(options, evmType.itemType), evmType.size);
case 'boolean':

@@ -133,5 +117,5 @@ return 'boolean';

else {
return `(${item})[]`;
return `${item}[]`;
}
}
//# sourceMappingURL=types.js.map
import { BytecodeWithLinkReferences, CodegenConfig, Config, Contract, FileDescription, TypeChainTarget } from 'typechain';
export interface IEthersCfg {
outDir?: string;
}
export default class Ethers extends TypeChainTarget {
name: string;
private readonly allContracts;
private readonly allFiles;
private readonly outDirAbs;
private readonly contractCache;
private readonly contractsWithoutBytecode;
private readonly bytecodeCache;

@@ -21,3 +18,2 @@ constructor(config: Config);

afterRun(): FileDescription[];
private genReExports;
}

@@ -15,7 +15,11 @@ "use strict";

this.name = 'Ethers';
this.contractCache = {};
this.contractsWithoutBytecode = {};
this.bytecodeCache = {};
panicOnOldTypeScriptVersion();
const { cwd, outDir, allFiles } = config;
this.allFiles = allFiles
.map((p) => (0, typechain_1.shortenFullJsonFilePath)(p, allFiles))
.map((p) => (0, path_1.relative)(this.cfg.inputDir, p))
.map(typechain_1.normalizeSlashes);
this.outDirAbs = (0, path_1.resolve)(cwd, outDir || DEFAULT_OUT_PATH);
this.allContracts = allFiles.map((fp) => (0, typechain_1.normalizeName)((0, typechain_1.getFilename)(fp)));
}

@@ -34,3 +38,2 @@ transformFile(file) {

transformBinFile(file) {
const name = (0, typechain_1.getFilename)(file.path);
const bytecode = (0, typechain_1.extractBytecode)(file.contents);

@@ -40,13 +43,12 @@ if (!bytecode) {

}
if (this.contractCache[name]) {
const { contract, abi } = this.contractCache[name];
delete this.contractCache[name];
if (this.contractsWithoutBytecode[file.path]) {
const { contract, abi } = this.contractsWithoutBytecode[file.path];
delete this.contractsWithoutBytecode[file.path];
return [this.genContractFactoryFile(contract, abi, bytecode)];
}
else {
this.bytecodeCache[name] = bytecode;
this.bytecodeCache[file.path] = bytecode;
}
}
transformAbiOrFullJsonFile(file) {
const name = (0, typechain_1.getFilename)(file.path);
const abi = (0, typechain_1.extractAbi)(file.contents);

@@ -57,4 +59,5 @@ if (abi.length === 0) {

const documentation = (0, typechain_1.extractDocumentation)(file.contents);
const contract = (0, typechain_1.parse)(abi, name, documentation);
const bytecode = (0, typechain_1.extractBytecode)(file.contents) || this.bytecodeCache[name];
const path = (0, path_1.relative)(this.cfg.inputDir, (0, typechain_1.shortenFullJsonFilePath)(file.path, this.cfg.allFiles));
const contract = (0, typechain_1.parse)(abi, path, documentation);
const bytecode = (0, typechain_1.extractBytecode)(file.contents) || this.bytecodeCache[file.path];
if (bytecode) {

@@ -67,3 +70,3 @@ return [

else {
this.contractCache[name] = { abi, contract };
this.contractsWithoutBytecode[file.path] = { abi, contract };
return [this.genContractTypingsFile(contract, this.cfg.flags)];

@@ -74,3 +77,3 @@ }

return {
path: (0, path_1.join)(this.outDirAbs, `${contract.name}.ts`),
path: (0, path_1.join)(this.outDirAbs, ...contract.path, `${contract.name}.ts`),
contents: (0, codegen_1.codegenContractTypings)(contract, codegenConfig),

@@ -81,4 +84,4 @@ };

return {
path: (0, path_1.join)(this.outDirAbs, 'factories', `${contract.name}${common_1.FACTORY_POSTFIX}.ts`),
contents: (0, codegen_1.codegenContractFactory)(contract, abi, bytecode),
path: (0, path_1.join)(this.outDirAbs, 'factories', ...contract.path, `${contract.name}${common_1.FACTORY_POSTFIX}.ts`),
contents: (0, codegen_1.codegenContractFactory)(this.cfg.flags, contract, abi, bytecode),
};

@@ -89,43 +92,85 @@ }

// generate a simplified factory, that allows to interact with deployed contract instances.
const abstractFactoryFiles = Object.keys(this.contractCache).map((contractName) => {
const { contract, abi } = this.contractCache[contractName];
const abstractFactoryFiles = Object.keys(this.contractsWithoutBytecode).map((contractName) => {
const { contract, abi } = this.contractsWithoutBytecode[contractName];
return {
path: (0, path_1.join)(this.outDirAbs, 'factories', `${contract.name}${common_1.FACTORY_POSTFIX}.ts`),
path: (0, path_1.join)(this.outDirAbs, 'factories', ...contract.path, `${contract.name}${common_1.FACTORY_POSTFIX}.ts`),
contents: (0, codegen_1.codegenAbstractContractFactory)(contract, abi),
};
});
const common = {
path: (0, path_1.join)(this.outDirAbs, 'common.ts'),
contents: (0, fs_1.readFileSync)((0, path_1.join)(__dirname, '../static/common.ts'), 'utf-8'),
};
const allContracts = this.allFiles.map((path) => (0, typechain_1.normalizeName)((0, typechain_1.getFilename)(path)));
const hardhatHelper = this.cfg.flags.environment === 'hardhat'
? { path: (0, path_1.join)(this.outDirAbs, 'hardhat.d.ts'), contents: (0, hardhat_1.generateHardhatHelper)(this.allContracts) }
? { path: (0, path_1.join)(this.outDirAbs, 'hardhat.d.ts'), contents: (0, hardhat_1.generateHardhatHelper)(allContracts) }
: undefined;
const typesBarrels = (0, typechain_1.createBarrelFiles)(this.allFiles, { typeOnly: true });
const factoriesBarrels = (0, typechain_1.createBarrelFiles)(this.allFiles.map((s) => `factories/${s}`), { typeOnly: false, postfix: common_1.FACTORY_POSTFIX });
const allBarrels = typesBarrels.concat(factoriesBarrels);
const [rootIndexes, otherBarrels] = (0, lodash_1.partition)(allBarrels, (fd) => fd.path === 'index.ts');
const rootIndex = {
path: (0, path_1.join)(this.outDirAbs, 'index.ts'),
contents: createRootIndexContent(rootIndexes, this.allFiles),
};
const allFiles = (0, lodash_1.compact)([
common,
hardhatHelper,
rootIndex,
...abstractFactoryFiles,
{
path: (0, path_1.join)(this.outDirAbs, 'common.ts'),
contents: (0, fs_1.readFileSync)((0, path_1.join)(__dirname, '../static/common.ts'), 'utf-8'),
},
{
path: (0, path_1.join)(this.outDirAbs, 'index.ts'),
contents: this.genReExports(),
},
hardhatHelper,
...otherBarrels.map((fd) => ({
path: (0, path_1.join)(this.outDirAbs, fd.path),
contents: fd.contents,
})),
]);
return allFiles;
}
genReExports() {
const codegen = [];
const allContractsNoDuplicates = (0, lodash_1.uniqBy)(this.allContracts, (c) => (0, path_1.basename)(c));
for (const fileName of allContractsNoDuplicates) {
const desiredSymbol = fileName;
codegen.push(`export type { ${desiredSymbol} } from './${desiredSymbol}'`);
}
exports.default = Ethers;
// root index.ts reexports also from deeper paths
function createRootIndexContent(rootIndexes, paths) {
const contracts = paths.map(typechain_1.parseContractPath);
const rootReexports = (0, lodash_1.uniqBy)(Object.values(contracts), (c) => c.name).flatMap((c) => {
const path = c.path.length === 0 ? c.name : `${c.path.join('/')}/${c.name}`;
return [
`export type { ${c.name} } from './${path}';`,
`export { ${c.name}${common_1.FACTORY_POSTFIX} } from './factories/${path}${common_1.FACTORY_POSTFIX}';`,
];
});
const rootIndexContent = new Set([
...rootIndexes[0].contents.split('\n'),
...rootIndexes[1].contents.split('\n'),
...rootReexports,
]);
return [...rootIndexContent].join('\n');
}
function panicOnOldTypeScriptVersion() {
const requiredTSVersion = { major: 4, minor: 3 };
const targetEthersVersion = require('../package.json').version;
let major;
let minor;
try {
const { version } = require('typescript');
[major, minor] = version.split('.').map(Number);
if (major > requiredTSVersion.major || (major === requiredTSVersion.major && minor >= requiredTSVersion.minor)) {
// the user has current version
return;
}
codegen.push('\n');
// then generate reexports for TypeChain generated factories
for (const fileName of allContractsNoDuplicates) {
const desiredSymbol = fileName + '__factory';
codegen.push(`export { ${desiredSymbol} } from './factories/${desiredSymbol}'`);
}
return codegen.join('\n');
}
catch (err) {
// we couldn't require `typescript`
return;
}
const bold = (text) => `\x1b[1m${text}\x1b[0m`;
const tsStr = `${requiredTSVersion.major}.${requiredTSVersion.minor}`;
const errorMessage = `@typechain/ethers-v5 ${targetEthersVersion} needs TypeScript version ${tsStr} or newer.`;
// eslint-disable-next-line no-console
console.error(`
⚠ ${bold(errorMessage)}
Generated code will cause syntax errors in older TypeScript versions.
Your TypeScript version is ${major}.${minor}.
`);
throw new Error(errorMessage);
}
exports.default = Ethers;
//# sourceMappingURL=index.js.map

@@ -11,3 +11,3 @@ {

],
"version": "9.0.0",
"version": "10.0.0",
"license": "MIT",

@@ -24,26 +24,21 @@ "repository": "https://github.com/ethereum-ts/Typechain",

],
"scripts": {
"start": "ts-node -T ./src/index.ts",
"format": "prettier --config ../../.prettierrc --ignore-path ../../.prettierignore --check \"./**/*.ts\" README.md",
"format:fix": "prettier --config ../../.prettierrc --ignore-path ../../.prettierignore --write \"./**/*.ts\" README.md",
"lint": "eslint --ext .ts src test",
"lint:fix": "yarn lint --fix",
"typecheck": "tsc --noEmit --incremental false --composite false",
"clean": "rm -rf dist && rm -f tsconfig.build.tsbuildinfo",
"test": "mocha --config ../../.mocharc.js",
"test:fix": "yarn lint:fix && yarn format:fix && yarn test && yarn typecheck"
},
"peerDependencies": {
"typechain": "^7.0.0",
"typescript": ">=4.0.0",
"ethers": "^5.1.3",
"@ethersproject/abi": "^5.0.0",
"@ethersproject/bytes": "^5.0.0",
"@ethersproject/providers": "^5.0.0",
"@ethersproject/abi": "^5.0.0"
"ethers": "^5.1.3",
"typechain": "^8.0.0",
"typescript": ">=4.3.0"
},
"devDependencies": {
"ganache-cli": "^6.12.2",
"@ethersproject/abi": "^5.0.0",
"@ethersproject/bytes": "^5.0.0",
"@ethersproject/providers": "^5.0.0",
"@types/lodash": "^4.14.139",
"ethers": "^5.1.3",
"test-utils": "1.0.0",
"ethers": "^5.1.3",
"@types/lodash": "^4.14.139"
"typechain": "^8.0.0",
"typescript": ">=4.3.0",
"@types/proxyquire": "^1.3.28",
"proxyquire": "^2.1.3"
},

@@ -53,3 +48,16 @@ "dependencies": {

"ts-essentials": "^7.0.1"
}
}
},
"scripts": {
"start": "ts-node -T ./src/index.ts",
"build": "tsc --build ./tsconfig.build.json --verbose",
"format": "prettier --config ../../.prettierrc --ignore-path ../../.prettierignore --check \"./**/*.ts\" README.md",
"format:fix": "prettier --config ../../.prettierrc --ignore-path ../../.prettierignore --write \"./**/*.ts\" README.md",
"lint": "eslint --ext .ts src test",
"lint:fix": "pnpm lint --fix",
"typecheck": "tsc --noEmit --incremental false --composite false",
"clean": "rm -rf dist && rm -f tsconfig.build.tsbuildinfo",
"test": "mocha --config ../../.mocharc.js",
"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"
}

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

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

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc