This snap demonstrates how to use the endowment:webassembly
permission to get
access to the WebAssembly
global from a snap, and use it to execute a
WebAssembly module.
This example consists of the usual snap files, as well as a program
directory
that contains the WebAssembly module. This is an
AssemblyScript module that exports a
fibonacci
function, which calculates the Fibonacci sequence.
For this example, we're using the AssemblyScript compiler to compile the WebAssembly module, but you can use any other language that compiles to WebAssembly.
Note: Using
WebAssembly
requires theendowment:webassembly
permissions. Refer to the documentation for more information.
Along with other permissions, the manifest of this snap includes the
endowment:webassembly
permission:
{
"initialPermissions": {
"endowment:webassembly": {}
}
}
This permission does not require any additional configuration.
This snap exposes an onRpcRequest
handler, which supports the following
JSON-RPC methods:
-
fibonacci
- Use theWebAssembly
global to execute a WebAssembly module that calculates the Fibonacci sequence. Then
parameter is used to specify the number of iterations to perform.
For more information, you can refer to the end-to-end tests.