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 4.0.3 to 5.0.0

dist/codegen/outputTransformers/index.d.ts

12

CHANGELOG.md
# typechain
## 5.0.0
### Major Changes
- d60a343: Rename `--outDir` CLI option to `--out-dir`
- 5a60d00: Remove dependency on `ts-generator`
### Minor Changes
- d60a343: Add `--always-generate-overloads` option and by default stop generating types for overloaded functions if
there are no overloads (reduces bloat)
## 4.0.3

@@ -4,0 +16,0 @@

41

dist/cli/cli.js
#!/usr/bin/env node
"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]; } });
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
o["default"] = v;
});
var __importStar = (this && this.__importStar) || function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
__setModuleDefault(result, mod);
return result;
};
Object.defineProperty(exports, "__esModule", { value: true });
const ts_generator_1 = require("ts-generator");
const parseArgs_1 = require("./parseArgs");
const TypeChain_1 = require("../TypeChain");
const runTypeChain_1 = require("../typechain/runTypeChain");
const logger_1 = require("../utils/logger");
const glob_1 = require("../utils/glob");
const prettier = __importStar(require("prettier"));
async function main() {
;
global.IS_CLI = true;
const options = parseArgs_1.parseArgs();
const cliConfig = parseArgs_1.parseArgs();
const cwd = process.cwd();
await ts_generator_1.tsGenerator({ cwd, loggingLvl: 'info' }, new TypeChain_1.TypeChain({ cwd, rawConfig: options }));
const config = {
cwd,
target: cliConfig.target,
outDir: cliConfig.outDir,
allFiles: glob_1.glob(cwd, cliConfig.files),
filesToProcess: glob_1.glob(cwd, cliConfig.files),
prettier,
flags: {
...cliConfig.flags,
environment: undefined,
},
};
const result = await runTypeChain_1.runTypeChain(config);
console.log(`Successfully generated ${result.filesGenerated} typings!`);
}

