Scrypto Events
  • 12 Feb 2024
  • 1 Minute to read
  • Dark
    Light
  • PDF

Scrypto Events

  • Dark
    Light
  • PDF

Article Summary

You can register and emit events directly from Scrypto.

use scrypto::prelude::*;

#[derive(ScryptoSbor, ScryptoEvent)]
struct RegisteredEvent {
    number: u64,
}

#[blueprint]
#[events(RegisteredEvent)]
mod example_event {
    struct ExampleEvent;

    impl ExampleEvent {
        pub fn emit_registered_event(number: u64) {
            Runtime::emit_event(RegisteredEvent { number });
        }
    }
}

The Blueprint macro expects an optional #[events(…​)] attribute for the event registration. Multiple attributes could be provided to add more events. I.e:

#[blueprint]
#[event(NewUserEvent, UserIsNoMoreEvent, UserIsUserEvent)]
mod blueprint {
	struct Club {}
	impl Club {}
}

Was this article helpful?

What's Next