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

@acala-network/wallet-v2

v0.0.4-20

Published

## Install

Downloads

1,703

Readme

Wallet

Install

pnpm install @polkadot/api @acala-network/wallet-v2

Types

Token

const token: Token = {
  id: "0x0000",
  symbol: "ACA",
  decimals: 12,
  isNative: true,
  isEvm: false,
  evm: "0x0000000000000000000100000000000000000000",
};
  • id: Token ID used in substrate, can be used to query storage in substrate
  • symbol: Token symbol
  • decimals: Token decimals
  • isNative: Whether the token is native token
  • isEvm: Whether the token is created by EVM
  • evm: The EVM address of the token

Account

const account: Account = {
  address: "5GrwvaEF5zXb26Fz9rcQpDWS57CtERHpNehXCPcNoHGKutQY",
  evm: "0x0000000000000000000100000000000000000000",
  isBound: true,
  isDefaultEvm: true,
  isDefaultSubstrate: false,
};
  • address: Substrate address
  • evm: EVM address
  • isBound: Whether the account has bound EVM address to substrate address
  • isDefaultEvm: Whether the account's EVM address is computed from substrate address
  • isDefaultSubstrate: Whether the account's substrate address is computed from EVM address

Balance

Balance is based on substrate balance data structure.
For EVM token, set locked and reserved to 0, and available equals to free.

const balance: Balance = {
  free: 1000000000000000000000000n,
  locked: 0n,
  reserved: 0n,
  available: 1000000000000000000000000n,
};
  • free: Free balance
  • locked: Locked balance
  • reserved: Reserved balance
  • available: Available balance

Usage

  1. Create a wallet instance
import { Wallet } from "@acala-network/wallet-v2";
import { ApiPromise, WsProvider } from "@polkadot/api";

const api = await ApiPromise.create({
  provider: new WsProvider("wss://acala-rpc.polkadot.io"),
});

await api.isReady;

const wallet = new Wallet({
  api,
  // optional accept a public client, if not passed, the wallet will also create one
  publicClient: createPublicClient({
    chain: acala,
    transport: http(),
  }),
});
  1. Get account
const account = await wallet.getAccount(
  // accepts EVM address too
  "5GrwvaEF5zXb26Fz9rcQpDWS57CtERHpNehXCPcNoHGKutQY",
);

console.log(account.address);
console.log(account.evm);
  1. Get registered tokens
const tokens = await wallet.getRegisteredTokenList();

console.log(JSON.stringify(tokens, null, 2));
  1. Get token by ID or symbol
// accepts token ID, EVM address, or symbol
const token = await wallet.getToken("AUSD");

console.log(token.id);
console.log(token.symbol);
console.log(token.decimals);
  1. Get balance
const balance = await wallet.getBalance(
  // accepts token ID, EVM address, or symbol
  "ACA",
  // accepts substrate address or EVM address
  "5GrwvaEF5zXb26Fz9rcQpDWS57CtERHpNehXCPcNoHGKutQY",
);

console.log(balance);
  1. Watch balance
const unsubscribe = await wallet.watchBalance(
  // accepts token ID, EVM address, or symbol
  "ACA",
  // accepts substrate address or EVM address
  "5GrwvaEF5zXb26Fz9rcQpDWS57CtERHpNehXCPcNoHGKutQY",
  (balance) => {
    console.log(balance);
    unsubscribe();
  },
);