Skip to content

Explain keys usage for provider.getEvents() in starknetjs.com #1486

@rsodre

Description

@rsodre

Is your feature request related to a problem? Please describe.
NO

Describe the solution you'd like
The usage example of provider.getEvents() here does not explain how the keys argument is formatted, and it is not intuitive.

import { RpcProvider } from 'starknet';
const myProvider = new RpcProvider({ nodeUrl: `${myNodeUrl}` });
const lastBlock = await myProvider.getBlock('latest');
const keyFilter = [[num.toHex(hash.starknetKeccak('EventPanic')), '0x8']];
const eventsList = await myProvider.getEvents({
address: myContractAddress,
from_block: { block_number: lastBlock.block_number - 9 },
to_block: { block_number: lastBlock.block_number },
keys: keyFilter,
chunk_size: 10,
});

I actually doubt this example will work (I haven't tested).
From what I found, the correct keys for this call should be [[num.toHex(hash.starknetKeccak('EventPanic'))], ['0x8']]

The correct use of keys is explained on SNIP-13:

Starknet's json-rpc starknet_getEvents method, takes an EventFilter object, which contains a nested list of keys to be matched against. For example, if the user sent an event filter containing
[[k1,k2],[;],[k3]], then the node should return events whose first key is k1 or k2, and the third key is k3, and the second key is unconstrained and can take any value.

Describe alternatives you've considered

Trial and error did not get me anywhere.
I only found the solution on SNIP-13.

Additional context

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions