1.8.9 • Published 10 months ago

@svylabs/microcraft-lib v1.8.9

Weekly downloads
-
License
MIT
Repository
github
Last release
10 months ago

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!

1.2.0

11 months ago

1.8.2

10 months ago

1.4.6

11 months ago

1.8.1

10 months ago

1.8.0

10 months ago

1.6.2

10 months ago

1.4.4

11 months ago

1.6.1

10 months ago

1.4.3

11 months ago

1.6.0

10 months ago

1.4.2

11 months ago

1.4.1

11 months ago

1.4.0

11 months ago

1.7.9

10 months ago

1.7.8

10 months ago

1.7.7

10 months ago

1.7.6

10 months ago

1.7.5

10 months ago

1.7.4

10 months ago

1.1.1

12 months ago

1.1.0

12 months ago

1.7.3

10 months ago

1.7.2

10 months ago

1.7.1

10 months ago

1.7.0

10 months ago

1.5.1

10 months ago

1.1.5

12 months ago

1.5.0

10 months ago

1.3.2

11 months ago

1.1.4

12 months ago

1.3.1

11 months ago

1.1.3

12 months ago

1.3.0

11 months ago

1.1.2

12 months ago

1.8.9

10 months ago

1.8.8

10 months ago

1.8.7

10 months ago

1.8.6

10 months ago

1.8.5

10 months ago

1.4.9

11 months ago

1.8.4

10 months ago

1.4.11

10 months ago

1.4.8

11 months ago

1.8.3

10 months ago

1.4.10

10 months ago

1.4.7

11 months ago

1.4.12

10 months ago

1.0.4

12 months ago

1.0.3

1 year ago

1.0.2

1 year ago