Skip to content

Commit e751f55

Browse files
committedNov 6, 2024
WIP script to test end to end
1 parent ddeab4b commit e751f55

File tree

4 files changed

+193
-0
lines changed

4 files changed

+193
-0
lines changed
 

‎.gitignore

+2
Original file line numberDiff line numberDiff line change
@@ -12,3 +12,5 @@ docs/
1212

1313
# Dotenv file
1414
.env
15+
16+
node_modules

‎package-lock.json

+109
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎package.json

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"dependencies": {
3+
"ethers": "^6.13.4"
4+
}
5+
}

‎script.ts

+77
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
import { ethers } from "ethers";
2+
import * as fs from "fs";
3+
import * as path from "path";
4+
5+
// Load ABI and Bytecode from the neighboring Foundry project
6+
const interopPoWContractArtifactPath = path.resolve(
7+
__dirname,
8+
"./out/InteropPoW.sol/InteropPoW.json"
9+
);
10+
const workerContractArtifactPath = path.resolve(
11+
__dirname,
12+
"./out/InteropPoW.sol/Worker.json"
13+
);
14+
15+
// Read the artifact JSON file
16+
const interopPoWContractArtifact = JSON.parse(fs.readFileSync(interopPoWContractArtifactPath, "utf8"));
17+
const workerContractArtifact = JSON.parse(fs.readFileSync(workerContractArtifactPath, "utf8"));
18+
19+
// Replace with your own RPC URL and Private Key
20+
const RPC_URL = "https://mainnet.infura.io/v3/YOUR_INFURA_PROJECT_ID";
21+
22+
// TODO generate a private key, ensure it has ETH on both chains
23+
const PRIVATE_KEY = "YOUR_PRIVATE_KEY"; // use same one on both chains
24+
25+
26+
// Network Name: Interop Devnet 0
27+
// Chain ID: 11473209
28+
// Public RPC URL: https://interop-devnet-0.optimism.io/
29+
// Sequencer RPC URL: https://interop-devnet-0.optimism.io/
30+
31+
32+
// Network Name: Interop Devnet 1
33+
// Chain ID: 21473209
34+
// Public RPC URL: https://interop-devnet-1.optimism.io/
35+
// Sequencer RPC URL: https://interop-devnet-1.optimism.io/
36+
37+
async function main() {
38+
const provider0 = new ethers.JsonRpcProvider("https://interop-devnet-0.optimism.io")
39+
const provider1 = new ethers.JsonRpcProvider("https://interop-devnet-1.optimism.io")
40+
41+
// Connect to the Ethereum network
42+
const wallet0 = new ethers.Wallet(PRIVATE_KEY, provider0);
43+
const wallet1 = new ethers.Wallet(PRIVATE_KEY, provider1);
44+
45+
// deploy entrypoint contract to chain 0
46+
const interopPoWFactory = new ethers.ContractFactory(interopPoWContractArtifact.abi, interopPoWContractArtifact.bytecode, wallet0);
47+
console.log("Deploying contract to chain 0...");
48+
const interopPoW = await interopPoWFactory.deploy() as ethers.Contract & { run: () => Promise<void> };
49+
await interopPoW.waitForDeployment()
50+
console.log(`Contract deployed at: ${await interopPoW.getAddress()} `);
51+
52+
// deploy worker to chain 0
53+
const workerFactory0 = new ethers.ContractFactory(interopPoWContractArtifact.abi, interopPoWContractArtifact.bytecode, wallet0);
54+
console.log("Deploying contract to chain 0...");
55+
const worker0 = await workerFactory0.deploy();
56+
await worker0.waitForDeployment()
57+
console.log(`Contract deployed at: ${await worker0.getAddress()} `);
58+
59+
// deploy worker to chain 1
60+
const workerFactory1 = new ethers.ContractFactory(interopPoWContractArtifact.abi, interopPoWContractArtifact.bytecode, wallet1);
61+
console.log("Deploying contract to chain 0...");
62+
const worker1 = await workerFactory1.deploy();
63+
await worker1.waitForDeployment()
64+
console.log(`Contract deployed at: ${await worker1.getAddress()} `);
65+
66+
// call entrypoint
67+
interopPoW.connect(wallet0);
68+
await interopPoW.run()
69+
70+
// wait for event
71+
72+
73+
}
74+
75+
main().catch((error) => {
76+
console.error("Error:", error);
77+
});

0 commit comments

Comments
 (0)
Please sign in to comment.