From 8314615d2a9ef1cc3b6b90079dd6af0cf384b02b Mon Sep 17 00:00:00 2001 From: KOSASIH Date: Sun, 20 Oct 2024 11:48:24 +0700 Subject: [PATCH] Create interact_with_rollup.js --- .../scripts/interact_with_rollup.js | 36 +++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 blockchain_integration/pi_network/pi-network-layer2-scaling/scripts/interact_with_rollup.js diff --git a/blockchain_integration/pi_network/pi-network-layer2-scaling/scripts/interact_with_rollup.js b/blockchain_integration/pi_network/pi-network-layer2-scaling/scripts/interact_with_rollup.js new file mode 100644 index 000000000..f86e4e021 --- /dev/null +++ b/blockchain_integration/pi_network/pi-network-layer2-scaling/scripts/interact_with_rollup.js @@ -0,0 +1,36 @@ +// interact_with_rollup.js +const { ethers } = require("hardhat"); + +async function main() { + const [owner, operator] = await ethers.getSigners(); + + // Assuming the addresses of the deployed contracts are known + const rollupManagerAddress = "YOUR_ROLLUP_MANAGER_ADDRESS"; + const rollupAddress = "YOUR_ROLLUP_ADDRESS"; + const rollupValidatorAddress = "YOUR_ROLLUP_VALIDATOR_ADDRESS"; + + const Rollup = await ethers.getContractAt("Rollup", rollupAddress); + const RollupManager = await ethers.getContractAt("RollupManager", rollupManagerAddress); + const RollupValidator = await ethers.getContractAt("RollupValidator", rollupValidatorAddress); + + // Add an operator + await RollupManager.connect(owner).addOperator(operator.address); + console.log("Operator added:", operator.address); + + // Create a batch + const stateRoot = ethers.utils.keccak256(ethers.utils.toUtf8Bytes("Sample State Root")); + await Rollup.connect(operator).createBatch(stateRoot); + console.log("Batch created with state root:", stateRoot); + + // Validate a transaction + await RollupValidator.connect(operator).validateTransaction(stateRoot, operator.address); + console.log("Transaction validated for operator:", operator.address); +} + +// Execute the interaction script +main() + .then(() => process.exit(0)) + .catch((error) => { + console.error(error); + process.exit(1); + });