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

darwinia.js.testdontuse

v0.0.14

Published

A library to help fetch darwinia storages and dispatch calls

Downloads

23

Readme

darwinia.js

Version >= ^3.0.2 for Darwinia 2.0. Version < 3.0.0 is for Darwinia 1.0.

A library to help

  1. fetch internal substrate storages, and
  2. dispatch calls
  3. Easy-to-use derived functions(Derived API List) which are build from 1 and 2.

Nodejs

npm install darwinia.js@^3.0.2

Browser

Collators Amount: <span id="result"></span>

<script type="module">
  import { ethers } from "https://esm.sh/[email protected]";
  import { clientBuilder } from "https://esm.sh/[email protected]";
  const provider = new ethers.providers.Web3Provider(window.ethereum);
  const client = clientBuilder.buildPangolinClient(provider);

  // storage
  const result = await client.storages.darwiniaStaking.collatorCount();
  const resultEl = document.getElementById("result");
  resultEl.innerHTML = result;

  // call
  await window.ethereum.request({ method: "eth_requestAccounts" });
  const signer = provider.getSigner();
  const from = await signer.getAddress();
  await client.calls.system.remarkWithEvent(signer, "0x12345678");
</script>

Try it in jsfiddle:

https://jsfiddle.net/wuminzhe/gwp4ovz1/4/

Browser - viem

Collators Amount: <span id="result"></span>

<script type="module">
  import {
    ethers
  } from "https://esm.sh/[email protected]";
  import {
    custom,
    createPublicClient,
    createWalletClient
  } from "https://esm.sh/[email protected]"
  import {
    clientBuilder,
    publicClientToProvider,
    walletClientToSigner
  } from "https://esm.sh/[email protected]";
  
  ///////////////////////
  // storage
  ///////////////////////
  // convert viem public client to ethers provider
  const publicClient = createPublicClient({
    transport: custom(window.ethereum)
  })
  const provider = await publicClientToProvider(publicClient);
	//
  const client = clientBuilder.buildPangolinClient(provider);
  const result = await client.storages.darwiniaStaking.collatorCount();
  const resultEl = document.getElementById("result");
  resultEl.innerHTML = result; 
  
  ///////////////////////
  // call
  ///////////////////////
  // convert viem wallet client to ethers provider & signer
	const walletClient = createWalletClient({
    transport: custom(window.ethereum)
  })
  const [provider2, signer] = walletClientToSigner(walletClient)
  //
  const pangolin = clientBuilder.buildPangolinClient(provider2);
  await pangolin.calls.session.setKeys(
    signer, {
      aura: "0xd43593c715fdd31c61141abd04a99fd6822c8558854ccde39a5684e7a56da27d",
    }, // keys
    "0x" // proof
  );
</script>

https://jsfiddle.net/wuminzhe/amwL4jpk/1/

Usage

fetch storage

The returns of this lib's functions are all json string or null.

import { ethers } from "ethers";
import { clientBuilder } from "darwinia.js";

async function main(): Promise<void> {
  const provider = new ethers.providers.JsonRpcProvider(
    "https://pangolin-rpc.darwinia.network"
  );
  // or
  // const provider = new ethers.providers.Web3Provider(window.ethereum);

  const pangolin = clientBuilder.buildPangolinClient(provider);

  let result = await pangolin.storages.system.account(
    "0x794BF0B66926D84CB735283D849f454A2A8d9a44"
  );
  console.log(`${result}\n`);
}

main();

dispatch call

import { ethers } from "ethers";
import { clientBuilder } from "darwinia.js";

async function main(): Promise<void> {
  const provider = new ethers.providers.Web3Provider(window.ethereum);

  const signer = provider.getSigner();

  const pangolin = clientBuilder.buildPangolinClient(provider);

  await pangolin.calls.session.setKeys(
    signer,
    {
      aura: "0xd43593c715fdd31c61141abd04a99fd6822c8558854ccde39a5684e7a56da27d",
    }, // keys
    "0x" // proof
  );
}

main();

dispatch multiple calls in a single transaction

import { ethers } from "ethers";
import { clientBuilder } from "darwinia.js";

async function main(): Promise<void> {
  const provider = new ethers.providers.Web3Provider(window.ethereum);

  const signer = provider.getSigner();

  const pangolin = clientBuilder.buildPangolinClient(provider);

  // prepare calls
  const setKeysCall = pangolin.calls.session.buildSetKeysCall(
    // keys
    {
      aura: "0xd43593c715fdd31c61141abd04a99fd6822c8558854ccde39a5684e7a56da27d",
    },
    // proof
    "px"
  );

  const collectCall = pangolin.calls.staking.buildCollectCall(120000000);

  // dispatch
  await pangolin.calls.utility.batchAll(signer, [setKeysCall, collectCall]);
}

main();

dispatch call with encoded input

import { ethers } from "ethers";
import { clientBuilder } from "darwinia.js";

async function main(): Promise<void> {
  const provider = new ethers.providers.Web3Provider(window.ethereum);

  const signer = provider.getSigner();

  const pangolin = clientBuilder.buildPangolinClient(provider);

  // call ended with `D` is the version that accept params encoded in scale codec
  await pangolin.calls.session.setKeysH(
    signer,
    "0xd43593c715fdd31c61141abd04a99fd6822c8558854ccde39a5684e7a56da27d00" // encoded (keys, proof)
  );
}

main();

More examples in examples

Derived API List

nominateAndStake

Nominate a collator and stake tokens to the collator.

setSessionKeysAndCommission

Set session keys and commission percetage. Example

trackSystemEvents

Track specified events. Example

getSystemEvents

Get the latest events. You can use this function with provider.on('block', callback) to implement the tracking functionality like trackSystemEvents. Example

See src/derived.ts.

Update Chains Metadata

npm run gen