How to receive checkpoints through websocket subscription?

Hello, head’s up, I’m a newcomer to SUI.

My objective: Use websockets to retrieve live updates of each new checkpoint via the subscribe_event method from the Rust SDK.

What I’ve tried: I was using a modified version of the event_api.rs GitHub example program to watch the events being emitted on mainnet. I continued to create a set of all events and their names over a 5-minute period and write them to a file. Within this file, there was no event that contained Checkpoint or something similar.

My question: Can I receive live updates of new checkpoints from the websocket endpoint? Or do I have to use the ReadApi with get_latest_checkpoint_sequence_number and then get_checkpoint?

My hope is, for each new checkpoint, to update a set of target wallet addresses via the transactions posted on each checkpoint. Any support is appreciated, thank you.

1 Like

You can subscribe to ValidatorEpochInfoEventV2 events

const client = new SuiClient({
    url: 'https://fullnode.mainnet.sui.io'
});


export const subscribeEvent = async (handler: (e: any) => void) => {
    await client.subscribeEvent({
        filter: {
            MoveEventType: '0x3::validator_set::ValidatorEpochInfoEventV2'
        },
        onMessage: (event: SuiEvent) => {
            console.log('Event Occured:', JSON.stringify(event, null, 2));
        },
    });
}

Also you can query for old events directly (WARNING: Results are paginated ):

async function getEpochInfoEvents() {
    const eventsResponse = await client.queryEvents({
        query: {
            MoveEventType: '0x3::validator_set::ValidatorEpochInfoEventV2'
        },
        limit: 50,
        cursor: null,
        order: 'ascending'
    });

    console.log('eventsResponse = ', eventsResponse.data);
}

getEpochInfoEvents();

Response:

  {
    id: {
      txDigest: '8eBMXpC8Np7RNDwwiGwSmeev1cSoc7w3fPXdikhH7RZo',
      eventSeq: '48'
    },
    packageId: '0x0000000000000000000000000000000000000000000000000000000000000003',
    transactionModule: 'sui_system',
    sender: '0x0000000000000000000000000000000000000000000000000000000000000000',
    type: '0x3::validator_set::ValidatorEpochInfoEventV2',
    parsedJson: {
      commission_rate: '200',
      epoch: '1',
      pool_staking_reward: '0',
      pool_token_exchange_rate: [Object],
      reference_gas_survey_quote: '1000',
      stake: '20000000000000000',
      storage_fund_staking_reward: '0',
      tallying_rule_global_score: '1',
      tallying_rule_reporters: [],
      validator_address: '0xa528acf0c239c28985da3170870629eb58dd9fb2683548317ce0a218427abb8d',
      voting_power: '43'
    },
    bcs: 'q4ijhZmHtJ9JUVUtkz95LTWyCKykkMPBsMub3hLV8TkRaEPTjfELpw9YrjMF3Xofhk1jRvBRsaQ2eL6ZMAPDajmd7Zo9pfhT5wS9kV9ougR3b
T8ixPo8Jafr6fcZ7B5aoyegNFFHMXaHKE6teRsY6vEb',
    timestampMs: '1690231065905'
  },
  {
    id: {
      txDigest: '8eBMXpC8Np7RNDwwiGwSmeev1cSoc7w3fPXdikhH7RZo',
      eventSeq: '49'
    },
    packageId: '0x0000000000000000000000000000000000000000000000000000000000000003',
    transactionModule: 'sui_system',
    sender: '0x0000000000000000000000000000000000000000000000000000000000000000',
    type: '0x3::validator_set::ValidatorEpochInfoEventV2',
    parsedJson: {
      commission_rate: '200',
      epoch: '1',
      pool_staking_reward: '0',
      pool_token_exchange_rate: [Object],
      reference_gas_survey_quote: '1000',
      stake: '20000000000000000',
      storage_fund_staking_reward: '0',
      tallying_rule_global_score: '1',
      tallying_rule_reporters: [],
      validator_address: '0x9b8b11c9b2336d35f2db8d5318ff32de51b85857f0e53a5c31242cf3797f4be4',
      voting_power: '43'
    },
    bcs: 'q4ijhZmHtHxWTMkiWsCbNhvPuQ8TmXjW1Qxc52yvh3XUsRBdBtzMGyfwaZyT3RKDhQqf69iSGZwAgW6w6SQegX6UeoycjLQYUKqSqzG3m32Rj
HV7tE1mMVntarw4h5vpU74XPVRZ7548QhhJcTndFhSf',
    timestampMs: '1690231065905'
  }
...
]
1 Like