Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Eventexample #593

Open
wants to merge 7 commits into
base: main
Choose a base branch
from
Open

Conversation

alex-sumner
Copy link
Contributor

Example code for reading event logs, as called for in issue #578

Copy link
Collaborator

@thiagodeev thiagodeev left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @alex-sumner, sorry for the delay.
Great job, thank you! Left some comments


Steps:
1. Rename the ".env.template" file located at the root of the "examples" folder to ".env"
1. Uncomment, and assign your Ethereum mainnet endpoint to the `RPC_PROVIDER_URL` variable in the ".env" file
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's change "Ethereum" to "Starknet".
Also, could you change this example to use a testnet smart contract? It'll be smoother for the user to use only one RPC provider for all their example interactions without the need to change it.


// create an EventFilter that specifies which events we want
eventFilter := rpc.EventFilter{
FromBlock: rpc.BlockID{Number: fromBlock},
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can change it to use the rpc.WithBlockNumber function, that way we don't need the FROM/TO_BLOCK variables

var events []rpc.EmittedEvent

// read all the events emitted by the contract in this range of blocks
events = readEvents(eventsInput, provider)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Your code is great, but we can make things simpler for new users. What about the first thing we do is call a single event using only starknet.go functions and basic types and print out that event info?
After this first part, we continue to show a more complex interaction (involving multiple calls, pagination, loops...).
Let's use the "readEvents" and "buildKeyFilter" only in this second part

@thiagodeev
Copy link
Collaborator

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants