Package Exports
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (@metamask/network-example-snap) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
@metamask/network-access-example-snap
This snap demonstrates how to use the endowment:network-access permission to
get access to the fetch function from a Snap. It also demonstrates how to use
WebSockets.
Snap manifest
Note: Using
fetchor WebSockets requires theendowment:network-accesspermissions. Refer to the documentation for more information.
Along with other permissions, the manifest of this snap includes the
endowment:network-access permission:
{
"initialPermissions": {
"endowment:network-access": {}
}
}This permission does not require any additional configuration.
Snap usage
This snap exposes an onRpcRequest handler, which supports the following
JSON-RPC methods:
fetch- Fetch a JSON document from the optionalurl, and return the fetched data.startWebSocket- Open a WebSocket connection to a local Ethereum node and subscribe to block updates.stopWebSocket- Close a WebSocket connection, if one exists.getState- Get the state of the Snap, including the block number and whether the WebSocket connection is active.
For more information, you can refer to the end-to-end tests.