Context
Give the function a context
This page is outdated. Please visit here for the most up-to-date content.
The first argument of any function must be a &str
. You can use it to pass a context
value to every function call. For example, we can set a context
string for wasm ID 123
, which is the hello world wasm example we just created. The context specifies that the function should say hello in emoji.
The Rust function now looks like this.
The next time you run it, it says hello based on the context.
The response is as follows.
We have just used a simple string as the context. For more complex use cases, the context could be a JSON object. You can set the state to the entire JSON string. The function is responsible for parsing the JSON string argument and makes sense of it.
You can also store the Second State VM storage ID in the stateful context. That enables stateful functions that can update and maintain its internal states across execution runs. We will cover that use case in a later tutorial.
Last updated