emit!() { /* proc-macro */ }
Expand description

Logs an event that can be subscribed to by clients. Uses the sol_log_data syscall which results in the following log:

Program data: <Base64EncodedEvent>

Example

use anchor_lang::prelude::*;

// handler function inside #[program]
pub fn initialize(_ctx: Context<Initialize>) -> Result<()> {
    emit!(MyEvent {
        data: 5,
        label: [1,2,3,4,5],
    });
    Ok(())
}

#[event]
pub struct MyEvent {
    pub data: u64,
    pub label: [u8; 5],
}