-
-
Notifications
You must be signed in to change notification settings - Fork 41
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
43 additions
and
0 deletions.
There are no files selected for viewing
43 changes: 43 additions & 0 deletions
43
blockchain_integration/pi_network/pi-network-layer2-scaling/examples/rollup_example.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
}); |