View Creator
ViewView A curated, SDL-defined representation of defraDB documents. Views transform raw indexed data into a structured output shape. Creator (ViewkitViewkit A CLI tool for creating, testing, and deploying views. It defines the SDL, attaches lenses, runs local validation using the Wasmer runtime, packages everything into a ViewBundle, and submits a deploy transaction to the View Registry.) is a CLI tool that helps you initialize, manage, and publish Shinzo viewsView A curated, SDL-defined representation of defraDB documents. Views transform raw indexed data into a structured output shape..
1. Prerequisites
OS
- macOS on Apple Silicon (M1/M2/M3) or Linux (x86_64 / amd_64)
Tools
gitmake- Go 1.23+ installed and on your PATH
Check Go:
go version
# expect something like: go version go1.23.x ...
Optional but helpful:
- A code editor (VS Code, GoLand, etc.)
- Basic comfortability running terminal commands
2. Clone the repository
From the directory where you keep your projects:
git clone https://github.com/shinzonetwork/shinzo-view-creator.git
cd shinzo-view-creator
3. Build the viewkit binary
From the repo root:
make build
If the build is successful, you should see a build directory:
ls build
# viewkit (plus any other build artifacts)
You can now run ViewkitViewkit A CLI tool for creating, testing, and deploying views. It defines the SDL, attaches lenses, runs local validation using the Wasmer runtime, packages everything into a ViewBundle, and submits a deploy transaction to the View Registry. via:
./build/viewkit --help
Optional: add viewkit to your PATH
So you don’t have to type ./build each time:
echo 'export PATH="$PWD/build:$PATH"' >> ~/.zshrc
source ~/.zshrc
Then you can run:
viewkit --help
4. Wasmer runtime
ViewkitViewkit A CLI tool for creating, testing, and deploying views. It defines the SDL, attaches lenses, runs local validation using the Wasmer runtime, packages everything into a ViewBundle, and submits a deploy transaction to the View Registry. can execute WebAssembly lensesLens A WASM module that transforms primitive documents (e.g., raw `Log` records) into view documents (e.g., `USDCTransfer`). Lenses must be deterministic: the same input always produces the same output. Hosts run them via LensVM. locally to validate and preview them.
Under the hood, it uses wasmer-go, which depends on a native dynamic library (libwasmer.dylib). If macOS cannot find that library, any command that touches lensesLens A WASM module that transforms primitive documents (e.g., raw `Log` records) into view documents (e.g., `USDCTransfer`). Lenses must be deterministic: the same input always produces the same output. Hosts run them via LensVM. will fail with an error like:
image not found
library not loaded: libwasmer.dylib
This section explains how to set that up.
4.1 Install the Wasmer Go module
From the repo root:
go get github.com/wasmerio/wasmer-go@v1.0.4
This ensures wasmer-go and its packaged native libraries are present in your GOPATH.
4.2 Environment variables
We will use three environment variables:
-
WASMER_ROOT
Points to the directory wherelibwasmer.dyliblives. -
WASMER_LIB_PATH
Used bywasmer-goto find the dynamic library. -
DYLD_LIBRARY_PATH
macOS dynamic loader search path. We prependWASMER_ROOTso the loader can findlibwasmer.dylibwhenviewkitstarts.
4.3 Configure the env vars
Append these lines to your ~/.zshrc if on Apple Silicon:
echo 'export WASMER_ROOT="$(go env GOPATH)/pkg/mod/github.com/wasmerio/wasmer-go@v1.0.4/wasmer/packaged/lib/darwin-aarch64"' >> ~/.zshrc
echo 'export WASMER_LIB_PATH="$WASMER_ROOT"' >> ~/.zshrc
echo 'export DYLD_LIBRARY_PATH="$WASMER_ROOT:$DYLD_LIBRARY_PATH"' >> ~/.zshrc
Otherwise append these lines to your ~/.zshrc if on Linux:
echo 'export WASMER_ROOT="$(go env GOPATH)/pkg/mod/github.com/wasmerio/wasmer-go@v1.0.4/wasmer/packaged/lib/linux-amd64"' >> ~/.zshrc
echo 'export WASMER_LIB_PATH="$WASMER_ROOT"' >> ~/.zshrc
echo 'export LD_LIBRARY_PATH="$WASMER_ROOT:$LD_LIBRARY_PATH"' >> ~/.zshrc
Reload your shell configuration:
source ~/.zshrc
Verify:
echo "$WASMER_ROOT"
ls "$WASMER_ROOT"
# you should see libwasmer.dylib here
If libwasmer.dylib is missing, re-run the go get step and ensure go env GOPATH returns a valid path.
5. Concepts: Views, queries, SDL, lenses, wallets
ViewkitViewkit A CLI tool for creating, testing, and deploying views. It defines the SDL, attaches lenses, runs local validation using the Wasmer runtime, packages everything into a ViewBundle, and submits a deploy transaction to the View Registry. revolves around viewsView A curated, SDL-defined representation of defraDB documents. Views transform raw indexed data into a structured output shape.. Each viewView A curated, SDL-defined representation of defraDB documents. Views transform raw indexed data into a structured output shape. is a bundle that includes:
- Metadata – name, version, target info
- Query – the raw shape of data to ingest
(for example:Log { address topics data transactionHash blockNumber }) - SDL (GraphQL) – how that data is modeled/exposed
(for example:type FilteredAndDecodedLogs { transactionHash: String }) - LensesLens A WASM module that transforms primitive documents (e.g., raw `Log` records) into view documents (e.g., `USDCTransfer`). Lenses must be deterministic: the same input always produces the same output. Hosts run them via LensVM. (WASMWASM A portable, sandboxed bytecode format. Lens transforms compile to WASM — typically from Rust or AssemblyScript — and hosts run them via LensVM.) – chained transforms that filter/decode/reshape data
- Wallet – key used to sign deployments to a target network (
local,devnet, etc.)
Think of the pipeline as:
raw data → query → lensesLens A WASM module that transforms primitive documents (e.g., raw `Log` records) into view documents (e.g., `USDCTransfer`). Lenses must be deterministic: the same input always produces the same output. Hosts run them via LensVM. (WASMWASM A portable, sandboxed bytecode format. Lens transforms compile to WASM — typically from Rust or AssemblyScript — and hosts run them via LensVM.) → GraphQL SDL → viewView A curated, SDL-defined representation of defraDB documents. Views transform raw indexed data into a structured output shape. stored + queryable
6. Quickstart: create and deploy a view (testdeploy)
We’ll walk end-to-end through an example viewView A curated, SDL-defined representation of defraDB documents. Views transform raw indexed data into a structured output shape. named testdeploy:
- Initialize the viewView A curated, SDL-defined representation of defraDB documents. Views transform raw indexed data into a structured output shape. bundle
- Inspect it
- Add a query
- Add SDL
- Attach a lensLens A WASM module that transforms primitive documents (e.g., raw `Log` records) into view documents (e.g., `USDCTransfer`). Lenses must be deterministic: the same input always produces the same output. Hosts run them via LensVM.
- Generate a wallet
- Deploy locally (with DefraDBdefraDB A peer-to-peer, document-oriented database embedded in every indexer and host. It handles storage, content addressing, CRDT merging, query serving, and P2P replication via libp2p. Playground)
- Deploy to devnet
All commands assume
viewkitis on your PATH.
If not, replaceviewkitwith./build/viewkit.
6.1 Initialize the view bundle
viewkit view init testdeploy
This:
- Creates a new viewView A curated, SDL-defined representation of defraDB documents. Views transform raw indexed data into a structured output shape. bundle called
testdeployon disk - Registers internal metadata for queries, SDL, lensesLens A WASM module that transforms primitive documents (e.g., raw `Log` records) into view documents (e.g., `USDCTransfer`). Lenses must be deterministic: the same input always produces the same output. Hosts run them via LensVM., and versions
6.2 Inspect the bundle
viewkit view inspect testdeploy
You should see something like:
- ViewView A curated, SDL-defined representation of defraDB documents. Views transform raw indexed data into a structured output shape. name:
testdeploy - A version / ID
- Initially empty or default sections for:
- Queries
- SDL
- LensesLens A WASM module that transforms primitive documents (e.g., raw `Log` records) into view documents (e.g., `USDCTransfer`). Lenses must be deterministic: the same input always produces the same output. Hosts run them via LensVM.
6.3 Add a query (raw ingest shape)
Define the raw data shape to ingest, e.g. basic EVMEVM The runtime that executes Solidity smart contracts. ShinzoHub embeds an EVM module so its registries are accessible as precompiled contracts at fixed addresses, callable from any EVM tooling. logsLog A document type the indexer produces for event logs emitted during transaction execution. `topics` holds the indexed parameters and `data` holds the non-indexed ones, both as raw hex. ABI decoding happens later, in a lens.:
viewkit view add query \
"Log {address topics data transactionHash blockNumber}" \
--name testdeploy
This tells ViewkitViewkit A CLI tool for creating, testing, and deploying views. It defines the SDL, attaches lenses, runs local validation using the Wasmer runtime, packages everything into a ViewBundle, and submits a deploy transaction to the View Registry. that testdeploy will ingest Log objects with the specified fields.
Check:
viewkit view inspect testdeploy
# now the query is attached to the view
6.4 Add SDL (GraphQL schema)
Add SDL to describe how the data is modeled/exposed:
viewkit view add sdl \
"type FilteredAndDecodedLogs @materialized(if: false) {transactionHash: String}" \
--name testdeploy
Notes:
@materialized(if: false)
Treat this as a virtual type, not a persisted table.transactionHash: String
Minimal example field; real viewsView A curated, SDL-defined representation of defraDB documents. Views transform raw indexed data into a structured output shape. will define more fields.
Inspect again:
viewkit view inspect testdeploy
# now shows both query and SDL
6.5 Attach a lens (WASM transform)
Attach a WebAssembly lensLens A WASM module that transforms primitive documents (e.g., raw `Log` records) into view documents (e.g., `USDCTransfer`). Lenses must be deterministic: the same input always produces the same output. Hosts run them via LensVM. that filters logsLog A document type the indexer produces for event logs emitted during transaction execution. `topics` holds the indexed parameters and `data` holds the non-indexed ones, both as raw hex. ABI decoding happens later, in a lens. by a specific address:
viewkit view add lens \
--args '{"src":"address", "value":"0x1e3aA9fE4Ef01D3cB3189c129a49E3C03126C636"}' \
--label "filter" \
--url "https://raw.githubusercontent.com/shinzonetwork/wasm-bucket/main/bucket/filter_transaction/filter_transaction.wasm" \
--name testdeploy
Flags:
--args– JSON passed to the lensLens A WASM module that transforms primitive documents (e.g., raw `Log` records) into view documents (e.g., `USDCTransfer`). Lenses must be deterministic: the same input always produces the same output. Hosts run them via LensVM.--label "filter"– human-readable label for the lensLens A WASM module that transforms primitive documents (e.g., raw `Log` records) into view documents (e.g., `USDCTransfer`). Lenses must be deterministic: the same input always produces the same output. Hosts run them via LensVM.--url– remote URL of the.wasmbinary--name testdeploy– attaches this lensLens A WASM module that transforms primitive documents (e.g., raw `Log` records) into view documents (e.g., `USDCTransfer`). Lenses must be deterministic: the same input always produces the same output. Hosts run them via LensVM. to thetestdeployviewView A curated, SDL-defined representation of defraDB documents. Views transform raw indexed data into a structured output shape.
Inspect:
viewkit view inspect testdeploy
# you should now see:
# - query
# - SDL
# - lens "filter"
If you see libwasmer.dylib / “image not found” errors, revisit the WasmerWasmer A WASM runtime written in Rust. Viewkit uses it to validate lenses locally before deployment. setup.
7. Wallet: create a deployment key
You need a wallet to sign deployments to local and devnet.
Generate one:
viewkit wallet generate
This will:
- Create a new keypair
- Store it in the wallet directory used by ViewkitViewkit A CLI tool for creating, testing, and deploying views. It defines the SDL, attaches lenses, runs local validation using the Wasmer runtime, packages everything into a ViewBundle, and submits a deploy transaction to the View Registry.
- Print details such as the address (and possibly a mnemonic/seed)
Treat it like any other wallet:
- Do not commit it to Git
- Do not paste the mnemonic in public places
- Store it securely
8. Deploy locally with --target local
The recommended flow is to deploy locally first, verify the viewView A curated, SDL-defined representation of defraDB documents. Views transform raw indexed data into a structured output shape. in a Playground, then deploy to a shared network like devnet.
Deploy to local:
viewkit view deploy testdeploy --target local
On success, you’ll see output similar to:
🚀 DefraDB is running on port 9181
⏳ Waiting for DefraDB to boot up...
✅ DefraDB booted up
⏳ Applying Schemas ...
✅ Schema Applied
⏳ Data Inserting...
✅ Data Inserted Successfully
✅ Applying View ...
✅ View Successfully Applied
🧪 Visit the DefraDB GraphQL Playground at http://127.0.0.1:9181/
📦 Press Ctrl+C to stop...
What’s happening:
- A local DefraDBdefraDB A peer-to-peer, document-oriented database embedded in every indexer and host. It handles storage, content addressing, CRDT merging, query serving, and P2P replication via libp2p. instance is started (port shown in the logsLog A document type the indexer produces for event logs emitted during transaction execution. `topics` holds the indexed parameters and `data` holds the non-indexed ones, both as raw hex. ABI decoding happens later, in a lens.).
- Schemas for your viewView A curated, SDL-defined representation of defraDB documents. Views transform raw indexed data into a structured output shape. are applied.
- Any seed data (if configured) is inserted.
- The viewView A curated, SDL-defined representation of defraDB documents. Views transform raw indexed data into a structured output shape. is applied.
- A DefraDBdefraDB A peer-to-peer, document-oriented database embedded in every indexer and host. It handles storage, content addressing, CRDT merging, query serving, and P2P replication via libp2p. GraphQL Playground URL is printed.
8.1 Use the DefraDB GraphQL Playground
-
Open the displayed URL in your browser, e.g.:
http://127.0.0.1:9181/
-
You should see a GraphQL Playground / explorer.
-
You can:
- Inspect the schema (e.g. see
FilteredAndDecodedLogs). - Run test queries against your local viewView A curated, SDL-defined representation of defraDB documents. Views transform raw indexed data into a structured output shape..
- Verify that your lensLens A WASM module that transforms primitive documents (e.g., raw `Log` records) into view documents (e.g., `USDCTransfer`). Lenses must be deterministic: the same input always produces the same output. Hosts run them via LensVM. is filtering logsLog A document type the indexer produces for event logs emitted during transaction execution. `topics` holds the indexed parameters and `data` holds the non-indexed ones, both as raw hex. ABI decoding happens later, in a lens. as expected.
- Inspect the schema (e.g. see
Example query (adjust to your SDL):
{
filteredAndDecodedLogs {
transactionHash
}
}
While this process is running, viewkit will keep the local DefraDBdefraDB A peer-to-peer, document-oriented database embedded in every indexer and host. It handles storage, content addressing, CRDT merging, query serving, and P2P replication via libp2p. instance alive. To stop it:
- Go back to the terminal and press Ctrl+C.
To iterate:
-
Update your viewView A curated, SDL-defined representation of defraDB documents. Views transform raw indexed data into a structured output shape. (queries/SDL/lensesLens A WASM module that transforms primitive documents (e.g., raw `Log` records) into view documents (e.g., `USDCTransfer`). Lenses must be deterministic: the same input always produces the same output. Hosts run them via LensVM.).
-
Re-run:
viewkit view deploy testdeploy --target local -
Refresh the Playground and test again.
9. Deploy to devnet with --target devnet
Once your viewView A curated, SDL-defined representation of defraDB documents. Views transform raw indexed data into a structured output shape. behaves correctly locally, you can deploy it to devnet.
Make sure:
- A wallet has been generated:
viewkit wallet generate - Any required devnet config/credentials are set
Then:
viewkit view deploy testdeploy --target devnet --rpc http://shinzohub-rpc.infra.source.network:8545
Conceptually:
- ViewkitViewkit A CLI tool for creating, testing, and deploying views. It defines the SDL, attaches lenses, runs local validation using the Wasmer runtime, packages everything into a ViewBundle, and submits a deploy transaction to the View Registry. bundles the
testdeployviewView A curated, SDL-defined representation of defraDB documents. Views transform raw indexed data into a structured output shape. definition (queries, SDL, lensesLens A WASM module that transforms primitive documents (e.g., raw `Log` records) into view documents (e.g., `USDCTransfer`). Lenses must be deterministic: the same input always produces the same output. Hosts run them via LensVM., metadata). - Signs a deployment transaction using your wallet.
- Sends it to the
devnetnetwork. - Registers the viewView A curated, SDL-defined representation of defraDB documents. Views transform raw indexed data into a structured output shape. on devnet so it can be used and queried there.
On success, you should see:
- A transaction hash or deployment ID
- A status message indicating success
If it fails:
- Confirm your wallet is present and funded (if required)
- Confirm
devnetis a valid target - Re-check the viewView A curated, SDL-defined representation of defraDB documents. Views transform raw indexed data into a structured output shape. definition with
viewkit view inspect testdeploy
10. Full flow cheat sheet
Here is the entire flow summarized:
# 0) clone + build
cd ~/code
git clone https://github.com/shinzonetwork/view-creator.git
cd view-creator
make build
export PATH="$PWD/build:$PATH"
# 1) initialize the view bundle
viewkit view init testdeploy
# 2) inspect the bundle
viewkit view inspect testdeploy
# 3) add a query (raw event shape to ingest)
viewkit view add query \
"Log {address topics data transactionHash blockNumber}" \
--name testdeploy
# 4) add SDL (how data is modeled/stored)
viewkit view add sdl \
"type FilteredAndDecodedLogs @materialized(if: false) {transactionHash: String}" \
--name testdeploy
# 5) attach a lens (WASM transform to filter by address)
viewkit view add lens \
--args '{"src":"address", "value":"0x1e3aA9fE4Ef01D3cB3189c129a49E3C03126C636"}' \
--label "filter" \
--url "https://raw.githubusercontent.com/shinzonetwork/wasm-bucket/main/bucket/filter_transaction/filter_transaction.wasm" \
--name testdeploy
# 6) create a wallet for deployments (one-time)
viewkit wallet generate
# 7) deploy locally and use the DefraDB Playground
viewkit view deploy testdeploy --target local
# -> follow the printed URL (e.g. http://127.0.0.1:9181/) for the GraphQL Playground
# -> press Ctrl+C in the terminal to stop
# 8) once you're happy, deploy to devnet
viewkit view deploy testdeploy --target devnet
This gives you a clean path from GitHub clone to a locally tested viewView A curated, SDL-defined representation of defraDB documents. Views transform raw indexed data into a structured output shape. and then to a devnet deployment.