Skip to content

Commit 74e3504

Browse files
author
Micah Zoltu
committed
Adds Typescript definitions.
This isn't complete, but it is _way_ better than nothing and gives a place for people to add additional typescript definitions in the future. Recommend switching over to TypeScript for this library so this file is generated automatically. :)
1 parent 9aeaca2 commit 74e3504

File tree

2 files changed

+149
-0
lines changed

2 files changed

+149
-0
lines changed

index.d.ts

Lines changed: 148 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,148 @@
1+
declare module 'solc' {
2+
export type Primitive =
3+
'bool' |
4+
'string' |
5+
'address' |
6+
'uint8' |
7+
'uint64' |
8+
'uint128' |
9+
'uint256' |
10+
'int8' |
11+
'int64' |
12+
'int128' |
13+
'int256' |
14+
'bytes' |
15+
'bytes20' |
16+
'bytes32' |
17+
'bool[]' |
18+
'string[]' |
19+
'address[]' |
20+
'uint8[]' |
21+
'uint64[]' |
22+
'uint128[]' |
23+
'uint256[]' |
24+
'int8[]' |
25+
'int64[]' |
26+
'int128[]' |
27+
'int256[]' |
28+
'bytes[]' |
29+
'bytes20[]' |
30+
'bytes32[]';
31+
32+
export interface AbiParameter {
33+
name: string,
34+
type: Primitive,
35+
}
36+
37+
export interface AbiEventParameter extends AbiParameter {
38+
indexed: boolean,
39+
}
40+
41+
export interface AbiFunction {
42+
name: string,
43+
type: 'function' | 'constructor' | 'fallback',
44+
stateMutability: 'pure' | 'view' | 'payable' | 'nonpayable',
45+
constant: boolean,
46+
payable: boolean,
47+
inputs: Array<AbiParameter>,
48+
outputs: Array<AbiParameter>,
49+
}
50+
51+
export interface AbiEvent {
52+
name: string,
53+
type: 'event',
54+
inputs: Array<AbiEventParameter>,
55+
anonymous: boolean,
56+
}
57+
58+
export type Abi = Array<AbiFunction | AbiEvent>;
59+
60+
interface CompilerInputSourceFile {
61+
keccak256?: string;
62+
urls: string[];
63+
}
64+
interface CompilerInputSourceCode {
65+
keccak256?: string;
66+
content: string;
67+
}
68+
interface CompilerInput {
69+
language: "Solidity" | "serpent" | "lll" | "assembly";
70+
settings?: any,
71+
sources: {
72+
[globalName: string]: CompilerInputSourceFile|CompilerInputSourceCode,
73+
};
74+
}
75+
interface CompilerOutputError {
76+
sourceLocation?: {
77+
file: string;
78+
start: number;
79+
end: number;
80+
};
81+
type: "TypeError" | "InternalCompilerError" | "Exception";
82+
component: "general" | "ewasm";
83+
severity: "error" | "warning";
84+
message: string;
85+
formattedMessage?: string;
86+
}
87+
interface CompilerOutputEvmBytecode {
88+
object: string;
89+
opcodes?: string;
90+
sourceMap?: string;
91+
linkReferences?: {} | {
92+
[globalName: string]: {
93+
[name: string]: {start: number, length: number}[];
94+
};
95+
};
96+
}
97+
interface CompilerOutputSources {
98+
[globalName: string]: {
99+
id: number;
100+
ast: any;
101+
legacyAST: any;
102+
},
103+
}
104+
interface CompilerOutputContracts {
105+
[globalName: string]: {
106+
[contractName: string]: {
107+
abi: Abi;
108+
metadata?: string;
109+
userdoc?: any;
110+
devdoc?: any;
111+
ir?: string;
112+
evm: {
113+
assembly?: string;
114+
legacyAssembly?: any;
115+
bytecode: CompilerOutputEvmBytecode;
116+
deployedBytecode?: CompilerOutputEvmBytecode;
117+
methodIdentifiers?: {
118+
[methodName: string]: string;
119+
};
120+
gasEstimates?: {
121+
creation: {
122+
codeDepositCost: string;
123+
executionCost: string;
124+
totalCost: string;
125+
};
126+
external: {
127+
[functionSignature: string]: string;
128+
};
129+
internal: {
130+
[functionSignature: string]: string;
131+
};
132+
};
133+
};
134+
ewasm?: {
135+
wast: string;
136+
wasm: string;
137+
}
138+
}
139+
};
140+
}
141+
interface CompilerOutput {
142+
errors?: CompilerOutputError[];
143+
sources?: CompilerOutputSources;
144+
contracts: CompilerOutputContracts;
145+
}
146+
type ReadCallback = (path: string) => { contents?: string, error?: string};
147+
function compileStandardWrapper(input: string, readCallback?: ReadCallback): string;
148+
}

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
"version": "0.4.20",
44
"description": "Solidity compiler",
55
"main": "index.js",
6+
"types": "index.d.ts",
67
"bin": {
78
"solcjs": "solcjs"
89
},

0 commit comments

Comments
 (0)