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

@svylabs/microcraft-lib

v1.2.0

Published

create an npm library and test it

Downloads

524

Readme

Microcraft Lib

The Microcraft Lib package allows you to embed a dynamic Web3 UI into your frontend application. It supports flexible UI definition using JSON/JavaScript and integrates with popular browser wallets.

Features

  • Dynamic UI: Define UI elements and actions dynamically using JSON or JavaScript.
  • Wallet Integration:
    • Metamask for Ethereum
    • Keplr Wallet for Cosmos (WIP)
  • Network Integration:
    • Ethereum
    • Cosmos (WIP)

Installation

You can install the package using npm:

npm install microcraft-lib

If there are any peer dependency issues, try installing with:

npm install microcraft-lib --legacy-peer-deps

Usage

Here is an example of how you can set up and use Microcraft Lib:

// Initializing the app JSON
const app = {
  components: [
    {
      "type": "text",
      "label": "Enter ERC20 Address",
      "id": "erc20AddressInput",
      "placement": "input"
    },
    {
      "type": "button",
      "label": "Fetch ERC20 Data",
      "id": "fetchERC20Data",
      "placement": "action",
      "codeRef": "actions/fetch_token_details.js" // you can define a function that can fetch token details here
    },
    {
      "type": "text",
      "label": "Total ERC20 Supply",
      "id": "erc20TotalSupply",
      "placement": "output"
    },
    {
      "type": "text",
      "label": "ERC20 Token Name",
      "id": "erc20Name",
      "placement": "output"
    },
    {
      "type": "text",
      "label": "ERC20 Token Symbol",
      "id": "erc20Symbol",
      "placement": "output"
    },
    {
      "type": "walletDropdown",
      "label": "Select Connected Wallet Address",
      "id": "walletAddress",
      "options": [],
      "placement": "input"
    },
    {
      "type": "text",
      "label": "Or Enter Wallet Address",
      "id": "walletAddressInput",
      "placement": "input"
    },
    {
      "type": "button",
      "label": "Fetch Wallet Data",
      "id": "fetchWalletInfo",
      "placement": "action",
      "codeRef": "actions/fetch_wallet.js"
    },
    {
      "type": "text",
      "label": "User's ERC20 Balance",
      "id": "erc20UserBalance",
      "placement": "output"
    }
  ],
  contracts: [
    {
      "name": "ERC20",
      "address": "0x5f98805A4E8be255a32880FDeC7F6728C6568bA0",
      "template": "ERC20",
      "abi": []
    }
  ],
  network: {
    "type": "ethereum",
    "config": {
      "rpcUrl": "your_rpc_url",
      "chainId": "your_chain_id",
      "exploreUrl": "your_explore_url"
    }
  }
}

// Initial data for app elements(components)
let data = {};

// Callback function to handle data updates
function setDataCallback(newData) {
  data = { ...data, ...newData };
}

// Debugging
const [outputCode, setOutputCode] = useState<Output | string>();

// Rendering the DynamicApp component
<DynamicApp
  components={app.components}
  data={data}
  setData={setDataCallback}
  contracts={app.contracts}
  network={app.network}
  debug={setOutputCode}
/>

Example Explained

  • Components: Defined as an array, each component has a type (e.g., "text", "button", "walletDropdown"), a label, an ID, and a placement that specifies its role (e.g., input, action, output).
  • Contract Details: Includes details like the contract name, address, template, and ABI for smart contract interaction.
  • Network Details: Configures the network type and RPC, chain ID, and explorer URL for connection.

You can render the UI dynamically using the <DynamicApp /> component, which takes in the components, data, contracts, and network details. The app also supports a debug function to monitor output data.


Enjoy building UI for your favorite web3 dapps with Microcraft Lib!