-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathindex.js
50 lines (40 loc) · 1.41 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
const ethers = require("ethers")
require('dotenv').config()
PRIVATE_KEY = process.env.PRIVATE_KEY
L2_RPC_URL = process.env.L2_RPC_URL || "https://goerli-rollup.arbitrum.io/rpc"
L3_RPC_URL = process.env.L3_RPC_URL
INBOX_CONTRACT_ADDRESS = process.env.INBOX_CONTRACT_ADDRESS
VALUE = process.env.VALUE
// Exporting the main function for use in other scripts
const depositETH = async () => {
if (!PRIVATE_KEY || !L2_RPC_URL || !L3_RPC_URL) {
throw new Error('Required environment variable not found');
}
// Generating providers from RPCs
const l2Provider = new ethers.providers.JsonRpcProvider(L2_RPC_URL);
// Creating the wallet and signer
const l2Signer = new ethers.Wallet(PRIVATE_KEY).connect(l2Provider);
// create contract instance
const depositEthInterface = new ethers.utils.Interface([
"function depositEth() public payable"
]);
const contract = new ethers.Contract(INBOX_CONTRACT_ADDRESS, depositEthInterface, l2Signer);
if (!VALUE) {
VALUE = '0.4'
}
const tx = await contract.depositEth({
value: ethers.utils.parseEther(VALUE)
});
console.log(`Briding ${VALUE} eth to your L3...`)
console.log('Transaction hash on Arbitrum Goerli: ', tx.hash);
await tx.wait();
console.log('Transaction has been mined');
}
const main = async () => {
await depositETH()
} // main
main().then(() => process.exit(0))
.catch((error) => {
console.error(error)
process.exit(1)
})