β‘Sentio Processor
The core concept of a Sentio project is the Processor. A processor is usually a TypeScript project that contains logic to use blockchain data to generate user-defined data for Sentio. The processor should be written using Sentio's SDK framework and be submitted and run on Sentio.
While Sentio processor provides maximum performance and flexibility, we also support hosted-subgraph that still has many features like SQL/GraphQL API, analytic dashboard, and multi-versioning. This allows you to easily run data pipelines on Sentio without writing new code.
A Sentio processor can handle multiple contracts on multiple chains. To import a contract, simply copy the contract's ABI JSON file into the abis
directory. Running sentio build
or sentio gen
will generate contract processor files into the src/types
directory.
Then you can use the generated contract processor class to bind to an address and add different handlers. The SDK also comes with several built-in contract processors. A minimal processor example with the built-in ERC20 processor is:
import { ERC20Processor } from '@sentio/sdk/eth/builtin/erc20'
ERC20Processor.bind({ address: '0x1e4ede388cbc9f4b5c79681b7f94d36a11abebc9', network: EthChainId.ETHEREUM })
.onEventTransfer((event, ctx) => {
ctx.meter.Counter('token').add(event.args.value)
}
)
The above code first binds the ERC20 contract processor to a specific address on the Ethereum mainnet (specified with network=EthChainId.ETHEREUM
, which can be omitted if just using Ethereum mainnet). Then it registers a function that handles the Transfer
event. For each of these events, we add the transfer value to a metric named token
.
If you bring your own ABI, our codegen will automatically generate all event handler registration methods in a type-safe way as well.
Updated 11 days ago