Skip to content

Commit 3bc112d

Browse files
authored
docs: added declared eth_call (#708)
* docs: added declared eth_call * fix: prettier fixes * docs: update wordings address & arguments passed * fix: fixed wordings
1 parent 8fe979d commit 3bc112d

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

website/pages/en/developing/creating-a-subgraph.mdx

+19
Original file line numberDiff line numberDiff line change
@@ -1154,6 +1154,25 @@ eventHandlers:
11541154

11551155
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.
11561156

1157+
## Declared eth_call
1158+
1159+
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.
1160+
1161+
> **Note:** [SpecVersion](#specversion-releases) >= `1.2.0` is required. Currently, `eth_calls` can only be declared for event handlers.
1162+
1163+
### Example Configuration in Subgraph Manifest
1164+
1165+
```yaml
1166+
event: TransferWithPool(address indexed, address indexed, uint256, bytes32 indexed)
1167+
handler: handleTransferWithPool
1168+
calls:
1169+
ERC20.poolInfo: ERC20[event.address].getPoolInfo(event.params.to)
1170+
```
1171+
1172+
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 variables which will be available when executing the handler.
1173+
1174+
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.
1175+
11571176
## Experimental features
11581177

11591178
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:

0 commit comments

Comments
 (0)