@@ -15,0 +48,0 @@ main().catch((e) => {

5

dist/cli/parseArgs.d.ts
export interface IOptions {
files: string;
files: string[];
target: string;
outDir?: string;
flags: {
alwaysGenerateOverloads: boolean;
};
}
export declare function parseArgs(): IOptions;

@@ -11,12 +11,16 @@ "use strict";

const optionDefinitions = [
{ name: 'glob', type: String, defaultOption: true },
{ name: 'glob', type: String, defaultOption: true, multiple: true },
{ name: 'target', type: String },
{ name: 'outDir', type: String },
{ name: 'out-dir', type: String },
{ name: 'show-stack-traces', type: Boolean },
{ name: 'always-generate-overloads', type: Boolean },
];
const rawOptions = command_line_args_1.default(optionDefinitions);
return {
files: rawOptions.glob || DEFAULT_GLOB_PATTERN,
outDir: rawOptions.outDir,
files: rawOptions.glob || [DEFAULT_GLOB_PATTERN],
outDir: rawOptions['out-dir'],
target: rawOptions.target,
flags: {
alwaysGenerateOverloads: rawOptions['always-generate-overloads'] || false,
},
};

@@ -23,0 +27,0 @@ }

@@ -5,1 +5,6 @@ export * from './parser/abiParser';

export * from './utils/signatures';
export * from './typechain/types';
export * from './typechain/runTypeChain';
export * from './utils/glob';
export * from './typechain/types';
export { normalizeName } from './parser/normalizeName';

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

Object.defineProperty(exports, "__esModule", { value: true });
exports.normalizeName = void 0;
__exportStar(require("./parser/abiParser"), exports);

@@ -18,2 +19,8 @@ __exportStar(require("./parser/parseEvmType"), exports);

__exportStar(require("./utils/signatures"), exports);
__exportStar(require("./typechain/types"), exports);
__exportStar(require("./typechain/runTypeChain"), exports);
__exportStar(require("./utils/glob"), exports);
__exportStar(require("./typechain/types"), exports);
var normalizeName_1 = require("./parser/normalizeName");
Object.defineProperty(exports, "normalizeName", { enumerable: true, get: function () { return normalizeName_1.normalizeName; } });
//# sourceMappingURL=index.js.map
export declare function getFilename(path: string): string;
export declare function getFileExtension(path: string): string;
export declare function ensureAbsPath(path: string): string;
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.getFileExtension = exports.getFilename = void 0;
exports.ensureAbsPath = exports.getFileExtension = exports.getFilename = void 0;
const path_1 = require("path");

@@ -13,2 +13,9 @@ function getFilename(path) {

exports.getFileExtension = getFileExtension;
function ensureAbsPath(path) {
if (path_1.isAbsolute(path)) {
return path;
}
return path_1.join(process.cwd(), path);
}
exports.ensureAbsPath = ensureAbsPath;
//# sourceMappingURL=files.js.map

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

],
"version": "4.0.3",
"version": "5.0.0",
"license": "MIT",

@@ -35,9 +35,11 @@ "repository": "https://github.com/ethereum-ts/Typechain",

"dependencies": {
"@types/prettier": "^2.1.1",
"command-line-args": "^4.0.7",
"debug": "^4.1.1",
"fs-extra": "^7.0.0",
"glob": "^7.1.6",
"js-sha3": "^0.8.0",
"lodash": "^4.17.15",
"ts-essentials": "^7.0.1",
"ts-generator": "^0.1.1"
"prettier": "^2.1.2",
"ts-essentials": "^7.0.1"
},

@@ -52,2 +54,3 @@ "devDependencies": {

"@types/lodash": "^4.14.139",
"@types/mkdirp": "^1.0.1",
"@types/node": "^8.0.25",

@@ -54,0 +57,0 @@ "@types/prettier": "^1.13.2",

<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>
<p align="center">🔌 TypeScript bindings for Ethereum smartcontracts</p>
<p align="center">🔌 TypeScript bindings for Ethereum smart contracts</p>

@@ -9,3 +9,2 @@ <p align="center">

<img alt="Downloads" src="https://img.shields.io/npm/dm/typechain.svg">
<a href="https://github.com/prettier/prettier"><img alt="Prettier" src="https://img.shields.io/badge/code_style-prettier-ff69b4.svg"></a>
<a href="/package.json"><img alt="Software License" src="https://img.shields.io/badge/license-MIT-brightgreen.svg?style=flat-square"></a>

@@ -15,9 +14,10 @@ </p>

<p align="center">
<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>
<i>Used by the best:</i> <br/>
<img src="https://raw.githubusercontent.com/ethereum-ts/TypeChain/master/docs/images/maker-logo.png" height="110" alt="Maker DAO" />
<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>
<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>
<br/>
<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>
<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>
</p>
<p align="center">
Contributed with: <br/>
<img src="https://github.com/Neufund/TypeChain/blob/6d358df7b2da6b62d56f9935f1666b17b93176f0/docs/images/neufund-logo.png?raw=true" width="100" alt="Neufund">
</p>
</p>

@@ -29,5 +29,5 @@

- IDE support - works with any IDE supporting Typescript
- extendible - work with many different APIs: `ethers.js v4`, `truffle v4`, `truffle v5`, `Web3.js v1` or you can create
your own target
- frictionless - works with simple, JSON ABI files as well as with Truffle style ABIs
- extendible - work with many different tools: `ethers.js`, `hardhat`, `truffle`, `Web3.js` or you can create your own
target
- frictionless - works with simple, JSON ABI files as well as with Truffle/Hardhat artifacts

@@ -44,11 +44,11 @@ ## Installation

| Package | Version | Description | Examples |
| ------------------------------------------------------ | --------------------------------------------------------------------------------------------------------------------- | -------------------------------------------- | -------------------------------- |
| [`typechain`](/packages/typechain) | [![npm](https://img.shields.io/npm/v/typechain.svg)](https://www.npmjs.com/package/typechain) | Core package | - |
| [`@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/truffle-v4`](/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 | [example](./examples/truffle-v4) |
| [`@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](./examples/hardhat) |
| Package | Version | Description | Examples |
| ------------------------------------------------------ | --------------------------------------------------------------------------------------------------------------------- | -------------------------------------------- | ---------------------------------------------------------------------------------- |
| [`typechain`](/packages/typechain) | [![npm](https://img.shields.io/npm/v/typechain.svg)](https://www.npmjs.com/package/typechain) | Core package | - |
| [`@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/truffle-v4`](/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 | [example](./examples/truffle-v4) |
| [`@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) |

@@ -59,2 +59,5 @@ ## Usage

_Note: If you use hardhat just use
[hardhat plugin](https://github.com/ethereum-ts/TypeChain/tree/master/packages/hardhat)._
```

@@ -68,3 +71,5 @@ typechain --target=(ethers-v4|truffle-v4|truffle-v5|web3-v1|path-to-custom-target) [glob]

package named: `@typechain/${target}`, so make sure that desired package is installed.
- `--outDir` (optional) - put all generated files to a specific dir.
- `--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

@@ -76,11 +81,9 @@ TypeChain always will rewrite existing files. You should not commit them. Read more in FAQ section.

```
typechain --target ethers-v4 --outDir app/contracts './node_modules/neufund-contracts/build/contracts/*.json'
typechain --target ethers-v4 --out-dir app/contracts './node_modules/neufund-contracts/build/contracts/*.json'
```
## Demo 🏎️
## Videos
![Demo](https://media.giphy.com/media/3oFzmqgHxrPZFhBst2/giphy.gif)
- [Devcon5 Video (2019)](https://www.youtube.com/watch?v=Ho4dGNKVkTE)
[Example usage](https://github.com/Neufund/commit.neufund.org/pull/331/files)
## Getting started 📚

@@ -90,14 +93,14 @@

Interacting with blockchain in Javascript is a pain. Web3 interface is sluggish and when using it with Typescript it
gets even worse. Often, you can't be sure what given method call will actually do without looking at ABI file. TypeChain
is here to solve these problems (as long as you use Typescript).
Interacting with blockchain in Javascript is a pain. Developers need to remember not only a name of a given smart
contract method or event but also it's full signature. This wastes time and might introduce bugs that will be triggered
only in runtime. TypeChain solves these problems (as long as you use TypeScript).
### How does it work?
TypeChain is code generator - provide ABI file and you will get Typescript class with flexible interface for interacting
with blockchain. Depending on the target parameter it can generate typings for truffle, web3 1.0.0 or ethers.
TypeChain is a code generator - provide ABI file and name of your blockchain access library (ethers/truffle/web3.js) and
you will get TypeScript typings compatible with a given library.
### Step by step guide
Install typechain with `yarn add --dev typechain` and install desired target.
Install TypeChain with `yarn add --dev typechain` and install desired target.

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

Use `ethers-v4` target to generate wrappers for [ethers.js](https://github.com/ethers-io/ethers.js/) lib.
Use `ethers-v4` target to generate wrappers for [ethers.js](https://github.com/ethers-io/ethers.js/) lib. To make it
work great with Hardhat, use [Hardhat plugin](https://github.com/ethereum-ts/TypeChain/tree/master/packages/hardhat).

@@ -167,26 +171,21 @@ ### Truffle v4 / v5

Furthermore, we will silent tslint for generated files with `/* tslint:disable */` comments.
Furthermore, TypeChain will silent `eslint` and `tslint` errors for generated files.
### Usage as API
You may want to use `ts-generator` api to kick off whole process by api:
```typescript
import { tsGenerator } from 'ts-generator'
import { TypeChain } from 'typechain/dist/TypeChain'
import { runTypeChain, glob } from 'typechain'
async function main() {
const cwd = process.cwd()
// find all files matching the glob
const allFiles = glob(cwd, [`${config.paths.artifacts}/!(build-info)/**/+([a-zA-Z0-9_]).json`])
await tsGenerator(
{ cwd },
new TypeChain({
cwd,
rawConfig: {
files: 'your-glob-here',
outDir: 'optional out dir path',
target: 'your-target',
},
}),
)
const result = await runTypeChain({
cwd,
filesToProcess: allFiles,
allFiles,
outDir: 'out directory',
target: 'target name',
})
}

@@ -197,2 +196,6 @@

If you don't care about incremental generation just specify the same set of files for `filesToProcess` and `allFiles`.
For incremental generation example read the source code of
[hardhat plugin](https://github.com/ethereum-ts/TypeChain/blob/master/packages/hardhat/src/index.ts).
# Contributing

@@ -204,2 +207,2 @@

Krzysztof Kaczor (krzkaczor) MIT | [Github](https://github.com/krzkaczor) | [Twitter](https://twitter.com/krzkaczor)
Kris Kaczor (krzkaczor) MIT | [Github](https://github.com/krzkaczor) | [Twitter](https://twitter.com/krzkaczor)

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