Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

typechain

Package Overview
Dependencies
Maintainers
2
Versions
85
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

typechain - npm Package Compare versions

Comparing version 7.0.1 to 8.0.0

dist/codegen/createBarrelFiles.d.ts

8

dist/cli/cli.js

@@ -5,3 +5,7 @@ #!/usr/bin/env node

if (k2 === undefined) k2 = k;
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
var desc = Object.getOwnPropertyDescriptor(m, k);
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
desc = { enumerable: true, get: function() { return m[k]; } };
}
Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {

@@ -26,2 +30,3 @@ if (k2 === undefined) k2 = k;

const runTypeChain_1 = require("../typechain/runTypeChain");
const files_1 = require("../utils/files");
const glob_1 = require("../utils/glob");

@@ -45,2 +50,3 @@ const logger_1 = require("../utils/logger");

filesToProcess: files,
inputDir: cliConfig.inputDir || (0, files_1.detectInputsRoot)(files),
prettier,

@@ -47,0 +53,0 @@ flags: {

@@ -5,3 +5,5 @@ export interface ParsedArgs {

outDir?: string | undefined;
inputDir?: string | undefined;
flags: {
discriminateTypes: boolean;
alwaysGenerateOverloads: boolean;

@@ -8,0 +10,0 @@ tsNocheck: boolean;

@@ -20,2 +20,7 @@ "use strict";

'out-dir': { type: String, optional: true, description: 'Output directory for generated files.' },
'input-dir': {
type: String,
optional: true,
description: 'Directory containing ABI files. Inferred as lowest common path of all files if not specified.',
},
'always-generate-overloads': {

@@ -33,2 +38,7 @@ type: Boolean,

},
'discriminate-types': {
type: Boolean,
defaultValue: false,
description: 'ethers-v5 target will add an artificial field `contractName` that helps discriminate between contracts',
},
help: { type: Boolean, defaultValue: false, alias: 'h', description: 'Prints this message.' },

@@ -58,5 +68,7 @@ }, {

outDir: rawOptions['out-dir'],
inputDir: rawOptions['input-dir'],
target: rawOptions.target,
flags: {
alwaysGenerateOverloads: rawOptions['always-generate-overloads'],
discriminateTypes: rawOptions['discriminate-types'],
tsNocheck: rawOptions['ts-nocheck'],

@@ -63,0 +75,0 @@ },

7

dist/codegen/syntax.js

@@ -60,3 +60,3 @@ "use strict";

function createImportTypeDeclaration(identifiers, moduleSpecifier) {
return identifiers.length > 0 ? `import { ${identifiers.join(', ')} } from "${moduleSpecifier}"` : '';
return identifiers.length > 0 ? `import type { ${identifiers.join(', ')} } from "${moduleSpecifier}"` : '';
}

@@ -68,4 +68,7 @@ exports.createImportTypeDeclaration = createImportTypeDeclaration;

function createImportsForUsedIdentifiers(possibleImports, sourceFile) {
const typePrefix = 'type ';
return Object.entries(possibleImports)
.map(([moduleSpecifier, identifiers]) => createImportDeclaration(getUsedIdentifiers(identifiers, sourceFile), moduleSpecifier))
.map(([moduleSpecifier, identifiers]) => moduleSpecifier.startsWith(typePrefix)
? createImportTypeDeclaration(getUsedIdentifiers(identifiers, sourceFile), moduleSpecifier.substring(typePrefix.length))
: createImportDeclaration(getUsedIdentifiers(identifiers, sourceFile), moduleSpecifier))
.join('\n');

@@ -72,0 +75,0 @@ }

@@ -0,1 +1,2 @@

export * from './codegen/createBarrelFiles';
export * from './codegen/syntax';

@@ -2,0 +3,0 @@ export * from './parser/abiParser';

"use strict";
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
var desc = Object.getOwnPropertyDescriptor(m, k);
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
desc = { enumerable: true, get: function() { return m[k]; } };
}
Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {

@@ -14,2 +18,3 @@ if (k2 === undefined) k2 = k;

exports.normalizeName = void 0;
__exportStar(require("./codegen/createBarrelFiles"), exports);
__exportStar(require("./codegen/syntax"), exports);

@@ -16,0 +21,0 @@ __exportStar(require("./parser/abiParser"), exports);

@@ -41,2 +41,3 @@ import { Dictionary } from 'ts-essentials';

rawName: string;
path: string[];
fallback?: FunctionWithoutInputDeclaration | undefined;

@@ -106,3 +107,8 @@ constructor: FunctionWithoutOutputDeclaration[];

}
export declare function parse(abi: RawAbiDefinition[], rawName: string, documentation?: DocumentationResult): Contract;
export declare function parseContractPath(path: string): {
name: string;
rawName: string;
path: string[];
};
export declare function parse(abi: RawAbiDefinition[], path: string, documentation?: DocumentationResult): Contract;
export declare function parseEvent(abiPiece: RawEventAbiDefinition, registerStruct: (struct: StructType) => void): EventDeclaration;

@@ -109,0 +115,0 @@ export declare function getFunctionDocumentation(abiPiece: RawAbiDefinition, documentation?: DocumentationResult): FunctionDocumentation | undefined;

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.isConstantFn = exports.isConstant = exports.ensure0xPrefix = exports.extractDocumentation = exports.extractBytecode = exports.extractAbi = exports.getFunctionDocumentation = exports.parseEvent = exports.parse = void 0;
exports.isConstantFn = exports.isConstant = exports.ensure0xPrefix = exports.extractDocumentation = exports.extractBytecode = exports.extractAbi = exports.getFunctionDocumentation = exports.parseEvent = exports.parse = exports.parseContractPath = void 0;
const js_sha3_1 = require("js-sha3");
const lodash_1 = require("lodash");
const path_1 = require("path");
const debug_1 = require("../utils/debug");
const errors_1 = require("../utils/errors");
const files_1 = require("../utils/files");
const normalizeName_1 = require("./normalizeName");
const parseEvmType_1 = require("./parseEvmType");
function parse(abi, rawName, documentation) {
function parseContractPath(path) {
const parsedPath = (0, path_1.parse)((0, files_1.normalizeSlashes)(path));
return {
name: (0, normalizeName_1.normalizeName)(parsedPath.name),
rawName: parsedPath.name,
path: parsedPath.dir.split('/').filter((x) => x),
};
}
exports.parseContractPath = parseContractPath;
function parse(abi, path, documentation) {
const constructors = [];

@@ -18,2 +29,10 @@ let fallback;

var _a;
// ignore registration if structName not present
if (newStruct.structName === undefined)
return;
// if struct array (recursive) then keep going deep until we reach the struct tuple
while (newStruct.type === 'array') {
newStruct = newStruct.itemType;
}
// only register if not already registered
const newStructName = (_a = newStruct.structName) === null || _a === void 0 ? void 0 : _a.toString();

@@ -48,4 +67,3 @@ if (!structs.find((s) => { var _a; return ((_a = s.structName) === null || _a === void 0 ? void 0 : _a.toString()) === newStructName; })) {

return {
name: (0, normalizeName_1.normalizeName)(rawName),
rawName,
...parseContractPath(path),
fallback,

@@ -188,3 +206,3 @@ constructor: constructors,

function extractBytecode(rawContents) {
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k;
var _a, _b, _c, _d, _e, _f;
// When there are some unlinked libraries, the compiler replaces their addresses in calls with

@@ -207,3 +225,3 @@ // "link references". There are many different kinds of those, depending on compiler version and usage.

}
catch (_l) {
catch (_g) {
return undefined;

@@ -213,15 +231,20 @@ }

return undefined;
function tryMatchBytecode(obj) {
if (obj && obj.match instanceof Function) {
return obj.match(bytecodeRegex);
}
}
// `json.evm.bytecode` often has more information than `json.bytecode`, needs to be checked first
if ((_c = (_b = (_a = json.evm) === null || _a === void 0 ? void 0 : _a.bytecode) === null || _b === void 0 ? void 0 : _b.object) === null || _c === void 0 ? void 0 : _c.match(bytecodeRegex)) {
if (tryMatchBytecode((_b = (_a = json.evm) === null || _a === void 0 ? void 0 : _a.bytecode) === null || _b === void 0 ? void 0 : _b.object)) {
return extractLinkReferences(json.evm.bytecode.object, json.evm.bytecode.linkReferences);
}
// handle json schema of @0x/sol-compiler
if ((_g = (_f = (_e = (_d = json.compilerOutput) === null || _d === void 0 ? void 0 : _d.evm) === null || _e === void 0 ? void 0 : _e.bytecode) === null || _f === void 0 ? void 0 : _f.object) === null || _g === void 0 ? void 0 : _g.match(bytecodeRegex)) {
if (tryMatchBytecode((_e = (_d = (_c = json.compilerOutput) === null || _c === void 0 ? void 0 : _c.evm) === null || _d === void 0 ? void 0 : _d.bytecode) === null || _e === void 0 ? void 0 : _e.object)) {
return extractLinkReferences(json.compilerOutput.evm.bytecode.object, json.compilerOutput.evm.bytecode.linkReferences);
}
// handle json schema of @foundry/forge
if ((_j = (_h = json.bytecode) === null || _h === void 0 ? void 0 : _h.object) === null || _j === void 0 ? void 0 : _j.match(bytecodeRegex)) {
if (tryMatchBytecode((_f = json.bytecode) === null || _f === void 0 ? void 0 : _f.object)) {
return extractLinkReferences(json.bytecode.object, json.bytecode.linkReferences);
}
if ((_k = json.bytecode) === null || _k === void 0 ? void 0 : _k.match(bytecodeRegex)) {
if (tryMatchBytecode(json.bytecode)) {
return extractLinkReferences(json.bytecode, json.linkReferences);

@@ -228,0 +251,0 @@ }

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

(s) => s.replace(/\./g, '-'),
(s) => s.replace(/_/g, '-'),
(s) => s.replace(/-[a-z]/g, (match) => match.substr(-1).toUpperCase()),

@@ -15,0 +14,0 @@ (s) => s.replace(/-/g, ''),

@@ -39,3 +39,3 @@ "use strict";

type: 'array',
itemType: parseEvmType(restOfTheType, components),
itemType: parseEvmType(restOfTheType, components, internalType),
originalType: rawType,

@@ -42,0 +42,0 @@ };

"use strict";
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
var desc = Object.getOwnPropertyDescriptor(m, k);
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
desc = { enumerable: true, get: function() { return m[k]; } };
}
Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {

@@ -25,3 +29,3 @@ if (k2 === undefined) k2 = k;

const debug_1 = require("../utils/debug");
const files_1 = require("../utils/files");
const ensureAbsPath_1 = require("../utils/files/ensureAbsPath");
const modules_1 = require("../utils/modules");

@@ -34,6 +38,5 @@ function findTarget(config) {

const possiblePaths = [
process.env.NODE_ENV === 'test' && `../../typechain-target-${target}/lib/index`,
`@typechain/${target}`,
`typechain-target-${target}`,
(0, files_1.ensureAbsPath)(target), // path
(0, ensureAbsPath_1.ensureAbsPath)(target), // path
];

@@ -40,0 +43,0 @@ const moduleInfo = (0, lodash_1.default)(possiblePaths).compact().map(modules_1.tryRequire).compact().first();

"use strict";
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
var desc = Object.getOwnPropertyDescriptor(m, k);
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
desc = { enumerable: true, get: function() { return m[k]; } };
}
Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {

@@ -28,14 +32,20 @@ if (k2 === undefined) k2 = k;

const debug_1 = require("../utils/debug");
const files_1 = require("../utils/files");
const findTarget_1 = require("./findTarget");
const io_1 = require("./io");
const DEFAULT_FLAGS = {
alwaysGenerateOverloads: false,
discriminateTypes: false,
tsNocheck: false,
environment: undefined,
};
async function runTypeChain(publicConfig) {
const _config = {
flags: { alwaysGenerateOverloads: false, tsNocheck: false, environment: undefined },
...publicConfig,
};
const allFiles = (0, io_1.skipEmptyAbis)(publicConfig.allFiles);
// skip empty paths
const config = {
..._config,
allFiles: (0, io_1.skipEmptyAbis)(_config.allFiles),
filesToProcess: (0, io_1.skipEmptyAbis)(_config.filesToProcess),
flags: DEFAULT_FLAGS,
inputDir: (0, files_1.detectInputsRoot)(allFiles),
...publicConfig,
allFiles,
filesToProcess: (0, io_1.skipEmptyAbis)(publicConfig.filesToProcess),
};

@@ -42,0 +52,0 @@ const services = {

@@ -13,2 +13,7 @@ /// <reference types="node" />

allFiles: string[];
/**
* Optional path to directory with ABI files.
* If not specified, inferred to be lowest common path of all input files.
*/
inputDir: string;
flags: CodegenConfig;

@@ -18,6 +23,7 @@ }

alwaysGenerateOverloads: boolean;
discriminateTypes: boolean;
tsNocheck?: boolean;
environment: 'hardhat' | undefined;
}
export declare type PublicConfig = MarkOptional<Config, 'flags'>;
export declare type PublicConfig = MarkOptional<Config, 'flags' | 'inputDir'>;
export declare abstract class TypeChainTarget {

@@ -24,0 +30,0 @@ readonly cfg: Config;

@@ -7,7 +7,10 @@ "use strict";

try {
const module = {
module: require(name),
name,
path: require.resolve(name),
};
let path;
try {
path = require.resolve(name, { paths: [process.cwd()] });
}
catch (_a) {
path = require.resolve(name);
}
const module = { module: require(path), name, path };
(0, debug_1.debug)('Load successfully: ', name);

@@ -14,0 +17,0 @@ return module;

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

],
"version": "7.0.1",
"version": "8.0.0",
"license": "MIT",

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

],
"scripts": {
"start": "ts-node -T ./src/index.ts",
"format": "prettier --config ../../.prettierrc --ignore-path ../../.prettierignore --check \"./**/*.ts\"",
"format:fix": "prettier --config ../../.prettierrc --ignore-path ../../.prettierignore --write \"./**/*.ts\"",
"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",
"post-build": "ts-node scripts/post-build",
"test": "mocha --config ../../.mocharc.js",
"test:fix": "yarn lint:fix && yarn format:fix && yarn test && yarn typecheck"
},
"dependencies": {
"@types/prettier": "^2.1.1",
"debug": "^4.1.1",
"debug": "^4.3.1",
"fs-extra": "^7.0.0",
"glob": "^7.1.6",
"glob": "7.1.7",
"js-sha3": "^0.8.0",
"lodash": "^4.17.15",
"mkdirp": "^1.0.4",
"prettier": "^2.1.2",
"ts-command-line-args": "^2.2.0",
"prettier": "^2.3.1",
"ts-essentials": "^7.0.1"

@@ -55,3 +43,3 @@ },

"@types/mkdirp": "^1.0.1",
"@types/node": "^8.0.25",
"@types/node": "^14",
"bluebird": "^3.5.1",

@@ -61,4 +49,17 @@ "coveralls": "^3.0.2"

"peerDependencies": {
"typescript": ">=4.1.0"
}
}
"typescript": ">=4.3.0"
},
"scripts": {
"start": "ts-node -T ./src/index.ts",
"format": "prettier --config ../../.prettierrc --ignore-path ../../.prettierignore --check \"./**/*.ts\"",
"format:fix": "prettier --config ../../.prettierrc --ignore-path ../../.prettierignore --write \"./**/*.ts\"",
"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",
"post-build": "ts-node scripts/post-build",
"test": "mocha --config ../../.mocharc.js",
"test:fix": "pnpm lint:fix && pnpm format:fix && pnpm test && pnpm typecheck"
},
"readme": "<p align=\"center\">\n <img src=\"/docs/images/typechain-logo.png\" width=\"300\" alt=\"TypeChain\">\n <p align=\"center\">🔌 TypeScript bindings for Ethereum smart contracts</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=\"/package.json\"><img alt=\"Software License\" src=\"https://img.shields.io/badge/license-MIT-brightgreen.svg?style=flat-square\"></a>\n <a href=\"https://discord.gg/wQDkeDgzgv\"><img alt=\"Join our discord!\" src=\"https://img.shields.io/discord/895381864922091630.svg?color=7289da&label=deth&logo=discord&style=flat-square\"></a>\n </p>\n\n <p align=\"center\">\n <strong>💸 Enjoy using TypeChain? Consider funding development via <a href=\"https://gitcoin.co/grants/4038/deth-typechain\">GitCoin</a> 💸</strong>\n </p>\n\n <p align=\"center\">\n <i>Used by the best:</i> <br/>\n <img src=\"https://raw.githubusercontent.com/ethereum-ts/TypeChain/master/docs/images/maker-logo.png\" height=\"110\" alt=\"Maker DAO\" />\n <a href=\"https://github.com/Uniswap/uniswap-v3-core/blob/main/hardhat.config.ts#L1\"><img src=\"https://raw.githubusercontent.com/ethereum-ts/TypeChain/master/docs/images/uniswap-logo.png\" height=\"90\" alt=\"Uniswap\" /></a>\n <a href=\"https://github.com/aave/protocol-v2/blob/master/hardhat.config.ts#L16\"><img src=\"https://raw.githubusercontent.com/ethereum-ts/TypeChain/master/docs/images/aave-logo.png\" height=\"60\" alt=\"AAVE\" /></a>\n <br/>\n <a href=\"https://github.com/ethereum-optimism/optimism/blob/master/packages/contracts/hardhat.config.ts#L14\"><img src=\"https://raw.githubusercontent.com/ethereum-ts/TypeChain/master/docs/images/optimism-logo.png\" height=\"90\" alt=\"Optimism\" /></a>\n <a href=\"https://github.com/matter-labs/zksync/blob/9687049af1efbd14d8e47d97ebea643e1516da9d/contracts/hardhat.config.ts#L4\"><img src=\"https://raw.githubusercontent.com/ethereum-ts/TypeChain/master/docs/images/zksync-logo.png\" height=\"100\" alt=\"zkSync\" /></a>\n <a href=\"https://github.com/KyberNetwork/dao_sc/blob/master/hardhat.config.ts#L8\"><img src=\"https://raw.githubusercontent.com/ethereum-ts/TypeChain/master/docs/images/kyber-logo.png\" height=\"100\" alt=\"Kyber\" /></a>\n <a href=\"https://github.com/OffchainLabs/arbitrum/blob/133ac08dbf423ce7ca79343260869e46bf02a543/packages/arb-bridge-eth/package.json#L39\"><img src=\"https://raw.githubusercontent.com/ethereum-ts/TypeChain/master/docs/images/arbitrum-logo.png\" height=\"100\" alt=\"Arbitrum\" /></a>\n </p>\n</p>\n\n## Features ⚡\n\n- static typing - you will never call not existing method again\n- IDE support - works with any IDE supporting Typescript\n- extendible - work with many different tools: `ethers.js`, `hardhat`, `truffle`, `Web3.js` or you can create your own\n target\n- frictionless - works with simple, JSON ABI files as well as with Truffle/Hardhat artifacts\n\n## Installation\n\n```bash\nnpm install --save-dev typechain\n```\n\nYou will also need to install a desired target for example `@typechain/ethers-v5`. [Learn more about targets](#targets-)\n\n_Take note, that code generated by TypeChain requires TypeScript version 4.3 or newer._\n\n## Packages 📦\n\n| Package | Version | Description | Examples |\n| ------------------------------------------------------------------------------------------------------------------------------------------- | --------------------------------------------------------------------------------------------------------------------- | -------------------------------------------- | -------------------------------------------------------------------------------------------------------------------- |\n| [`typechain`](/packages/typechain) | [![npm](https://img.shields.io/npm/v/typechain.svg)](https://www.npmjs.com/package/typechain) | Core package | - |\n| [`@typechain/ethers-v5`](/packages/target-ethers-v5) | [![npm](https://img.shields.io/npm/v/@typechain/ethers-v5.svg)](https://www.npmjs.com/package/@typechain/ethers-v5) | Ethers ver 5 support (⚠️ requires TS 4.0 >=) | [example](./examples/ethers-v5) |\n| [`@typechain/truffle-v5`](/packages/target-truffle-v5) | [![npm](https://img.shields.io/npm/v/@typechain/truffle-v5.svg)](https://www.npmjs.com/package/@typechain/truffle-v5) | Truffle ver 5 support | [example](./examples/truffle-v5) |\n| [`@typechain/web3-v1`](/packages/target-web3-v1) | [![npm](https://img.shields.io/npm/v/@typechain/web3-v1.svg)](https://www.npmjs.com/package/@typechain/web3-v1) | Web3 ver 1 support | [example](./examples/web3-v1) |\n| [`@typechain/hardhat`](/packages/hardhat) | [![npm](https://img.shields.io/npm/v/@typechain/hardhat.svg)](https://www.npmjs.com/package/@typechain/hardhat) | Hardhat plugin | [example-ethers](./examples/hardhat) [example-truffle](./examples/hardhat-truffle) |\n| [`@typechain/truffle-v4`](https://github.com/dethcrypto/TypeChain/tree/fb96e1cf06c8c4c17cd79a1743362bd3d34eab76/packages/target-truffle-v4) | [![npm](https://img.shields.io/npm/v/@typechain/truffle-v4.svg)](https://www.npmjs.com/package/@typechain/truffle-v4) | Truffle ver 4 support **(deprecated)** | [example](https://github.com/dethcrypto/TypeChain/tree/fb96e1cf06c8c4c17cd79a1743362bd3d34eab76/examples/truffle-v4) |\n| [`@typechain/ethers-v4`](/packages/target-ethers-v4) | [![npm](https://img.shields.io/npm/v/@typechain/ethers-v4.svg)](https://www.npmjs.com/package/@typechain/ethers-v4) | Ethers ver 4 support **(deprecated)** | [example](https://github.com/dethcrypto/TypeChain/tree/db551b5c5f70e86f3ca342551e9e0369d099cfa2/examples/ethers-v4) |\n\n### eth-sdk\n\nTypeChain generates only TypeScript typings (`d.ts`) files, if you're looking for \"opionated\", \"batteries included\"\nsolution check out our new project: [eth-sdk](https://github.com/dethcrypto/eth-sdk). It generates typesafe, ready to\nuse ethers.js wrappers and uses etherscan/sourcify to automatically get ABIs based only on smart contract addresses.\nUnder the hood, `eth-sdk` relies on `TypeChain`.\n\n## Usage\n\n### CLI\n\n_Note: If you use hardhat just use\n[hardhat plugin](https://github.com/ethereum-ts/TypeChain/tree/master/packages/hardhat)._\n\n```\ntypechain --target=(ethers-v5|truffle-v4|truffle-v5|web3-v1|path-to-custom-target) [glob]\n```\n\n- `glob` - pattern that will be used to find ABIs, remember about adding quotes: `typechain \"**/*.json\"`, examples:\n `./abis/**/*.abi`, `./abis/?(Oasis.abi|OasisHelper.abi)`.\n- `--target` - ethers-v5, truffle-v4, truffle-v5, web3-v1 or path to your custom target. Typechain will try to load\n package named: `@typechain/${target}`, so make sure that desired package is installed.\n- `--out-dir` (optional) - put all generated files to a specific dir.\n- `--always-generate-overloads` (optional) - some targets won't generate unnecessary types for overloaded functions by\n default, this option forces to always generate them\n- `--discriminate-types` (optional) - ethers-v5 will add an artificial field `contractName` that helps discriminate\n between contracts\n\nTypeChain always will rewrite existing files. You should not commit them. Read more in FAQ section.\n\nExample:\n\n```\ntypechain --target ethers-v5 --out-dir app/contracts './node_modules/neufund-contracts/build/contracts/*.json'\n```\n\n## Videos\n\n- [Devcon5 Video (2019)](https://www.youtube.com/watch?v=Ho4dGNKVkTE)\n\n## Getting started 📚\n\n### Motivation\n\nInteracting with blockchain in Javascript is a pain. Developers need to remember not only a name of a given smart\ncontract method or event but also it's full signature. This wastes time and might introduce bugs that will be triggered\nonly in runtime. TypeChain solves these problems (as long as you use TypeScript).\n\n### How does it work?\n\nTypeChain is a code generator - provide ABI file and name of your blockchain access library (ethers/truffle/web3.js) and\nyou will get TypeScript typings compatible with a given library.\n\n### Step by step guide\n\nInstall TypeChain with `npm install --save-dev typechain` and install desired target.\n\nRun `typechain --target=your_target` (you might need to make sure that it's available in your path if you installed it\nonly locally), it will automatically find all `.abi` files in your project and generate Typescript classes based on\nthem. You can specify your glob pattern: `typechain --target=your_target \"**/*.abi.json\"`. `node_modules` are always\nignored. We recommend git ignoring these generated files and making typechain part of your build process.\n\nThat's it! Now, you can simply import typings, check out our examples for more details.\n\n## Targets 🎯\n\n### Ethers.js v5\n\nUse `ethers-v5` target to generate wrappers for [ethers.js](https://github.com/ethers-io/ethers.js/) lib. To make it\nwork great with Hardhat, use [Hardhat plugin](https://github.com/ethereum-ts/TypeChain/tree/master/packages/hardhat).\n\nIf you're using Ethers.js v4, you can find legacy `@typechain/ethers-v4` target on\n[npm](https://www.npmjs.com/package/@typechain/ethers-v4) and commit\n[`db551b5`](https://github.com/dethcrypto/TypeChain/tree/db551b5c5f70e86f3ca342551e9e0369d099cfa2).\n\n### Truffle v5\n\nTruffle target is great when you use truffle contracts already. Check out\n[truffle-typechain-example](https://github.com/ethereum-ts/truffle-typechain-example) for more details. It require\ninstalling [typings](https://www.npmjs.com/package/truffle-typings) for truffle library itself.\n\nNow you can simply use your contracts as you did before and get full type safety, yay!\n\n### Web3 v1\n\nGenerates typings for contracts compatible with latest stable Web3.js version. Typings for library itself are now part\nof the `Web3 1.0.0` library so nothing additional is needed. For now it needs explicit cast as shown\n[here](https://github.com/krzkaczor/TypeChain/pull/88/files#diff-540a9b8840419be93ddb8d4b53325637R8), this will be fixed\nafter improving official typings.\n\n### NatSpec support\n\nIf you provide solidity artifacts rather than plain ABIs as an input, TypeChain can generate NatSpec comments directly\nto your typings which enables simple access to docs while coding.\n\n### Your own target\n\nThis might be useful when you're creating a library for users of your smartcontract and you don't want to lock yourself\ninto any API provided by Web3 access providing library. You can generate basically any code (even for different\nlanguages than TypeScript!) that based on smartcontract's ABI.\n\n## FAQ 🤔\n\n### Q: Should I commit generated files to my repository?\n\nA: _NO_ — we believe that no generated files should go to git repository. You should git ignore them and make\n`typechain` run automatically for example in post install hook in package.json:\n\n```\n\"postinstall\":\"typechain\"\n```\n\nWhen you update ABI, just regenerate files with TypeChain and Typescript compiler will find any breaking changes for\nyou.\n\n### Q: How do I customize generated code?\n\nA: You can create your own target and generate basically any code.\n\n### Q: Generated files won't match current codestyle of my project :(\n\nA: We will automatically format generated classes with `prettier` to match your coding preferences (just make sure to\nuse `.prettierrc` file).\n\nFurthermore, TypeChain will silent `eslint` and `tslint` errors for generated files.\n\n### Usage as API\n\n```typescript\nimport { runTypeChain, glob } from 'typechain'\n\nasync function main() {\n const cwd = process.cwd()\n // find all files matching the glob\n const allFiles = glob(cwd, [`${config.paths.artifacts}/!(build-info)/**/+([a-zA-Z0-9_]).json`])\n\n const result = await runTypeChain({\n cwd,\n filesToProcess: allFiles,\n allFiles,\n outDir: 'out directory',\n target: 'target name',\n })\n}\n\nmain().catch(console.error)\n```\n\nIf you don't care about incremental generation just specify the same set of files for `filesToProcess` and `allFiles`.\nFor incremental generation example read the source code of\n[hardhat plugin](https://github.com/ethereum-ts/TypeChain/blob/master/packages/hardhat/src/index.ts).\n\n# Contributing\n\nCheck out our [contributing guidelines](./CONTRIBUTING.md)\n\n# Licence\n\nKris Kaczor (krzkaczor) MIT | [Github](https://github.com/krzkaczor) | [Twitter](https://twitter.com/krzkaczor)\n"
}
<p align="center">
<img src="https://github.com/Neufund/TypeChain/blob/d82f3cc644a11e22ca8e42505c16f035e2f2555d/docs/images/typechain-logo.png?raw=true" width="300" alt="TypeChain">
<h3 align="center">TypeChain</h3>
<img src="/docs/images/typechain-logo.png" width="300" alt="TypeChain">
<p align="center">🔌 TypeScript bindings for Ethereum smart contracts</p>

@@ -12,3 +11,3 @@

</p>
<p align="center">

@@ -45,4 +44,6 @@ <strong>💸 Enjoy using TypeChain? Consider funding development via <a href="https://gitcoin.co/grants/4038/deth-typechain">GitCoin</a> 💸</strong>

You will also need to install a desired target for example `@typechain/ethers-v4`. [Learn more about targets](#targets-)
You will also need to install a desired target for example `@typechain/ethers-v5`. [Learn more about targets](#targets-)
_Take note, that code generated by TypeChain requires TypeScript version 4.3 or newer._
## Packages 📦

@@ -54,7 +55,7 @@

| [`@typechain/ethers-v5`](/packages/target-ethers-v5) | [![npm](https://img.shields.io/npm/v/@typechain/ethers-v5.svg)](https://www.npmjs.com/package/@typechain/ethers-v5) | Ethers ver 5 support (⚠️ requires TS 4.0 >=) | [example](./examples/ethers-v5) |
| [`@typechain/ethers-v4`](/packages/target-ethers-v4) | [![npm](https://img.shields.io/npm/v/@typechain/ethers-v4.svg)](https://www.npmjs.com/package/@typechain/ethers-v4) | Ethers ver 4 support | [example](./examples/ethers-v4) |
| [`@typechain/truffle-v5`](/packages/target-truffle-v5) | [![npm](https://img.shields.io/npm/v/@typechain/truffle-v5.svg)](https://www.npmjs.com/package/@typechain/truffle-v5) | Truffle ver 5 support | [example](./examples/truffle-v5) |
| [`@typechain/web3-v1`](/packages/target-web3-v1) | [![npm](https://img.shields.io/npm/v/@typechain/web3-v1.svg)](https://www.npmjs.com/package/@typechain/web3-v1) | Web3 ver 1 support | [example](./examples/web3-v1) |
| [`@typechain/hardhat`](/packages/hardhat) | [![npm](https://img.shields.io/npm/v/@typechain/hardhat.svg)](https://www.npmjs.com/package/@typechain/hardhat) | Hardhat plugin | [example-ethers](./examples/hardhat) [example-truffle](./examples/hardhat-truffle) |
| [`@typechain/truffle-v4`](https://github.com/dethcrypto/TypeChain/tree/fb96e1cf06c8c4c17cd79a1743362bd3d34eab76/packages/target-truffle-v4) | [![npm](https://img.shields.io/npm/v/@typechain/truffle-v4.svg)](https://www.npmjs.com/package/@typechain/truffle-v4) | Truffle ver 4 support (deprecated) | [example](https://github.com/dethcrypto/TypeChain/tree/fb96e1cf06c8c4c17cd79a1743362bd3d34eab76/examples/truffle-v4) |
| [`@typechain/truffle-v4`](https://github.com/dethcrypto/TypeChain/tree/fb96e1cf06c8c4c17cd79a1743362bd3d34eab76/packages/target-truffle-v4) | [![npm](https://img.shields.io/npm/v/@typechain/truffle-v4.svg)](https://www.npmjs.com/package/@typechain/truffle-v4) | Truffle ver 4 support **(deprecated)** | [example](https://github.com/dethcrypto/TypeChain/tree/fb96e1cf06c8c4c17cd79a1743362bd3d34eab76/examples/truffle-v4) |
| [`@typechain/ethers-v4`](/packages/target-ethers-v4) | [![npm](https://img.shields.io/npm/v/@typechain/ethers-v4.svg)](https://www.npmjs.com/package/@typechain/ethers-v4) | Ethers ver 4 support **(deprecated)** | [example](https://github.com/dethcrypto/TypeChain/tree/db551b5c5f70e86f3ca342551e9e0369d099cfa2/examples/ethers-v4) |

@@ -76,3 +77,3 @@ ### eth-sdk

```
typechain --target=(ethers-v4|ethers-v5|truffle-v4|truffle-v5|web3-v1|path-to-custom-target) [glob]
typechain --target=(ethers-v5|truffle-v4|truffle-v5|web3-v1|path-to-custom-target) [glob]
```

@@ -82,7 +83,9 @@

`./abis/**/*.abi`, `./abis/?(Oasis.abi|OasisHelper.abi)`.
- `--target` - ethers-v4, ethers-v5, truffle-v4, truffle-v5, web3-v1 or path to your custom target. Typechain will try
to load package named: `@typechain/${target}`, so make sure that desired package is installed.
- `--target` - ethers-v5, truffle-v4, truffle-v5, web3-v1 or path to your custom target. Typechain will try to load
package named: `@typechain/${target}`, so make sure that desired package is installed.
- `--out-dir` (optional) - put all generated files to a specific dir.
- `--always-generate-overloads` (optional) - some targets won't generate unnecessary types for overloaded functions by
default, this option forces to always generate them
- `--discriminate-types` (optional) - ethers-v5 will add an artificial field `contractName` that helps discriminate
between contracts

@@ -116,3 +119,3 @@ TypeChain always will rewrite existing files. You should not commit them. Read more in FAQ section.

Install TypeChain with `yarn add --dev typechain` and install desired target.
Install TypeChain with `npm install --save-dev typechain` and install desired target.

@@ -128,3 +131,3 @@ Run `typechain --target=your_target` (you might need to make sure that it's available in your path if you installed it

### Ethers.js v4 / v5
### Ethers.js v5

@@ -134,4 +137,8 @@ Use `ethers-v5` target to generate wrappers for [ethers.js](https://github.com/ethers-io/ethers.js/) lib. To make it

### Truffle v4 / v5
If you're using Ethers.js v4, you can find legacy `@typechain/ethers-v4` target on
[npm](https://www.npmjs.com/package/@typechain/ethers-v4) and commit
[`db551b5`](https://github.com/dethcrypto/TypeChain/tree/db551b5c5f70e86f3ca342551e9e0369d099cfa2).
### Truffle v5
Truffle target is great when you use truffle contracts already. Check out

@@ -138,0 +145,0 @@ [truffle-typechain-example](https://github.com/ethereum-ts/truffle-typechain-example) for more details. It require

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

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