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

typechain

Package Overview
Dependencies
Maintainers
1
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 0.0.2 to 0.0.3

dist/debug.d.ts

5

dist/abiParser.d.ts
export declare enum AbiType {
BOOL = "bool",
UINT8 = "uint8",
UINT256 = "uint256",
BYTES = "bytes",
VOID = "void",
ADDRESS = "address",
STRING = "string",
}

@@ -23,2 +27,3 @@ export interface AbiParameter {

outputs: Array<AbiType>;
payable: boolean;
}

@@ -25,0 +30,0 @@ export interface Contract {

35

dist/abiParser.js
"use strict";
exports.__esModule = true;
var debug_1 = require("./debug");
var AbiType;
(function (AbiType) {
AbiType["BOOL"] = "bool";
AbiType["UINT8"] = "uint8";
AbiType["UINT256"] = "uint256";
AbiType["BYTES"] = "bytes";
AbiType["VOID"] = "void";
AbiType["ADDRESS"] = "address";
AbiType["STRING"] = "string";
})(AbiType = exports.AbiType || (exports.AbiType = {}));

@@ -14,2 +19,3 @@ function parse(abi) {

abi.forEach(function (abiPiece) {
// @todo implement missing abi pieces
// skip constructors for now

@@ -19,11 +25,22 @@ if (abiPiece.type === "constructor") {

}
if (abiPiece.constant && abiPiece.inputs.length === 0 && abiPiece.outputs.length === 1) {
constants.push(parseConstant(abiPiece));
// skip events
if (abiPiece.type === "event") {
return;
}
else if (abiPiece.constant) {
constantFunctions.push(parseConstantFunction(abiPiece));
if (abiPiece.type === "fallback") {
return;
}
else {
functions.push(parseFunctionDeclaration(abiPiece));
if (abiPiece.type === "function") {
if (abiPiece.constant && abiPiece.inputs.length === 0 && abiPiece.outputs.length === 1) {
constants.push(parseConstant(abiPiece));
}
else if (abiPiece.constant) {
constantFunctions.push(parseConstantFunction(abiPiece));
}
else {
functions.push(parseFunctionDeclaration(abiPiece));
}
return;
}
throw new Error("Unrecognized abi element: " + abiPiece.type);
});

@@ -46,2 +63,3 @@ return {

function parseConstant(abiPiece) {
debug_1["default"]("Parsing constant \"" + abiPiece.name + "\"");
return {

@@ -53,2 +71,3 @@ name: abiPiece.name,

function parseConstantFunction(abiPiece) {
debug_1["default"]("Parsing constant function \"" + abiPiece.name + "\"");
return {

@@ -61,7 +80,9 @@ name: abiPiece.name,

function parseFunctionDeclaration(abiPiece) {
debug_1["default"]("Parsing function declaration \"" + abiPiece.name + "\"");
return {
name: abiPiece.name,
inputs: abiPiece.inputs,
outputs: parseOutputs(abiPiece.outputs)
outputs: parseOutputs(abiPiece.outputs),
payable: abiPiece.payable
};
}

32

dist/generateSource.js

@@ -13,5 +13,5 @@ "use strict";

function codeGenForContract(abi, input) {
return "/* CODE GENERATED BY TYPECHAIN ver " + utils_1.getVersion() + " */\n \nimport { BigNumber } from \"bignumber.js\";\n\ninterface ITxParams {\n from?: string; \n gas?: number | string | BigNumber;\n gasPrice?: number | string | BigNumber;\n}\n\nfunction promisify(func: any, args: any): Promise<any> {\n return new Promise((res,rej) => {\n func(...args, (err: any, data: any) => {\n if (err) return rej(err);\n return res(data);\n })\n })\n}\n\nclass Contract {\n public readonly rawWeb3Contract: any;\n \n public constructor(web3: any, address: string) {\n this.rawWeb3Contract = web3.eth.contract(" + JSON.stringify(abi) + ").at(address);\n }\n static async createAndValidate(web3: any, address: string): Promise<Contract> {\n const contract = new Contract(web3, address);\n const code = await promisify(web3.eth.getCode, [address]);\n if (code === \"0x0\") {\n throw new Error(`Contract at ${address} doesn't exist!`);\n }\n return contract; \n }\n \n " + input.constants
return "/* GENERATED BY TYPECHAIN VER. " + utils_1.getVersion() + " */\n \nimport { BigNumber } from \"bignumber.js\";\n\ninterface ITxParams {\n from?: string; \n gas?: number | string | BigNumber;\n gasPrice?: number | string | BigNumber;\n}\n\ninterface IPayableTxParams {\n value: string | BigNumber;\n from?: string; \n gas?: number | string | BigNumber;\n gasPrice?: number | string | BigNumber;\n}\n\nfunction promisify(func: any, args: any): Promise<any> {\n return new Promise((res,rej) => {\n func(...args, (err: any, data: any) => {\n if (err) return rej(err);\n return res(data);\n })\n })\n}\n\nclass Contract {\n public readonly rawWeb3Contract: any;\n \n public constructor(web3: any, address: string) {\n this.rawWeb3Contract = web3.eth.contract(" + JSON.stringify(abi) + ").at(address);\n }\n static async createAndValidate(web3: any, address: string): Promise<Contract> {\n const contract = new Contract(web3, address);\n const code = await promisify(web3.eth.getCode, [address]);\n if (code === \"0x0\") {\n throw new Error(`Contract at ${address} doesn't exist!`);\n }\n return contract; \n }\n \n " + input.constants
.map(function (constant) {
return "public get " + constant.name + "(): Promise<" + codeGenForTypes(constant.output) + "> { return promisify(this.rawWeb3Contract." + constant.name + ", []); }";
return "public get " + constant.name + "(): Promise<" + codeGenForTypes(constant.output, true) + "> { return promisify(this.rawWeb3Contract." + constant.name + ", []); }";
})

@@ -29,9 +29,7 @@ .join("\n") + " \n " + input.constantFunctions

return "public " + func.name + "Tx(" + (func.inputs.map(codeGenForParams).join(", ") +
(func.inputs.length === 0
? ""
: ", ")) + "params?: ITxParams): Promise<" + codeGenForOutputTypelist(func.outputs) + "> { return promisify(this.rawWeb3Contract." + func.name + ", [" + (func.inputs
(func.inputs.length === 0 ? "" : ", ")) + "params?: " + (func.payable
? "IPayableTxParams"
: "ITxParams") + "): Promise<" + codeGenForOutputTypelist(func.outputs) + "> { return promisify(this.rawWeb3Contract." + func.name + ", [" + (func.inputs
.map(codeGenForArgs)
.join(", ") + (func.inputs.length === 0
? ""
: ", ")) + "params ]); }";
.join(", ") + (func.inputs.length === 0 ? "" : ", ")) + "params ]); }";
})

@@ -41,3 +39,3 @@ .join(";\n") + " \n}\n\nexport default Contract;";

function codeGenForParams(param) {
return param.name + ": " + codeGenForTypes(param.type);
return param.name + ": " + codeGenForTypes(param.type, true);
}

@@ -49,12 +47,13 @@ function codeGenForArgs(param) {

if (output.length === 1) {
return codeGenForTypes(output[0]);
return codeGenForTypes(output[0], false);
}
else {
return "[" + output.map(codeGenForTypes).join(", ") + "]";
return "[" + output.map(function (x) { return codeGenForTypes(x, false); }).join(", ") + "]";
}
}
function codeGenForTypes(abiType) {
function codeGenForTypes(abiType, isInput) {
switch (abiType) {
case abiParser_1.AbiType.BOOL:
return "boolean";
case abiParser_1.AbiType.UINT8:
case abiParser_1.AbiType.UINT256:

@@ -64,5 +63,12 @@ return "BigNumber";

return "void";
// @todo we should try to match it with another contract
case abiParser_1.AbiType.ADDRESS:
return isInput ? "BigNumber | string" : "BigNumber";
case abiParser_1.AbiType.STRING:
return "string";
case abiParser_1.AbiType.BYTES:
return "string"; // @todo double check it. More strict typing would be useful here
default:
throw new Error("Unrecognized type!");
throw new Error("Unrecognized type " + abiType);
}
}
{
"name": "typechain",
"version": "0.0.2",
"version": "0.0.3",
"license": "MIT",
"devDependencies": {
"@types/chalk": "^0.4.31",
"@types/debug": "^0.0.30",
"@types/glob": "^5.0.32",

@@ -13,2 +14,3 @@ "@types/node": "^8.0.25",

"chalk": "^2.1.0",
"debug": "^3.0.1",
"glob": "^7.1.2"

@@ -15,0 +17,0 @@ },

@@ -66,2 +66,7 @@ # Typechain

- transaction support
- improve generated code (autoformatting, more checks)
- improve generated code (autoformatting, more checks, wiring contracts together)
#### Debugging 🐞
```sh
DEBUG=typechain typechain
```

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