Off-Chain Rollup State
This method returns the current off-chain state, representing the most up-to-date database condition including all recent operations that have been processed and cryptographically verified but not yet published to the blockchain.
Real-time state tracking:
- Latest sequence number: Most recent off-chain operation processed
- Current Merkle roots: Immediate state before and after recent operations
- Processing status: Whether off-chain operations are succeeding or failing
- Pending operations: Operations awaiting on-chain rollup publication
- Performance metrics: Timestamps showing off-chain processing speed
Critical for:
- Real-time applications: Get immediate feedback on database operations
- Performance monitoring: Track off-chain processing efficiency
- Rollup preparation: Verify off-chain state before on-chain rollup
- Debugging: Identify issues with recent database operations
- Load balancing: Understand current system processing capacity
Best Practice
Always check off-chain state health before initiating on-chain rollups. Failed off-chain operations should be resolved with proverRetry()
first.
Pre-rollup checklist:
- Check this off-chain state health
- Verify
proverStatus()
isSuccess
- Compare with
rollUpOnChainState()
- If ready, initiate
rollUpOnChainStart()
Performance Advantage
Off-chain state queries are faster and don't depend on blockchain network conditions or gas prices.
Definition
await zkdb
.db(databaseName: string)
.rollUpOffChainState(): Promise<TRollupOffChainStateResponse>;
Parameters
- None
Returns
Promise<TRollupOffChainStateResponse>
: Returns the most current database state including all off-chain operations, or null if no operations have been performed. This represents the real-time state before blockchain rollup, including the latest document changes and their cryptographic proofs.
type TRollupOffChainStateResponse = {
sequenceNumber: bigint;
merkleRootOld: string;
merkleRootNew: string;
timestamp: string;
} | null;
Example
import { ZkDatabase } from 'zkdb';
const zkdb = await ZkDatabase.connect({
userName: "chiro-user",
privateKey: "EKFTciRxyxshZjimay9sktsn7v5PvmC5zPq7q4JnitHUytxUVnFP",
environment: "node",
// This URL is for test environment
url: "https://api.zkdatabase.org/graphql",
});
await zkdb.auth.signIn();
const dbTest = zkdb.db('zkdb_test');
const state = await dbTest.rollUpOffChainState();
console.log('Off-chain state:', state);
await zkdb.auth.signOut();
Result:
{
"sequenceNumber": 10,
"merkleRootOld": "0x123...",
"merkleRootNew": "0x456...",
"timestamp": "2025-01-01T00:00:00.000Z"
}