I want to emit event from the native rust solana smart contract. And how to add listener to listen all upcoming events for specific smart contract.

1 Answer 1


Anchor rust code snippet:

use anchor_lang::prelude::*;

pub fn initialize(_ctx: Context<Initialize>) -> Result<()> {
    emit!(MyEvent {
        err_msg_code: 100

pub struct MyEvent {
    pub err_msg_code: u32,
  • What happens exactly when a event gets triggered? For instance in your example would MyEvent struct be displayed in logMessages within the corresponding transaction? Commented Jan 6, 2023 at 8:35
  • 2
    @PeterSchwarz Event is emitted so that it can be subscribe to by the clients. And it would not display in logMessages, for that u need to use msg macro. Commented Jun 14, 2023 at 17:19

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.