Skip to content

Commit

Permalink
Create rollup_example.js
Browse files Browse the repository at this point in the history
  • Loading branch information
KOSASIH authored Oct 20, 2024
1 parent 9ab7f80 commit cc8afad
Showing 1 changed file with 43 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
// rollup_example.js
const { ethers } = require("hardhat");
const networkConfig = require("./network_config.json");

async function main() {
const [owner] = await ethers.getSigners();

// Load the Rollup and RollupManager contracts
const rollupManagerAddress = networkConfig.networks.rinkeby.rollupManagerAddress;
const rollupAddress = networkConfig.networks.rinkeby.rollupAddress;

const Rollup = await ethers.getContractFactory("Rollup");
const rollup = await Rollup.attach(rollupAddress);

const RollupManager = await ethers.getContractFactory("RollupManager");
const rollupManager = await RollupManager.attach(rollupManagerAddress);

// Create a new batch
const stateRoot = ethers.utils.keccak256(ethers.utils.toUtf8Bytes("Sample State Root"));
console.log("Creating a new batch with state root:", stateRoot);

const tx = await rollup.connect(owner).createBatch(stateRoot);
await tx.wait();
console.log("Batch created successfully!");

// Validate the batch
console.log("Validating the batch...");
const validatorAddress = await rollupManager.validator();
const validateTx = await rollup.connect(validatorAddress).validateTransaction(stateRoot, owner.address);
await validateTx.wait();
console.log("Batch validated successfully!");

// Check if the transaction is valid
const isValid = await rollup.isTransactionValid(stateRoot, owner.address);
console.log("Is the transaction valid?", isValid);
}

main()
.then(() => process.exit(0))
.catch((error) => {
console.error(error);
process.exit(1);
});

0 comments on commit cc8afad

Please sign in to comment.