Skip to content

Commit

Permalink
example: add cli demo
Browse files Browse the repository at this point in the history
  • Loading branch information
jaipaljadeja committed Oct 17, 2024
1 parent 1b897d9 commit 56fbe71
Show file tree
Hide file tree
Showing 4 changed files with 102 additions and 0 deletions.
19 changes: 19 additions & 0 deletions examples/cli/apibara.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import { defaultSink } from "@apibara/indexer";
import { defineConfig } from "apibara/config";

export default defineConfig({
runtimeConfig: {
test: 123,
check: "something",
},
presets: {
dev: {
runtimeConfig: {
test: 999,
},
},
},
sink: {
default: () => defaultSink(),
},
});
33 changes: 33 additions & 0 deletions examples/cli/indexers/starknet.indexer.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import { defineIndexer } from "@apibara/indexer";
import { StarknetStream } from "@apibara/starknet";
import type { ApibaraRuntimeConfig } from "apibara/types";
import { hash } from "starknet";

export default function (runtimeConfig: ApibaraRuntimeConfig) {
console.log("--> Starknet Indexer Runtime Config: ", runtimeConfig);
return defineIndexer(StarknetStream)({
streamUrl: "https://starknet.preview.apibara.org",
finality: "accepted",
startingCursor: {
orderKey: 80_000n,
},
filter: {
events: [
{
address:
"0x049d36570d4e46f48e99674bd3fcc84644ddd6b96f7c741b1562b82f9e004dc7" as `0x${string}`,
keys: [hash.getSelectorFromName("Transfer") as `0x${string}`],
includeReceipt: true,
},
],
},
async transform({ block: { header } }) {
console.log("Transforming block ", header?.blockNumber);
},
hooks: {
"handler:after": ({ endCursor }) => {
console.log("Handler After ", endCursor?.orderKey);
},
},
});
}
20 changes: 20 additions & 0 deletions examples/cli/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{
"name": "indexer",
"version": "1.0.0",
"description": "",
"scripts": {},
"keywords": [],
"author": "",
"license": "ISC",
"devDependencies": {
"@types/node": "^20.5.2",
"typescript": "^5.6.2"
},
"dependencies": {
"@apibara/indexer": "workspace:*",
"@apibara/protocol": "workspace:*",
"@apibara/starknet": "workspace:*",
"apibara": "workspace:*",
"starknet": "^6.11.0"
}
}
30 changes: 30 additions & 0 deletions examples/cli/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
{
"$schema": "https://json.schemastore.org/tsconfig",
"display": "Default",
"compilerOptions": {
"composite": false,
"declaration": true,
"declarationMap": true,
"esModuleInterop": true,
"forceConsistentCasingInFileNames": true,
"inlineSources": false,
"preserveWatchOutput": true,
"target": "ES2022",
"lib": ["ES2023"],
"module": "ESNext",
"skipLibCheck": true,
"types": ["node"],
"moduleResolution": "bundler",
"isolatedModules": true,
"moduleDetection": "force",
"noEmit": true,
"strict": true,
"noUnusedLocals": true,
"noUnusedParameters": true,
"noFallthroughCasesInSwitch": true,
"sourceMap": true,
"outDir": "./dist",
"baseUrl": "."
},
"exclude": ["node_modules", "dist"]
}

0 comments on commit 56fbe71

Please sign in to comment.