I have used the emit macro in Anchor to emit events from the smart contract as follows,
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],
}
Now I want to subscribe to these events from my TS frontend. I want the ability to subscribe to new events as well as the ability to query past events. Is this possible on Solana and if so, how can I do this?