Skip to main content

Quick Access

Magic Actions Example

Explore reference implementation on GitHub

1) Create action instruction

The instruction update_leaderboard runs on the base layer immediately after the commit lands. The #[action] attribute on its accounts context marks it as callable from a post-commit action.

2) Build the commit instruction with the action

The commit instruction commit_and_update_leaderboard runs on the ER. It uses MagicIntentBundleBuilder to schedule both the commit and the post-commit action onto magic_context — both are applied together when the ER transaction is sealed back to the base layer.

Execute multiple actions

You can commit multiple accounts and chain several actions in one call. Actions execute sequentially in the order they’re passed to add_post_commit_actions.

Undelegate with actions

Actions can also be chained onto an undelegation — the counter commits, undelegates, and the actions run, all atomically in one ER transaction.