@pylon-protocol/hype
v0.3.0
Published
On-chain Event Subscriber Framework for Terra Blockchain
Downloads
7
Readme
An experimental indexer framework. Allows subscribing on-chain events from Terra Blockchain.
Architecture Overview
Example
Subscribing CW20 Transfers in Real-Time
const hype = await createRealtimeHype();
const ancTransferFinder = createCw20TransferLogFinder('terra14z56l0fp2lsf86zy3hty2z47ezkhnthtr9yq76');
hype.subscribe('anchor-transfer', async (block) => {
extractEventsInBlock(block, [ancTransferFinder])
.forEach(({ txHash, event: { from, to, amount } }) => {
console.log(`Sent ${amount} ANC from ${from} to ${to}`);
console.log(` -> https://finder.terra.money/mainnet/tx/${txHash}`);
});
});
await hype.start();
Indexing CW20 Transfer Logs in Real-Time
const datasource = new BlockPoller(
new LCDBlockFetcher(),
saveLastSyncedHeightInHivePersistence(new DynamoDBDriver({...})),
);
const hype = new Hype(datasource);
hype.subscribe(
'cw20-transfer',
createPersistentIndexer(Cw20TransferLog, async (block) =>
extractEventsInBlock(block, [
createReturningLogFinderRule(
{
type: 'from_contract',
attributes: [
['contract_address'],
['action', 'transfer'],
['from'],
['to'],
['amount'],
],
},
(_, match) => Cw20TransferLog.create({
token: match[0].value,
from: match[2].value,
to: match[3].value,
amount: match[4].value,
}),
),
])
),
);
await hype.start();
Indexing Specific Range of Blocks
Replace BlockPoller
with BlockBackFiller
.
const datasource = new BlockBackFiller(
new FCDBlockFetcher('https://hive.terra.dev/graphql'),
4980471, 4981423,
);
const hype = new Hype(datasource);
hype.subscribe('cw20-transfer', ...);
hype.start();