@metamask/wasm-example-snap

2.1.3 • Public • Published

@metamask/wasm-example-snap

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.

Snap manifest

Note: Using WebAssembly requires the endowment: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.

Snap usage

This snap exposes an onRpcRequest handler, which supports the following JSON-RPC methods:

  • fibonacci - Use the WebAssembly global to execute a WebAssembly module that calculates the Fibonacci sequence. The n parameter is used to specify the number of iterations to perform.

For more information, you can refer to the end-to-end tests.

Readme

Keywords

none

Package Sidebar

Install

npm i @metamask/wasm-example-snap

Weekly Downloads

6,594

Version

2.1.3

License

(MIT-0 OR Apache-2.0)

Unpacked Size

65.9 kB

Total Files

7

Last publish

Collaborators

  • mcmire
  • nicholasellul
  • lgbot
  • naugtur
  • ritave
  • danfinlay
  • kumavis
  • rekmarks
  • metamaskbot
  • gudahtt
  • brad.decker
  • sethkfman