{"id":13710189,"url":"https://github.com/streamingfast/substreams-sink-kv","last_synced_at":"2025-09-08T00:36:12.274Z","repository":{"id":65447722,"uuid":"585704265","full_name":"streamingfast/substreams-sink-kv","owner":"streamingfast","description":"Substreams KV sink","archived":false,"fork":false,"pushed_at":"2024-11-29T20:08:21.000Z","size":1644,"stargazers_count":2,"open_issues_count":6,"forks_count":5,"subscribers_count":3,"default_branch":"develop","last_synced_at":"2025-04-30T21:01:55.561Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/streamingfast.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2023-01-05T21:19:37.000Z","updated_at":"2024-11-29T20:06:16.000Z","dependencies_parsed_at":"2024-04-04T21:45:34.327Z","dependency_job_id":"97ad6d1f-07cd-4e6e-a79e-bbac3558bf0c","html_url":"https://github.com/streamingfast/substreams-sink-kv","commit_stats":{"total_commits":65,"total_committers":8,"mean_commits":8.125,"dds":0.5538461538461539,"last_synced_commit":"622a3eb856f9155682a82b400508c3d033448e07"},"previous_names":[],"tags_count":12,"template":false,"template_full_name":null,"purl":"pkg:github/streamingfast/substreams-sink-kv","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/streamingfast%2Fsubstreams-sink-kv","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/streamingfast%2Fsubstreams-sink-kv/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/streamingfast%2Fsubstreams-sink-kv/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/streamingfast%2Fsubstreams-sink-kv/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/streamingfast","download_url":"https://codeload.github.com/streamingfast/substreams-sink-kv/tar.gz/refs/heads/develop","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/streamingfast%2Fsubstreams-sink-kv/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":274117385,"owners_count":25225101,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-09-07T02:00:09.463Z","response_time":67,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-08-02T23:00:52.913Z","updated_at":"2025-09-08T00:36:12.251Z","avatar_url":"https://github.com/streamingfast.png","language":"Go","funding_links":[],"categories":["Protobuf"],"sub_categories":["Sinks"],"readme":"# Substreams key-value service Sink\n\nA [Substreams _sink_](https://substreams.streamingfast.io/developers-guide/sink-targets) to pipe data from a [Substreams](https://substreams.streamingfast.io) endpoint into a key-value store and serve queries through either:\n- [Connect-Web protocol](https://connect.build/docs/introduction) (gRPC-compatible) via the `GenericService`\n- a User defined WASM query service\n\n## Requirements\n\n##### WasmEdge\n\nLearn about WasmEdge from its [Quick Start Guide](https://wasmedge.org/book/en/quick_start/install.html), or simply run the following to install.\n\n```bash\ncurl -sSf https://raw.githubusercontent.com/WasmEdge/WasmEdge/master/utils/install.sh | bash -s -- --version 0.11.2\n```\n\n## Install\n\nGet from the [Releases tab](https://github.com/streamingfast/substreams-sink-kv/releases), or from source:\n\n```bash\ngo install -v github.com/streamingfast/substreams-sink-kv/cmd/substreams-sink-kv@latest\n```\n\n## Running\n\nThe `substreams-sink-kv` binary offers two mode of operations:\n- `inject`: Runs a Substreams and pipes the data into a key-value store\n- `serve`: Serves data through a query service: `GenericService` or `WASMQueryService`\n\nYou can run `substreams-sink-kv` solely in `inject` or `serve` mode or both.\n\n\u003e **Note** To connect to Substreams you will need an authentication token, follow this [guide](https://substreams.streamingfast.io/reference-and-specs/authentication) to obtain one.\n\n```bash\n# Inject Mode\nsubstreams-sink-kv inject mainnet.eth.streamingfast.io:443 \u003ckv_dsn\u003e \u003csubstreams_spkg_path\u003e \u003ckv_out\u003e\n\n# Serve Mode\nsubstreams-sink-kv serve \u003ckv_dsn\u003e \u003csubstreams_spkg_path\u003e --listen-addr=\":9000\"\n\n# Inject and Serve Mode\nsubstreams-sink-kv inject mainnet.eth.streamingfast.io:443 \u003ckv_dsn\u003e \u003csubstreams_spkg_path\u003e \u003ckv_out\u003e --listen-addr=\":9000\"\n```\n\n## Query Service\n\nThe Query Service is an API that allows you to consume data from your sinked key-value. There are 2 types of Query Services:\n- Generic Service\n- Wasm Query Service\n\nthe `sink` block of your Substreams manifest defines and configures which one to use\n\n```yaml\nspecVersion: v0.1.0\npackage:\n  name: \"your_substreams_to_sink\"\n  version: v0.0.1\n\n...\n\nsink:\n  module: kv_out\n  type: sf.substreams.sink.kv.v1.WASMQueryService\n  config:\n    wasmQueryModule: \"@@./blockmeta_wasm_query/blockmeta_wasm_query.wasm\"\n    grpcService: \"eth.service.v1.Blockmeta\"\n```\n\nbreaking down the `sink` block we get the following:\n\n- **module**: The name of the module that will be used to sink the key-value store. The module should be of kind `map` with an output type of [`sf.substreams.sink.kv.v1.KVOperations`](https://github.com/streamingfast/substreams-sink-kv/blob/main/proto/substreams/sink/kv/v1/kv.proto)\n- **type**: Support to types currently:\n  - [`sf.substreams.sink.kv.v1.WASMQueryService`](./proto/substreams/sink/kv/v1/services.proto)\n  - [`sf.substreams.sink.kv.v1.GenericService`](./proto/substreams/sink/kv/v1/services.proto)\n- **config**: a key-value structure that matches the attributes of the Proto object for the given `type` selected above\n\n\u003e **_NOTE:_**  the `@@` notation will read the path and inject the content of the file in bytes, while the `@` notation will dump the file content in ascii\n\n\n### Generic Service\n\nThe Generic Query service is a [Connect-Web protocol](https://connect.build/docs/introduction) (gRPC-compatible). It exposes a browser and gRPC-compatible APIs. The API is defined in `protobuf` [here](./proto/substreams/sink/kv/v1/read.proto).\n\nYou can find a detailed example with documentation [here](./examples/generic-service)\n\n### WASM Query Service\n\nThe wasm query service is a user-defined gRPC API that is backed by WASM code, which has access to underlying key-value store.\n\nYou can find a detailed example with documentation [here](./examples/wasm-query-service)\n\n## Contributing\n\nRefer to the [general StreamingFast contribution guide](https://github.com/streamingfast/streamingfast/blob/master/CONTRIBUTING.md).\n\n### WasmEdge\n\nBumping `github.com/second-state/WasmEdge-go` to a newer version requires matching WasmEdge version. For example `github.com/second-state/WasmEdge-go@0.11.2` requires [WasmEdge 0.11.2](https://github.com/WasmEdge/WasmEdge/releases/tag/0.11.2).\n\nIf a new version of [WasmEdge](https://github.com/WasmEdge/WasmEdge), it requires also modifying the [./devel/docker/Dockerfile.goreleaser](./devel/docker/Dockerfile.goreleaser) file so it pulls dependencies required for building using the correct version. Testing the build can be done using by first building the Docker image via `./devel/docker/push.sh` and then running:\n\n```bash\ndocker run --rm -it -v `pwd`:/work -w /work goreleaser-wasmedge:v1.20.3 release --snapshot --clean --skip-validate\n```\n\nManual Golang compilation within the docker image can be done with:\n\n```bash\ndocker run --rm -it -v `pwd`:/work -w /work --entrypoint bash goreleaser-wasmedge:v1.20.3\ncd /work\n# Adjust CC, CXX, C_INCLUDE_PATH, LIBRARY_PATH and GOOS/GOARCH according to .goreleaser.yaml file\nCGO_ENABLED=1 CC=oa64-clang CXX=oa64-clang++ GOOS=darwin GOARCH=arm64 C_INCLUDE_PATH=/usr/local/osxcross/include/arm64 LIBRARY_PATH=\"/usr/local/osxcross/lib/arm64\" go build -trimpath -mod=readonly -ldflags=\"-s -w\" -o /work/substreams-sink-kv-cross-compiled ./cmd/substreams-sink-kv/\n```\n\n## `kvdb` tool\n\nYou can inspect badger files written by this tool with:\n\n```\ngo install github.com/streamingfast/kvdb/cmd/kvdb@develop\n```\n\n## License\n\n[Apache 2.0](https://github.com/streamingfast/substreams/blob/develop/LICENSE/README.md).\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fstreamingfast%2Fsubstreams-sink-kv","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fstreamingfast%2Fsubstreams-sink-kv","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fstreamingfast%2Fsubstreams-sink-kv/lists"}