ChronoState is a library which parses memos from individual blocks on-chain and then is meant to use the event sourcing pattern to reconstruct and give applications specific instructions to reconstruct state.
npm install @atomone/chronostateReconstructing the past, validating the present, securing the future.
ChronoState is a library which parses memos from individual blocks on-chain and then is meant to use the event sourcing pattern to reconstruct and give applications specific instructions to reconstruct state.
Using the default cosmos banking module, a memo can be used to invoke action state.
Action state can be targeted towards a specific public address which wants to handle the action state.
The only requirement is that you have a prefix for your memos; which helps the event parser find information about events.
Example
``js`
namespace.Function("arg1", "arg2", "arg3")
``
pnpm i @atomone/chronostate
This is how you setup ChronoState and start the block parsing system. It's recommended to have a starting block number, and use that to reconstruct the rest of the state, or create live state based on that.
`tshttps://atomone-api.allinbits.com/
const endpoints = [, https://atomone-rest.publicnode.com];
// This function takes incoming memos from blocks being parsed
function handleAction(action: Action) {
console.log(action);
}
// This function starts the block parsing process by getting current block height,
// Then sets up a ChronoState instance that looks for messages with a prefix of 0xTest
// It also checks to ensure the receiver is a specific address.
// We give it a minimum height to start processing blocks from, usually last block processed.
async function parseBlocks() {
const height = await getCurrentBlockHeight(endpoints);
const min_height = ${parseInt(height) - 50};
const state = new ChronoState({
API_URLS: endpoints,
MEMO_PREFIX: '0xTest',
// RECEIVER: 'atone1uq6zjslvsa29cy6uu75y8txnl52mw06j6fzlep', // These are optional
// SENDER: 'atone1uq6zjslvsa29cy6uu75y8txnl52mw06j6fzlep', // These are optional
START_BLOCK: min_height,
LOG: true,
});
state.onAction(handleAction);
await state.start();
}
`
This is what you can expect from the handle action function when logging results.
`ts``
{
hash: '682defbf453ffe65a1a56f595fdadd9cc14e99b6e9b8a396bc924b9c69fc9d0b',
from: 'atone16k0xnxqr48qdwxreu6rgcghg0xp9hn7vpn06nm',
to: 'atone1uq6zjslvsa29cy6uu75y8txnl52mw06j6fzlep',
memo: '0xTest',
amounts: [
{ denom: 'uatone', amount: '1000000' }
],
timestamp: '2025-03-18T14:45:37.323011612Z',
height: '2267005'
}