Static files
You can handle static files in your Snap bundle using the
snap_getFile
API method.
This is useful to load Wasm modules, ZK circuits, or any other files that must be lazily loaded.
Steps
1. Specify static files in the Snap's manifest file
Specify static files as an array in the source.files
field of your Snap's
manifest file.
File paths are relative to the Snap package root, that is, one level above the src
directory.
For example:
snap.manifest.json
"source": {
"shasum": "xxx",
"location": {
// ...
},
"files": [
"./files/myfile.bin"
]
}
2. Load static files using snap_getFile
In your Snap code, load static files using snap_getFile
.
This method returns a string in the encoding specified, with a default of Base64 if no encoding is specified.
For example:
index.js
const contents = await snap.request({
method: "snap_getFile",
params: {
path: "./files/myfile.bin",
encoding: "hex",
},
})
// "0x..."
console.log(contents)
Example
See the @metamask/get-file-example-snap
package for a full example of handling static files.