Git Product home page Git Product logo

use-inkathon's Introduction

useInkathon โ€“ React Hooks for Substrate & ink!

Typescript React Scio Labs

Typesafe React Hooks abstracting functionality by polkadot.js for working with Substrate-based networks and ink! Smart Contracts.

By Dennis Zoma & Scio Labs ๐Ÿช„

Join our Telegram Group ๐Ÿ’ฌ

Live in Action ๐Ÿšข

See this library live & in action within our ink!athon dApp boilerplate!

Disclaimer ๐Ÿšจ

This package is under development and not ready for production use yet. See the open issues.

Documentation ๐Ÿ“ƒ

https://scio-labs.github.io/use-inkathon/

Features โœจ

  • Wrapper for polkadot.js (wallet connection, account switching, etc.) that saves you 100+ lines of code
  • Easy-to-use React Hooks:
    • useInkathon โ€“ Main Hook responsible for connection, account management, etc.
    • useBalance โ€“ Fetches the native token balance of a given wallet
    • useContract โ€“ Instantiates a polkadot.js ContractPromise for given abi & address
    • useRegisteredContract โ€“ Instantiates a contract with only one single identifier (read more about the contract registry concept below)
  • Contract Interaction Helper Functions: Call mutating (contractTx) and non-mutating (contractQuery) contract functions with automatic upfront gas estimation.
  • Constants/Definitions for Substrate-based chains & wallets
  • Makes polkadot.js compatible with server-side environments (i.e. Next.js)
  • Works multichain with live & dynamic chain-switching out-of-the-box

Getting Started

Install the package from the npm registry:

npm install @scio-labs/use-inkathon

Use it:

  1. Wrap it around your app or parent component:
// import { development, UseInkathonProvider } from '@scio-labs/use-inkathon'

<UseInkathonProvider appName="ink!athon" defaultChain={development}>
  <Component {...pageProps} />
</UseInkathonProvider>
  1. Use the useInkathon hook everywhere underneath to access all the exposed properties below.
import { useInkathon } from '@scio-labs/use-inkathon'

const { api, connect, activeChain, activeAccount, โ€ฆ } = useInkathon()

The Contract Registry Concept ๐ŸŒŸ

Define metadata once and create ContractPromises everywhere with just a single identifier:

const { contract } = useRegisteredContract('greeter')

This works by defining typesafe contract metadata objects (example) which are passed to the UseInkathonProvider provider (example).

import { alephzeroTestnet, SubstrateDeployment } from '@scio-labs/use-inkathon'

export const getDeployments = async (): Promise<SubstrateDeployment[]> => {
  return [
    {
      contractId: 'greeter',
      networkId: alephzeroTestnet.network,
      abi: await import(
        `@inkathon/contracts/greeter/deployments/metadata.json`
      ),
      address: '5HPwzKmJ6wgs18BEcLdH5P3mULnfnowvRzBtFcgQcwTLVwFc',
    },
  ]
}
<UseInkathonProvider
  appName="ink!athon"
  defaultChain={alephzeroTestnet}
  deployments={getDeployments()}
>
  <Component {...pageProps} />
</UseInkathonProvider>

Package Development

# Install pnpm (https://pnpm.io/)
npm i -g pnpm

# Install dependencies
pnpm i

# Start tsup in development mode (watching)
pnpm dev

# Build the package and generated docs
pnpm build

Heads up, when locally importing a development version of this package into other projects: Unfortunately, this does not yet work w/o generating a local packages .tgz-build every time. Otherwise, polkadot.js thinks it's installed twice with two different versions.

# 1. [THIS PACKAGE] Generate a .tgz package of the build
pnpm tsup && pnpm pack

# 2. [OTHER PROJECT] Add it as a dependency in your other project
#    NOTE: This results in a package.json entry like: `"@scio-labs/use-inkathon": "file:../scio-labs-use-inkathon-0.0.1-alpha.X.tgz"`
pnpm add ../use-inkathon/scio-labs-use-inkathon-0.0.1-alpha.X.tgz
# 3. [OTHER PROJECT] Subsequent updates can be done via
#    TIP: Add `--offline` flag for faster package updates
pnpm update @scio-labs/use-inkathon

Package Release

GITHUB_TOKEN=โ€ฆ pnpm release-it

use-inkathon's People

Contributors

wottpal avatar maximiliandietel03 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.