1.8.9 • Published 6 months ago

@svylabs/microcraft-lib v1.8.9

Weekly downloads
-
License
MIT
Repository
github
Last release
6 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

8 months ago

1.8.2

6 months ago

1.4.6

7 months ago

1.8.1

6 months ago

1.8.0

6 months ago

1.6.2

7 months ago

1.4.4

7 months ago

1.6.1

7 months ago

1.4.3

7 months ago

1.6.0

7 months ago

1.4.2

7 months ago

1.4.1

7 months ago

1.4.0

7 months ago

1.7.9

6 months ago

1.7.8

6 months ago

1.7.7

6 months ago

1.7.6

6 months ago

1.7.5

6 months ago

1.7.4

6 months ago

1.1.1

8 months ago

1.1.0

8 months ago

1.7.3

6 months ago

1.7.2

6 months ago

1.7.1

6 months ago

1.7.0

6 months ago

1.5.1

7 months ago

1.1.5

8 months ago

1.5.0

7 months ago

1.3.2

7 months ago

1.1.4

8 months ago

1.3.1

7 months ago

1.1.3

8 months ago

1.3.0

7 months ago

1.1.2

8 months ago

1.8.9

6 months ago

1.8.8

6 months ago

1.8.7

6 months ago

1.8.6

6 months ago

1.8.5

6 months ago

1.4.9

7 months ago

1.8.4

6 months ago

1.4.11

7 months ago

1.4.8

7 months ago

1.8.3

6 months ago

1.4.10

7 months ago

1.4.7

7 months ago

1.4.12

7 months ago

1.0.4

9 months ago

1.0.3

9 months ago

1.0.2

9 months ago