Simple counter program using Bolt and Ephemeral Rollups.
Read more about the Bolt framework here: https://docs.magicblock.gg/BOLT/Introduction/introduction
Build the program:
bolt build
Add the Ephemeral Rollup endpoints to the env variables:
export PROVIDER_ENDPOINT="<provided endpoint>"
export WS_ENDPOINT="<provided endpoint>"
Run the tests:
bolt test --skip-deploy
Delegating an account is the process of transferring the ownership of an account to the delegation program. After delegation, the account can be treated as a regular account in the Ephemeral Rollups, where transactions can be run with low-latency.
A component can be made delegatable by adding the delegate
attribute.
-
Add the delegate attribute:
#[component(delegate)] #[derive(Default)] pub struct Counter { pub count: u64, }
-
After delegation, you can run transactions on the account with low-latency. Any transaction that would work on the base base layer will work on the delegated account.
-
Call the instruction to execute the delegation
const counterPda = FindComponentPda(counterComponent.programId, entityPda); const delegateIx = createDelegateInstruction({ entity: entityPda, account: counterPda, ownerProgram: counterComponent.programId, payer: provider.wallet.publicKey, }); const tx = new anchor.web3.Transaction().add(delegateIx); const txSign = await provider.sendAndConfirm(tx);
-
Apply a system:
const applySystem = await ApplySystem({ authority: providerEphemeralRollup.wallet.publicKey, system: systemIncrease.programId, entity: entityPda, components: [counterComponent.programId], }); const txSign = await providerEphemeralRollup.sendAndConfirm(applySystem.transaction);
Undelegating an account is the process of transferring the ownership of an account back to the owner program.
You can undelegate with:
const counterComponentPda = FindComponentPda(
counterComponent.programId, entityPda
);
const undelegateIx = createUndelegateInstruction({
payer: provider.wallet.publicKey,
delegatedAccount: counterComponentPda,
ownerProgram: counterComponent.programId,
reimbursement: provider.wallet.publicKey,
});
const tx = new anchor.web3.Transaction().add(undelegateIx);
await provider.sendAndConfirm(tx);
To run tests using a local ephemeral validator, follow these steps:
Ensure you have the ephemeral validator installed globally:
npm install -g @magicblock-labs/ephemeral-validator
Run the local validator with the appropriate environment variables:
ACCOUNTS_REMOTE=https://rpc.magicblock.app/devnet ACCOUNTS_LIFECYCLE=ephemeral ephemeral-validator
ACCOUNTS_REMOTE
point to the reference RPC endpoint, and ACCOUNTS_LIFECYCLE
should be set to ephemeral
.
Execute the tests while pointing to the local validator:
PROVIDER_ENDPOINT=http://localhost:8899 WS_ENDPOINT=ws://localhost:8900 anchor test --skip-build --skip-deploy --skip-local-validator
This setup ensures tests run efficiently on a local ephemeral rollup while connecting to the devnet.