-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathsendChildToParent.ts
58 lines (44 loc) · 1.84 KB
/
sendChildToParent.ts
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
51
52
53
54
55
56
57
58
import { utils, providers, Wallet, BigNumber, Contract } from "ethers";
import { EthBridger, registerCustomArbitrumNetwork } from "@arbitrum/sdk";
import dotenv from "dotenv";
import { ARB_SYS_ADDRESS } from "@arbitrum/sdk/dist/lib/dataEntities/constants";
import { blueberryNetwork as childNetwork} from "../helpers/custom-network";
dotenv.config();
console.log("Environment Variables Loaded");
/**
* Set up: instantiate Parent / Child wallets connected to providers
*/
const walletPrivateKey: string = process.env.DEVNET_PRIVKEY as string;
const parentProvider = new providers.JsonRpcProvider(process.env.ParentRPC);
const childProvider = new providers.JsonRpcProvider(process.env.ChildRPC);
const parentWallet = new Wallet(walletPrivateKey, parentProvider);
const childWallet = new Wallet(walletPrivateKey, childProvider);
const main = async () => {
// register - needed for retryables
registerCustomArbitrumNetwork(childNetwork);
const counter = "0xEEeBe2F778AA186e88dCf2FEb8f8231565769C27";
const abi = ["function increment()"];
const iface = new utils.Interface(abi);
const calldata = iface.encodeFunctionData("increment");
const ethBridger = new EthBridger(childNetwork);
const inboxAddress = ethBridger.childNetwork.ethBridge.inbox;
const arbSysAbi = [
"function sendTxToL1(address destination, bytes calldata data) external payable returns (uint256)",
];
const arbSysContract = new Contract(ARB_SYS_ADDRESS, arbSysAbi, childWallet);
let { data } = await arbSysContract.populateTransaction.sendTxToL1(
counter,
calldata
);
const depositTx = await parentWallet.sendTransaction({
to: ARB_SYS_ADDRESS,
data,
gasLimit: 8000000,
});
let rec = await depositTx.wait();
console.log(`Tx initiated! 🥳 txHash: ${rec.transactionHash}`);
};
main().catch((err) => {
console.error(err);
process.exit(1);
});