5 releases

0.1.4 Oct 17, 2023
0.1.3 Oct 17, 2023
0.1.2 Oct 17, 2023
0.1.1 Oct 13, 2023
0.1.0 Oct 13, 2023

#2995 in Magic Beans

Download history 6/week @ 2023-11-10 6/week @ 2023-11-17 11/week @ 2023-11-24 17/week @ 2023-12-01 5/week @ 2023-12-15 11/week @ 2023-12-22 5/week @ 2023-12-29 5/week @ 2024-01-26 5/week @ 2024-02-02 7/week @ 2024-02-09 77/week @ 2024-02-16

94 downloads per month

MIT license

12KB
153 lines

RuSnap

Build Metamask Snap use Rust.

Features

  • Snap basic function.
    • Manage keys
    • Dialog and Notification
    • Random
    • Store Data
    • Network Access (WIP)
    • Ethereum Provider (WIP)
  • RPC Handle
  • Keyring API (TODO)

Example

https://github.com/tiannian/rusnap-example

Install and Usage

Install cargo-rusnap.

cargo install rusnap

Dependencies

Please install these dependencies.

  • wasm-pack
  • npm (yarn or pnpm)

Create Snap

cargo rusnap new <pkg-name>

Build Snap

# Build dev mode in default
cargo rusnap build

# Build release mode
cargo rusnap build --release

Start Snap

cargo rusnap start

Snap

Install Snap in Metamask

Then you can load snap in metamask.

Execute these js statement in broswer devtool:

window.ethereum.request({
  method: "wallet_requestSnaps",
  params: { "local:http://localhost:8080": {} },
});

Or use Metamask Snap Debug Tool.

Call Snap

Execute these js statement in broswer devtool:

window.ethereum.request({
  method: "wallet_invokeSnap",
  params: {
    snapId: "local:http://localhost:8080",
    request: {
      method: "hello",
    },
  },
});

Publish Snap

TODO

Reference

Basic Function

Basic function of Snap: docs.rs

Random

Use OsRng in rand_core or other random crate based on getrandom.

Please add getrandom with js feature.

getrandom = { version = "0.2.10", features = ["js"] }

Web3 SDK

Use rusnap-ethers and ethers.

Note: rusnap-ethers don't re-export into rusnap crate, please add this crate independently.

Dependencies

~22–39MB
~719K SLoC