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

docs: added declared eth_call #708

Merged
merged 4 commits into from
Jun 17, 2024
Merged
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions website/pages/en/developing/creating-a-subgraph.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -1154,6 +1154,25 @@ eventHandlers:

Inside the handler function, the receipt can be accessed in the `Event.receipt` field. When the `receipt` key is set to `false` or omitted in the manifest, a `null` value will be returned instead.

## Declared eth_call

Reducing `eth_call` definitely improves indexing speed. For `eth_calls` that cannot be eliminated, they can be declared in the subgraph manifest to be processed in parallel with the block processing. When `graph-node` processes a block, it performs all declared `eth_calls` in parallel before handlers are run where as `eth_calls` that are not declared are executed sequentially when handlers run. This helps reducing total time spent on `eth_calls` and improves indexing speed.

> **Note:** [SpecVersion](#specversion-releases) >= `1.2.0` is required. Currently, `eth_calls` can only be declared for event handlers.

### Example Configuration in Subgraph Manifest

```yaml
event: TransferWithPool(address indexed, address indexed, uint256, bytes32 indexed)
handler: handleTransferWithPool
calls:
ERC20.poolInfo: ERC20[event.address].getPoolInfo(event.params.to)
```

In the example above, the `ERC20.poolInfo` is declared `eth_call`. The text before colon(`ERC20.poolInfo`) is the label for this `eth_call` which is used when logging errors. The text after colon(`ERC20[event.address].getPoolInfo(event.params.to)`) is the actual `eth_call` that will be executed which is in the form of `Contract[address].function(arguments)`. The `address` and `arguments` can be replaced with actual values or variables which will be available when executing the handler.
Copy link
Contributor

Choose a reason for hiding this comment

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

The address and arguments can be replaced with actual values or variables which will be available when executing the handler.

I think per this comment you can't pass in hard-coded values currently. The above kind of suggests that you can, so maybe remove "actual values or"?


When declared `eth_calls` are used, `graph-node` caches the results in the memory and when the `eth_call` is triggered inside handlers, it fetches the result from the cache instead of making an actual RPC call.

## Experimental features

Starting from `specVersion` `0.0.4`, subgraph features must be explicitly declared in the `features` section at the top level of the manifest file, using their `camelCase` name, as listed in the table below:
Expand Down
Loading