Skip to content

Commit fba0abb

Browse files
react-solidity updates
1. Fixing contracts export script that might've failed if one of the pinned-contracts / deployed-contracts directory was missing 2. Updated terminal instructions for the template
1 parent 3c240b8 commit fba0abb

File tree

2 files changed

+36
-25
lines changed

2 files changed

+36
-25
lines changed

src/templateConfigs/react-solidity.ts

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,15 +16,20 @@ const config: TemplateConfig = {
1616
/^pnpm-lock\.yaml/,
1717
],
1818
instructions: `
19-
${c.primary("Step 1: ")}${c.secondary("start remixd environment")}
20-
${c.code("pnpm remixd")}
19+
${c.primary("For Remix environment:")}
20+
${c.primary("1. ")}${c.secondary("start remixd environment: ")}${c.code("pnpm remixd")}
21+
${c.primary("2. ")}${c.secondary("edit, deploying and pin smart contracts in Remix")}
22+
${c.primary("3. ")}${c.secondary("export the contracts: ")}${c.code("pnpm contracts:export")}
2123
22-
${c.primary("Step 2: ")}\
23-
${c.secondary("after deploying and pinning smart contracts in remix, build the contracts")}
24-
${c.code("pnpm contracts:build")}
24+
${c.primary("For local environment:")}
25+
${c.primary("1. ")}${c.secondary("edit and build smart contracts: ")}${c.code("pnpm contracts:build")}
26+
${c.primary("2. ")}${c.secondary("deploy smart contracts to chain: ")}${c.code("pnpm contracts:deploy")}
27+
${c.primary("3. ")}${c.secondary("export the contracts: ")}${c.code("pnpm contracts:export")}
2528
26-
${c.primary("Step 3: ")}${c.secondary("start frontend app")}
27-
${c.code("pnpm frontend:dev")}`,
29+
${c.primary("Use the contract in the frontend app:")}
30+
${c.primary("1. ")}${c.secondary("use exported smart contract address in ")}${c.code("frontend/src/App.tsx")}
31+
${c.primary("2. ")}${c.secondary("start frontend app: ")}${c.code("pnpm frontend:dev")}
32+
`,
2833
};
2934

3035
export default config;

templates/react-solidity/contracts/src/exportContracts.ts

Lines changed: 24 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -8,35 +8,41 @@ let res = "export const contracts = {";
88
let dirEntries: fs.Dirent[] = [];
99

1010
try {
11-
dirEntries.push(...fs.readdirSync(
12-
path.join(".deploys", "pinned-contracts"),
13-
{ recursive: true, withFileTypes: true }
14-
));
15-
dirEntries.push(...fs.readdirSync(
16-
path.join(".deploys", "deployed-contracts"),
17-
{ recursive: true, withFileTypes: true }
18-
));
11+
dirEntries.push(
12+
...fs.readdirSync(path.join(".deploys", "pinned-contracts"), { recursive: true, withFileTypes: true }),
13+
);
14+
dirEntries.push(
15+
...fs.readdirSync(path.join(".deploys", "deployed-contracts"), { recursive: true, withFileTypes: true }),
16+
);
1917
} catch (e: unknown) {
20-
if (e instanceof Error && "code" in e && e.code === "ENOENT") {
21-
console.warn("No contracts found; remember to pin deployed contracts in Remix in order to use them from frontend");
22-
process.exit();
18+
// One of those dirs can not exist, and it's fine
19+
if (!(e instanceof Error && "code" in e && e.code === "ENOENT")) {
20+
throw e;
2321
}
2422
}
2523

24+
dirEntries = dirEntries.filter(
25+
(entry) => entry.isFile() && entry.name.startsWith("0x") && entry.name.endsWith(".json"),
26+
);
27+
28+
if (dirEntries.length === 0) {
29+
console.warn(
30+
"No contracts found; remember to pin deployed contracts in Remix or build them locally, in order to use them from frontend",
31+
);
32+
process.exit();
33+
}
34+
2635
for (const entry of dirEntries) {
27-
if (entry.isFile() && entry.name.startsWith("0x") && entry.name.endsWith(".json")) {
28-
const strippedAddress = entry.name.slice(2, entry.name.length - 5);
36+
const strippedAddress = entry.name.slice(2, entry.name.length - 5);
2937

30-
console.log(`Processing contract ${strippedAddress}`);
38+
console.log(`Processing contract ${strippedAddress}`);
3139

32-
const value = fs.readFileSync(path.join(entry.parentPath, entry.name), "utf-8");
33-
res += `\n "${strippedAddress}": ${value},\n`;
34-
}
40+
const value = fs.readFileSync(path.join(entry.parentPath, entry.name), "utf-8");
41+
res += `\n "${strippedAddress}": ${value},\n`;
3542
}
3643

3744
res += "};";
3845
const outPath = path.join("dist", "contracts.js");
3946
fs.writeFileSync(outPath, res);
4047

4148
console.log(`Exported contracts to ${outPath}`);
42-

0 commit comments

Comments
 (0)