Skip to content

Checking Wasm binary

Stackr builds a Wasm binary of your State Machine and stores it in stackr_build/stf.wasm. You can check the binary using a Wasm runtime like wasmtime or similar tools.

In this example, we will use wasmtime to check the binary.

Install Wasmtime

Terminal
curl https://wasmtime.dev/install.sh -sSf | bash

Run Wasmtime

We give an object consisting of an array of actions and currentState to the Stackr State Machine (SSM) which then applies these actions and returns the next state.

The easiest way to check that the SSM is valid is to give it an array of empty actions and a 'currentState' which could be the state object in your 'genesis-state.json' (0 in case of counter). It should then return the same state as no actions were applied.

Terminal
# Fetch provider for Javy, this is required to be dynamically linked before running the Wasm binary
npx javy-cli emit-provider -o provider.wasm
 
# Run a sample block with no actions and hooks
echo '{"actions":[],"hooks":[],"currentState":0}' | wasmtime run --preload javy_quickjs_provider_v2=provider.wasm stackr_build/stf.wasm

and you should see the output as:

Terminal
{"state":0,"root":"0x....."}

State above is the updated state after applying the actions. And root is stateRoot as defined in your state machine.

Anything else in the output means that the Wasm binary is not working as expected or failed to compile.