Starknet
Starknet support is in beta stage. Here is a quick start guide to set up a processor for Starknet.
Create project
You can create a new project with the following command:
npx @sentio/cli@latest create [your-project-name] -c starknet
Navigate to the project directory, where you should find the following files:
βββ package.json
βββ sentio.yaml
βββ src
β βββ processor.test.ts
β βββ processor.ts
βββ tsconfig.json
Setup contract address
Add the contract address in sentio.yaml
file:
project: your-project-name
contracts:
- name: <ContractName> # (optional)
address: <contract address> # Starknet contract address
chain: starknet_sepolia # Chain name, starknet_mainnet or starknet_sepolia
Please use the deployed address of the contract, not the class hash.
Including the contract name is optional but recommended, as it assists in naming the types during code generation.
Retrieve the ABI and Generate Types
Run the following command to retrieve the ABI and generate the types:
yarn sentio build
The abi will be saved in abis/starknet
directory and the types will be generated in src/types/starknet
.
βββ abis
β βββ starknet
β βββ sepolia
β βββ VoteContract-0x00cf88f7ecf1bf36e9262333879e2937611cd81758db64a169776a2710464391.json
βββ package.json
βββ sentio.yaml
βββ src
β βββ processor.test.ts
β βββ processor.ts
β βββ schema
β βββ types
β βββ aptos
β βββ eth
β βββ fuel
β βββ solana
β βββ starknet
β β βββ VoteContract-processor.ts
β β βββ tabi.ts
β βββ sui
βββ tsconfig.json
βββ yarn.lock
Processor
Start your processor by importing the generated code and binding the processor to the contract address. You should find onXXX
methods if the contract has events.
import { VoteContractProcessor } from "./types/starknet/VoteContract-processor.js"
VoteContractProcessor.bind({})
.onVoteEvent(async (event, ctx) => {
// your processor logic
})
The ctx
object has a getContract
method to get the contract instance. You can use it to call the contract's view functions.
VoteContractProcessor.bind({})
.onVoteEvent(async (event, ctx) => {
const votes = await ctx.getContract().get_votes()
})
Updated 21 days ago