npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@firnprotocol/snap

v1.3.1

Published

Firn Protocol's official MetaMask Snap.

Downloads

10

Readme

Firn Protocol's Snap

Firn's Snap allows websites to securely invoke Firn Protocol on behalf of users.

An end-to-end, open-source working example exhibiting the below methods is available, and hosted, at Tome; see also firnprotocol/tome for the source.

API

Connecting

Connect to the Firn Snap in the standard way; that is:

await provider.request({
  method: "wallet_requestSnaps",
  params: { "npm:@firnprotocol/snap": {} },
});

Initialize

The initialize method prompts the user to "log into" his Firn account, on behalf of his currently logged-in Ethereum account (in practice, this entails signing a special message). As a side effect, it caches the user's secret Firn key in secure, encrypted storage (visible only within the Firn snap, and not to the calling website). If this method is called more than once, then the additional calls will be no-ops.

This method must be called before either of the below methods are. In practice, you may want to call this method immediately after prompting the user to connect the Snap in the first place.

await window.ethereum.request({
  method: "wallet_invokeSnap",
  params: { snapId: "npm:@firnprotocol/snap", request: { method: "initialize" } }
});

This method will either return nothing (upon success) or will throw an error (upon a failure).

Request Balance

The requestBalance method prompts the user to disclose his Firn balance. The RPC method will either return the user's Firn balance—denominated in milliether (!)—as a plain JavaScript number, or will throw an error. Here's an example invocation:

const balance = await window.ethereum.request({ // might throw; will be handled above
  method: "wallet_invokeSnap",
  params: { snapId: "npm:@firnprotocol/snap", request: { method: "requestBalance" } }
});
console.log(`User's Firn balance is ${(balance / 1000).toFixed(3)} ETH.`);

Transact

The transact method prompts the user to anonymously execute a prescribed transaction using his Firn account. It will either return the transactionHash of the resulting successful, mined transaction, or else will throw a descriptive error. Here's an example invocation:

import { encodeFunctionData } from "viem";

const TOME_ABI = [{
  "inputs": [
    {
      "internalType": "string",
      "name": "message",
      "type": "string"
    }
  ],
  "name": "broadcast",
  "outputs": [],
  "stateMutability": "nonpayable",
  "type": "function"
}];
const data = encodeFunctionData({
  abi: TOME_ABI,
  functionName: "broadcast",
  args: ["A test message."],
});
const transaction = {
  to: "0x0D9993a3e3A0e73633c153CCf49A0bD17159A60D", // Tome address on Base
  data, // a bytes-like hex string
  value: 0, // a plain `Number`, denominated in milli-ether
};
const transactionHash = await window.ethereum.request({
  method: "wallet_invokeSnap",
  params: { snapId: defaultSnapOrigin, request: { method: "transact", params: transaction } },
});
console.log(`Transaction successful! Its hash is ${transactionHash}.`);

Further details and usage examples can be found at Tome.