@vechain.energy/dapp-kit-hooks
TypeScript icon, indicating that this package has built-in type declarations

1.2.1 • Public • Published
  • A collection of simple helpers to simplify interaction with Vechain.
  • The naming lookup is handled with vet.domains and supported for MainNet only.
  • Requires a correctly set up dapp-kit-react.
yarn add @vechain.energy/dapp-kit-hooks

Hooks

useWalletName(address)

import { useWallet, useWalletModal } from "@vechain/dapp-kit-react";
import { useWalletName } from "@vechain.energy/dapp-kit-hooks";

export default function UserAddress() {
  const { account, disconnect } = useWallet();
  const walletModal = useWalletModal();
  const { name } = useWalletName(account);

  if (!account) {
    return (
      <Button
        className={className}
        onClick={() => void walletModal.open()}
        variant={variant}
      >
        Connect
      </Button>
    );
  }

  if (name) {
    return <span>{name}</span>;
  }

  return (
    <span>
      {account.slice(0, 6)}...{account.slice(-4)}
    </span>
  );
}

Helper Functions

getAddress(name, connex)

  • Helper to always get an address returned, suited for sending integrations.
  • Returns given address or a getRecord() call.
import { useConnex } from "@vechain/dapp-kit-react"
import { getAddress } from "@vechain.energy/dapp-kit-hooks";

// ..
const connex = useConnex()

// ..

// always get an address
await getAddress("0x981ebf8F1F98465F93fd0208a0b5e531DdC37815", connex) 
await getAddress("hello.vet", connex) 

getRecord(name, connex)

  • Lookup the address record for a name manually.
  • Returns address or throws if no record is found
import { useConnex } from "@vechain/dapp-kit-react"
import { getRecord } from "@vechain.energy/dapp-kit-hooks";

// ..
const connex = useConnex()

// ..

// get the address for a .vet name
await getRecord("hello.vet", connex) 

getName(name, connex)

  • Lookup the primary name for an address.
  • Returns name or empty string.
import { useConnex } from "@vechain/dapp-kit-react"
import { getName } from "@vechain.energy/dapp-kit-hooks";

// ..
const connex = useConnex()

// ..

// get the primary name for an address
await getName("0x981ebf8F1F98465F93fd0208a0b5e531DdC37815", connex) 

Readme

Keywords

Package Sidebar

Install

npm i @vechain.energy/dapp-kit-hooks

Weekly Downloads

11

Version

1.2.1

License

MIT

Unpacked Size

498 kB

Total Files

17

Last publish

Collaborators

  • favo