Skip to content

dappkit react implementation to help FE developers

Notifications You must be signed in to change notification settings

Ardandxb/dappkit-react

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

62 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

@taikai/dappkit-react

$ npm install -s @taikai/dappkit-react

Usage

Available hooks

import {useDappkit,} from "./use-dappkit";
// ... your component

// share this connection with your other dappkit classes
const {connection} = useDappkit();

Wallet selector

import {WalletSelector, ConnectorsNames} from "@layerx-labs/dappkit-react";

const [showModal, setShowModal] = useState(false);
// .. your component
<WalletSelector availableWallets={[ConnectorsNames.Metamask, ConnectorsNames.Coinbase]} />

Get notified of chain-id and address changes,

import {useDappkit} from "@taikai/dappkit-react";

const {address, chainId} = useDappkit();

useEffect(() => {
  console.log(`Info`, address, chainId);
}, [address, chainId])

Supported Wallets

wallet ConnectorsNames
Coinbase Coinbase
Metamask Metamask
Safe GnosisSafe
Wallet Connect v2 WalletConnect

Sharing your connection with other dappkit classes

import {ERC20} from "@taikai/dappkit";
import {useDappkit} from "@taikai/dappkit-react";
import {useEffect, useState} from "react";

function useERC20(tokenAddress: string) {
  const [token, setToken] = useState<ERC20 | null>(null);

  const {connection} = useDappkit();

  useEffect(() => {
    if (!connection) {
      setToken(null);
      return;
    }

    setToken(new ERC20(connection, tokenAddress));
  }, [connection]);

  function transferTokenAmount(amount: number, address: string) {
    if (!token)
      return;

    return token.transferTokenAmount(address, amount);
  }
  
  return {token, transferTokenAmount};
}

About

dappkit react implementation to help FE developers

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • TypeScript 100.0%