Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 7ca8ecc

Browse files
committedOct 13, 2022
added compiler wrapper
1 parent 0effc33 commit 7ca8ecc

File tree

6 files changed

+131
-40
lines changed

6 files changed

+131
-40
lines changed
 

‎package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@
1111
"dependencies": {
1212
"next": "12.3.1",
1313
"react": "18.2.0",
14-
"react-dom": "18.2.0"
14+
"react-dom": "18.2.0",
15+
"solc": "^0.8.17"
1516
},
1617
"devDependencies": {
1718
"@types/node": "18.8.5",

‎pages/index.tsx

Lines changed: 7 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ const Home: NextPage = () => {
1414

1515
<main className={styles.main}>
1616
<h1 className={styles.title}>
17-
Welcome to <a href="https://nextjs.org">Next.js!</a>
17+
Frontend Solidity Compiler
1818
</h1>
1919

2020
<p className={styles.description}>
@@ -23,48 +23,16 @@ const Home: NextPage = () => {
2323
</p>
2424

2525
<div className={styles.grid}>
26-
<a href="https://nextjs.org/docs" className={styles.card}>
26+
<div className={styles.card}>
2727
<h2>Documentation &rarr;</h2>
2828
<p>Find in-depth information about Next.js features and API.</p>
29-
</a>
30-
31-
<a href="https://nextjs.org/learn" className={styles.card}>
32-
<h2>Learn &rarr;</h2>
33-
<p>Learn about Next.js in an interactive course with quizzes!</p>
34-
</a>
35-
36-
<a
37-
href="https://github.com/vercel/next.js/tree/canary/examples"
38-
className={styles.card}
39-
>
40-
<h2>Examples &rarr;</h2>
41-
<p>Discover and deploy boilerplate example Next.js projects.</p>
42-
</a>
43-
44-
<a
45-
href="https://vercel.com/new?utm_source=create-next-app&utm_medium=default-template&utm_campaign=create-next-app"
46-
className={styles.card}
47-
>
48-
<h2>Deploy &rarr;</h2>
49-
<p>
50-
Instantly deploy your Next.js site to a public URL with Vercel.
51-
</p>
52-
</a>
29+
</div>
30+
<div className={styles.card}>
31+
<h2>Documentation &rarr;</h2>
32+
<p>Find in-depth information about Next.js features and API.</p>
33+
</div>
5334
</div>
5435
</main>
55-
56-
<footer className={styles.footer}>
57-
<a
58-
href="https://vercel.com?utm_source=create-next-app&utm_medium=default-template&utm_campaign=create-next-app"
59-
target="_blank"
60-
rel="noopener noreferrer"
61-
>
62-
Powered by{' '}
63-
<span className={styles.logo}>
64-
<Image src="/vercel.svg" alt="Vercel Logo" width={72} height={16} />
65-
</span>
66-
</a>
67-
</footer>
6836
</div>
6937
)
7038
}

‎src/sol/compiler.ts

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
interface AbiIO {
2+
indexed?: boolean;
3+
internalType: string;
4+
name: string;
5+
type: string;
6+
}
7+
8+
interface Abi {
9+
input: AbiIO[];
10+
output: AbiIO[];
11+
name: string;
12+
stateMutability: string;
13+
type: string;
14+
anonymous?: boolean;
15+
}
16+
17+
interface ContractData {
18+
contractName: string;
19+
byteCode: string;
20+
abi: Abi[];
21+
}
22+
23+
export const compile = (contractCode: string): Promise<ContractData[]> => {
24+
return new Promise((resolve, reject) => {
25+
const worker = new Worker(
26+
new URL("./solc.worker.ts", import.meta.url), { type: "module" }
27+
);
28+
worker.onmessage = function (e: any) {
29+
const output = e.data.output;
30+
const result = [];
31+
for (const contractName in output.contracts['contract']) {
32+
const contract = output.contracts['contract'][contractName];
33+
result.push({
34+
contractName: contractName,
35+
byteCode: contract.evm.bytecode.object,
36+
abi: contract.abi
37+
} as ContractData);
38+
}
39+
resolve(result);
40+
};
41+
worker.onerror = reject;
42+
worker.postMessage({
43+
contractCode: contractCode,
44+
});
45+
});
46+
};

‎src/sol/dec.d.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
declare module "solc/wrapper";
2+
declare function importScripts(...urls: string[]): void;

‎src/sol/solc.worker.ts

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
importScripts('https://binaries.soliditylang.org/bin/soljson-latest.js');
2+
import wrapper from 'solc/wrapper';
3+
4+
self.onmessage = (event) => {
5+
const contractCode = event.data.contractCode;
6+
const sourceCode = {
7+
language: 'Solidity',
8+
sources: {
9+
contract: { content: contractCode }
10+
},
11+
settings: {
12+
outputSelection: { '*': { '*': ['*'] } }
13+
}
14+
};
15+
const compiler = wrapper((self as any).Module);
16+
self.postMessage({
17+
output: JSON.parse(compiler.compile(JSON.stringify(sourceCode)))
18+
});
19+
};

‎yarn.lock

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -395,6 +395,16 @@ color-name@~1.1.4:
395395
resolved "https://registry.yarnpkg.com/color-name/-/color-name-1.1.4.tgz#c2a09a87acbde69543de6f63fa3995c826c536a2"
396396
integrity sha512-dOy+3AuW3a2wNbZHIuMZpTcgjGuLU/uBL/ubcZF9OXbDo8ff4O8yVp5Bf0efS8uEoYo5q4Fx7dY9OgQGXgAsQA==
397397

398+
command-exists@^1.2.8:
399+
version "1.2.9"
400+
resolved "https://registry.yarnpkg.com/command-exists/-/command-exists-1.2.9.tgz#c50725af3808c8ab0260fd60b01fbfa25b954f69"
401+
integrity sha512-LTQ/SGc+s0Xc0Fu5WaKnR0YiygZkm9eKFvyS+fRsU7/ZWFF8ykFM6Pc9aCVf1+xasOOZpO3BAVgVrKvsqKHV7w==
402+
403+
commander@^8.1.0:
404+
version "8.3.0"
405+
resolved "https://registry.yarnpkg.com/commander/-/commander-8.3.0.tgz#4837ea1b2da67b9c616a67afbb0fafee567bca66"
406+
integrity sha512-OkTL9umf+He2DZkUq8f8J9of7yL6RJKI24dVITBmNfZBmri9zYZQrKkuXiKhyfPSu8tUhnVBB1iKXevvnlR4Ww==
407+
398408
concat-map@0.0.1:
399409
version "0.0.1"
400410
resolved "https://registry.yarnpkg.com/concat-map/-/concat-map-0.0.1.tgz#d8a96bd77fd68df7793a73036a3ba0d5405d477b"
@@ -809,6 +819,11 @@ flatted@^3.1.0:
809819
resolved "https://registry.yarnpkg.com/flatted/-/flatted-3.2.7.tgz#609f39207cb614b89d0765b477cb2d437fbf9787"
810820
integrity sha512-5nqDSxl8nn5BSNxyR3n4I6eDmbolI6WT+QqR547RwxQapgjQBmtktdP+HTBb/a/zLsbzERTONyUB5pefh5TtjQ==
811821

822+
follow-redirects@^1.12.1:
823+
version "1.15.2"
824+
resolved "https://registry.yarnpkg.com/follow-redirects/-/follow-redirects-1.15.2.tgz#b460864144ba63f2681096f274c4e57026da2c13"
825+
integrity sha512-VQLG33o04KaQ8uYi2tVNbdrWp1QWxNNea+nmIB4EVM28v0hmP17z7aG1+wAkNzVq4KeXTq3221ye5qTJP91JwA==
826+
812827
fs.realpath@^1.0.0:
813828
version "1.0.0"
814829
resolved "https://registry.yarnpkg.com/fs.realpath/-/fs.realpath-1.0.0.tgz#1504ad2523158caa40db4a2787cb01411994ea4f"
@@ -1098,6 +1113,11 @@ js-sdsl@^4.1.4:
10981113
resolved "https://registry.yarnpkg.com/js-sdsl/-/js-sdsl-4.1.5.tgz#1ff1645e6b4d1b028cd3f862db88c9d887f26e2a"
10991114
integrity sha512-08bOAKweV2NUC1wqTtf3qZlnpOX/R2DU9ikpjOHs0H+ibQv3zpncVQg6um4uYtRtrwIX8M4Nh3ytK4HGlYAq7Q==
11001115

1116+
js-sha3@0.8.0:
1117+
version "0.8.0"
1118+
resolved "https://registry.yarnpkg.com/js-sha3/-/js-sha3-0.8.0.tgz#b9b7a5da73afad7dedd0f8c463954cbde6818840"
1119+
integrity sha512-gF1cRrHhIzNfToc802P800N8PpXS+evLLXfsVpowqmAFR9uwbi89WvXg2QspOmXL8QL86J4T1EpFu+yUkwJY3Q==
1120+
11011121
"js-tokens@^3.0.0 || ^4.0.0":
11021122
version "4.0.0"
11031123
resolved "https://registry.yarnpkg.com/js-tokens/-/js-tokens-4.0.0.tgz#19203fb59991df98e3a287050d4647cdeaf32499"
@@ -1181,6 +1201,11 @@ lru-cache@^6.0.0:
11811201
dependencies:
11821202
yallist "^4.0.0"
11831203

1204+
memorystream@^0.3.1:
1205+
version "0.3.1"
1206+
resolved "https://registry.yarnpkg.com/memorystream/-/memorystream-0.3.1.tgz#86d7090b30ce455d63fbae12dda51a47ddcaf9b2"
1207+
integrity sha512-S3UwM3yj5mtUSEfP41UZmt/0SCoVYUcU1rkXv+BQ5Ig8ndL4sPoJNBUJERafdPb5jjHJGuMgytgKvKIf58XNBw==
1208+
11841209
merge2@^1.3.0, merge2@^1.4.1:
11851210
version "1.4.1"
11861211
resolved "https://registry.yarnpkg.com/merge2/-/merge2-1.4.1.tgz#4368892f885e907455a6fd7dc55c0c9d404990ae"
@@ -1336,6 +1361,11 @@ optionator@^0.9.1:
13361361
type-check "^0.4.0"
13371362
word-wrap "^1.2.3"
13381363

1364+
os-tmpdir@~1.0.2:
1365+
version "1.0.2"
1366+
resolved "https://registry.yarnpkg.com/os-tmpdir/-/os-tmpdir-1.0.2.tgz#bbe67406c79aa85c5cfec766fe5734555dfa1274"
1367+
integrity sha512-D2FR03Vir7FIu45XBY20mTb+/ZSWB00sjU9jdQXt83gDrI4Ztz5Fs7/yy74g2N5SVQY4xY1qDr4rNddwYRVX0g==
1368+
13391369
p-limit@^3.0.2:
13401370
version "3.1.0"
13411371
resolved "https://registry.yarnpkg.com/p-limit/-/p-limit-3.1.0.tgz#e1daccbe78d0d1388ca18c64fea38e3e57e3706b"
@@ -1522,6 +1552,11 @@ scheduler@^0.23.0:
15221552
dependencies:
15231553
loose-envify "^1.1.0"
15241554

1555+
semver@^5.5.0:
1556+
version "5.7.1"
1557+
resolved "https://registry.yarnpkg.com/semver/-/semver-5.7.1.tgz#a954f931aeba508d307bbf069eff0c01c96116f7"
1558+
integrity sha512-sauaDf/PZdVgrLTNYHRtpXa1iRiKcaebiKQ1BJdpQlWH2lCvexQdX55snPFyK7QzpudqbCI0qXFfOasHdyNDGQ==
1559+
15251560
semver@^6.3.0:
15261561
version "6.3.0"
15271562
resolved "https://registry.yarnpkg.com/semver/-/semver-6.3.0.tgz#ee0a64c8af5e8ceea67687b133761e1becbd1d3d"
@@ -1560,6 +1595,19 @@ slash@^3.0.0:
15601595
resolved "https://registry.yarnpkg.com/slash/-/slash-3.0.0.tgz#6539be870c165adbd5240220dbe361f1bc4d4634"
15611596
integrity sha512-g9Q1haeby36OSStwb4ntCGGGaKsaVSjQ68fBxoQcutl5fS1vuY18H3wSt3jFyFtrkx+Kz0V1G85A4MyAdDMi2Q==
15621597

1598+
solc@^0.8.17:
1599+
version "0.8.17"
1600+
resolved "https://registry.yarnpkg.com/solc/-/solc-0.8.17.tgz#c748fec6a64bf029ec406aa9b37e75938d1115ae"
1601+
integrity sha512-Dtidk2XtTTmkB3IKdyeg6wLYopJnBVxdoykN8oP8VY3PQjN16BScYoUJTXFm2OP7P0hXNAqWiJNmmfuELtLf8g==
1602+
dependencies:
1603+
command-exists "^1.2.8"
1604+
commander "^8.1.0"
1605+
follow-redirects "^1.12.1"
1606+
js-sha3 "0.8.0"
1607+
memorystream "^0.3.1"
1608+
semver "^5.5.0"
1609+
tmp "0.0.33"
1610+
15631611
source-map-js@^1.0.2:
15641612
version "1.0.2"
15651613
resolved "https://registry.yarnpkg.com/source-map-js/-/source-map-js-1.0.2.tgz#adbc361d9c62df380125e7f161f71c826f1e490c"
@@ -1636,6 +1684,13 @@ text-table@^0.2.0:
16361684
resolved "https://registry.yarnpkg.com/text-table/-/text-table-0.2.0.tgz#7f5ee823ae805207c00af2df4a84ec3fcfa570b4"
16371685
integrity sha512-N+8UisAXDGk8PFXP4HAzVR9nbfmVJ3zYLAWiTIoqC5v5isinhr+r5uaO8+7r3BMfuNIufIsA7RdpVgacC2cSpw==
16381686

1687+
tmp@0.0.33:
1688+
version "0.0.33"
1689+
resolved "https://registry.yarnpkg.com/tmp/-/tmp-0.0.33.tgz#6d34335889768d21b2bcda0aa277ced3b1bfadf9"
1690+
integrity sha512-jRCJlojKnZ3addtTOjdIqoRuPEKBvNXcGYqzO6zWZX8KfKEpnGY5jfggJQ3EjKuu8D4bJRr0y+cYJFmYbImXGw==
1691+
dependencies:
1692+
os-tmpdir "~1.0.2"
1693+
16391694
to-regex-range@^5.0.1:
16401695
version "5.0.1"
16411696
resolved "https://registry.yarnpkg.com/to-regex-range/-/to-regex-range-5.0.1.tgz#1648c44aae7c8d988a326018ed72f5b4dd0392e4"

0 commit comments

Comments
 (0)
Please sign in to comment.