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

@xiti/terpsnapper

v0.1.1

Published

A helper package with utilities to interact with the Cosmos Extension for MetaMask.

Downloads

2

Readme

Provider Library for Cosmos Extension for Metamask

Snapper is a utility library for interacting with the official Cosmos Extension for Metamask.

Global Provider (Drop In Replacement for window.keplr)

Add the provider as a global object within your dApp.

import { CosmosSnap } from "@xiti/terpsnapper";
window.cosmos = new CosmosSnap();

const memo = "Hello from Metamask!";

let offlineSigner = await window.cosmos.getOfflineSigner("morocco-1");

let wallet = await window.cosmos.getAccount("morocco-1");

// Create a send token message
const msg = {
    typeUrl: "/cosmos.bank.v1beta1.MsgSend",
    value: {
    fromAddress: wallet.address,
    toAddress: "cosmos123456789",
    amount: [
        {
        denom: "uatom",
        amount: "10000",
        },
    ],
    },
};

// Create fee
const fee = {
    amount: [],
    gas: "200000",
};

const signingClient = await SigningStargateClient.connectWithSigner(
    "https://rpc-cosmoshub.whispernode.com:443",
    offlineSigner
);

const result = await signingClient.sign(wallet.address, [msg], fee, memo);

Use in development mode. Note: You must run the snap locally for this to run properly.

window.cosmos.changeSnapId("local:http://localhost:8080");

Structure of the provider.

export interface SnapProvider {
  experimentalSuggestChain(chainInfo: ChainInfo): Promise<void>;
  signAmino(
    chainId: string,
    signer: string,
    signDoc: StdSignDoc,
  ): Promise<AminoSignResponse>;
  signDirect(
    chainId: string,
    signer: string,
    signDoc: {
      /** SignDoc bodyBytes */
      bodyBytes?: Uint8Array | null;

      /** SignDoc authInfoBytes */
      authInfoBytes?: Uint8Array | null;

      /** SignDoc chainId */
      chainId?: string | null;

      /** SignDoc accountNumber */
      accountNumber?: Long | null;
    },
  ): Promise<DirectSignResponse>;
  sendTx(
    chainId: string,
    tx: Uint8Array,
  ): Promise<DeliverTxResponse>;
  getOfflineSigner(chainId: string): Promise<OfflineAminoSigner & OfflineDirectSigner>;
  enabled(): Promise<boolean>;
  install(): Promise<void>;
  getChains(): Promise<Chain[]>;
  deleteChain(chain_id: string): Promise<void>;
  signAndBroadcast(chain_id: string, msgs: Msg[], fees: Fees): Promise<DeliverTxResponse>;
  sign(chain_id: string, msgs: Msg[], fees: Fees): Promise<Int8Array>;
  addAddressToBook(chain_id: string, address: string, name: string): Promise<void>;
  getAddressBook(): Promise<Address[]>;
  deleteAddressFromBook(address: string): Promise<void>;
  getBech32Addresses(): Promise<CosmosAddress[]>;
  getBech32Address(chain_id: string): Promise<CosmosAddress>;
  getAccount(chain_id: string): Promise<AccountData>;
  changeSnapId(snap_id: string): void;
}

Direct Interaction Functions

You can interact with the snap directly to with these functions although we highly suggest using the provider through the window as it is a drop in replacement for other Cosmos wallets.

Check If Installed

import { isSnapInstalled } from '@xiti/terpsnapper';
let result: boolean = await isSnapInstalled();

Check If Initialized

import { isSnapInitialized } from '@xiti/terpsnapper';
let result: boolean = await isSnapInitialized();

Install The Cosmos Extension.

import { installSnap } from '@xiti/terpsnapper';
await installSnap();

Suggest Chain.

Use the format like here in the chain registry. The more info the better.

import { suggestChain } from '@xiti/terpsnapper';
let chain: Chain = {};
await suggestChain(chain);

Get Chains.

Gets all the chains that are in state within the snap.

import { getChains } from '@xiti/terpsnapper';
let chains: []Chain = await getChains();

Delete Chain.

Delete a chain from wallet state.

import { deleteChain } from '@xiti/terpsnapper';
await deleteChain("morocco-1");

Sign & Broadcast.

Sign and broadcast a transaction. Note, you can use our production grade infrastructure (RPCs) to broadcast transactions using this function.

import { signAndBroadcast } from '@xiti/terpsnapper';
import { DeliverTxResponse } from "@cosmjs/stargate";

const msgs = [
    {
        typeUrl: "/cosmos.bank.v1beta1.MsgSend",
        value: {
            fromAddress: senderAddress,
            toAddress: recipientAddress,
            amount: [{
                denom: "uatom",
                amount: "500000"
            }],
        },
    }
];
const fees = {
    amount: [{
        denom: "uatom",
        amount: "500"
    }],
    gas: "200000"
};
let txResult: DeliverTxResponse = await signAndBroadcast("morocco-1", msgs, fees);

Sign Transaction.

Just sign a transaction and return it. Note, this does not use our production grade infrastructure. You must use your own to broadcast the transaction.

import { sign } from '@xiti/terpsnapper';
import { DeliverTxResponse } from "@cosmjs/stargate";

const msgs = [
    {
        typeUrl: "/cosmos.bank.v1beta1.MsgSend",
        value: {
            fromAddress: senderAddress,
            toAddress: recipientAddress,
            amount: [{
                denom: "uatom",
                amount: "500000"
            }],
        },
    }
];
const fees = {
    amount: [{
        denom: "uatom",
        amount: "500"
    }],
    gas: "200000"
};
let txResult: DeliverTxResponse = await sign("morocco-1", msgs, fees);

Add Address to Address Book.

import { addAddressToBook } from '@xiti/terpsnapper';
await addAddressToBook("morocco-1", "cosmos123456789", "John Doe");

Get Address Book

import { getAddressBook } from '@xiti/terpsnapper';
let book: Address[] = await getAddressBook();

Delete Address from Address Book

import { deleteAddressFromBook } from '@xiti/terpsnapper';
await deleteAddressFromBook("cosmos123456789");

Get All Bech32 Addresses

Gets all the Bech32 addresses for all chains in state. Note, this is an expensively heavy operation so use wisely.

import { getBech32Addresses } from '@xiti/terpsnapper';
let allAddresses: CosmosAddress[] = await getBech32Addresses();

Get All Bech32 Addresses

Gets a Bech32 address for a chain.

import { getBech32Addresses } from '@xiti/terpsnapper';
let address: CosmosAddress = await getBech32Address("morocco-1");