The Account pattern (contracts/core/pattern/Account.sol) is the easiest way to start with the Bloxchain protocol. It combines all core security components into a single upgrade‑safe contract:
SecureOwnable– owner / broadcaster / recovery roles and secure ownership flowsRuntimeRBAC– dynamic roles and function permissionsGuardController– time‑locked, meta‑tx‑aware execution with target whitelists
abstract contract Account is GuardController, RuntimeRBAC, SecureOwnable {
// initialize(...) wires all three components
// supportsInterface(...) joins all component interfaces
// receive() accepts ETH, fallback() rejects unsupported calls
}Concrete implementations (for example AccountBlox) inherit from Account and add application‑specific logic while reusing the shared state machine and security model.
-
Initialization
- Single
initialize(initialOwner, broadcaster, recovery, timeLockPeriodSec, eventForwarder)call that:- Initializes the shared
SecureOperationStatevia each component. - Loads definition libraries for:
- Secure ownership operations (
SecureOwnableDefinitions) - Runtime role configuration (
RuntimeRBACDefinitions) - Guarded execution and whitelists (
GuardControllerDefinitions)
- Secure ownership operations (
- Initializes the shared
- Operational recommendation: For many deployed instances, use a factory / cloner that deploys the proxy (or minimal proxy) and invokes
initializein the same transaction so initialization cannot be skipped by mistake. Reference implementation:CopyBlox(contracts/examples/applications/CopyBlox/CopyBlox.sol) — validatesIBaseStateMachine, clones, callsinitialize, reverts on failure. Manual transparent/UUPS deploys should follow an explicit runbook; see Getting Started — Deployment and initialization.
- Single
-
Security Model
- Protected roles (
OWNER_ROLE,BROADCASTER_ROLE,RECOVERY_ROLE) are controlled only bySecureOwnable. - Non‑protected roles and function permissions are configured via
RuntimeRBACrole config batches. - Execution of arbitrary calls (including ERC‑20, application contracts, etc.) is mediated by
GuardController:- Time‑locked request / approve / cancel flows.
- Meta‑transaction based approvals (owner signs, broadcaster executes).
- Strict per‑function target whitelists.
- Protected roles (
-
ETH Handling
receive()accepts plain ETH and emitsEthReceived(sender, value).fallback()always reverts – all non‑ETH‑transfer calls must go through known selectors coordinated by the state machine.
From the SDK’s perspective, an Account is one contract address that simultaneously exposes all three component interfaces.
You typically create three wrappers pointing to the same address:
import {
SecureOwnable,
RuntimeRBAC,
GuardController,
} from '@bloxchain/sdk';
import { createPublicClient, createWalletClient, http } from 'viem';
import { sepolia } from 'viem/chains';
import { privateKeyToAccount } from 'viem/accounts';
// 1) Create clients
const rpcUrl = process.env.RPC_URL!;
const privateKey = process.env.PRIVATE_KEY!;
const account = privateKeyToAccount(privateKey);
const publicClient = createPublicClient({
chain: sepolia,
transport: http(rpcUrl),
});
const walletClient = createWalletClient({
account,
chain: sepolia,
transport: http(rpcUrl),
});
// 2) Use a deployed Account-based contract (e.g. AccountBlox)
const accountAddress = '0x...' as `0x${string}`; // from deployed-addresses.json
const secureOwnable = new SecureOwnable(publicClient, walletClient, accountAddress, sepolia);
const runtimeRBAC = new RuntimeRBAC(publicClient, walletClient, accountAddress, sepolia);
const guardController = new GuardController(publicClient, walletClient, accountAddress, sepolia);Once instantiated:
- Use
secureOwnableto:- Inspect and change owner / broadcaster / recovery (via secure, time‑locked flows).
- Update global time‑lock configuration.
- Use
runtimeRBACto:- Inspect roles and their permissions.
- Apply role config batches using the same definition contracts used on‑chain.
- Use
guardControllerto:- Submit guarded executions via
executeWithTimeLockorexecuteWithPayment. - Approve / cancel via time‑lock or meta‑transactions.
- Configure whitelists and function schemas using guard config batches.
- Submit guarded executions via
Use Account (or an Account‑based implementation) when you want:
- A single address that:
- Can receive ETH.
- Can own / guard other contracts and tokens.
- Has auditable, time‑locked, role‑based approvals for critical operations.
- The full Bloxchain security model without wiring each component by hand.
For a step‑by‑step walkthrough that uses an Account‑based contract as the entry point, see the updated Getting Started guide.