One of the challenges of interacting with smart contracts is computing the current state of a contract.
For example, the ERC20 token standard defines a “balanceOf” method for a given input address, but does not dictate how those balances are to be stored or computed. On a token smart contract with hundreds of thousands or millions of balances holders, it is impractical to call “getBalance” for all accounts on every block.
MultiBaas implements a general solution called “Event Queries”. They allow a user to define a set of events and how they should be enumerated or aggregated, for example a list of balances or the most recent status per address.
An Event Query consists of:
Each Event is defined by:
A Field contains:
A Filter contains:
Consider an ERC20 token smart contract "curvetoken".
If the following Transfer(address indexed _from, address indexed _to, uint256 _value) events are emitted by the contract:
Then the state of the contract, if we were to call balanceOf(owner) for each of owner = 0x0, 0xA, 0xB, and 0xC, would be:
To retrieve that data using an event query, we can define one using the API as follows:
We can then execute the query as follows:
Note the "zero" account has a balance of -100. This is a special case as we are simply adding or subtracting all transfers to and from the account.
You can also preview a query by making a POST request.
Event queries are accessed in the UI via the Contracts > Event Queries menu.
The main screen of the event queries management UI displays a list of existing queries, a paginated sample of their results, and actions that can be taken.
Clicking Edit or New Event Query brings up the event query edit screen. The top half of the page allows the user to define the events that will be aggregated into the event query. For each event, one or more fields may be added. For each event query, a field may be selected to group by and order by.
When you update the query, a sample of the results will appear below the query editor.
You can also preview the generated JSON definition of the query by expanding the Query JSON section.
he Events page shows a preview of the events of all contracts being monitored by MultiBaas. To navigate to the Events page
In MultiBaas event monitoring persistence is enabled on a per-smart contract per-address basis when a smart contract is linked ...