npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@justaname.id/react

v0.3.139

Published

The **JustaName React SDK** makes it easy to integrate Ethereum Name Service (ENS) functionalities, including subname management, and user authentication via ENS into React applications. It simplifies interacting with ENS off-chain operations while ensuri

Downloads

3,897

Readme

JustaName React SDK

The JustaName React SDK makes it easy to integrate Ethereum Name Service (ENS) functionalities, including subname management, and user authentication via ENS into React applications. It simplifies interacting with ENS off-chain operations while ensuring secure and easy integration with your dApps.

Table of Contents


Installation

Install the JustaName React SDK using npm or yarn:

npm install @justaname.id/react

# or

yarn add @justaname.id/react

Usage

Setup with JustaNameProvider

To use the JustaName React SDK, wrap your application with the JustaNameProvider. This component provides all child components access to the JustaName context, enabling seamless interaction with ENS services.

Example: Setup with JustaNameProvider

tsx
'use client';
import { JustaNameProvider } from '@justaname.id/react';
import { configureChains, createClient, WagmiConfig } from 'wagmi';
import { publicProvider } from 'wagmi/providers/public';
import { getDefaultWallets, RainbowKitProvider } from '@rainbow-me/rainbowkit';
import '@rainbow-me/rainbowkit/styles.css';
import { AddSubname } from './AddSubname';

const { wallets } = getDefaultWallets();

const config = getDefaultConfig({
  appName: 'JustaName Console',
  projectId: 'YOUR_PROJECT_ID',
  wallets: [
    ...wallets,
    {
      groupName: 'Other',
      wallets: [argentWallet, trustWallet, ledgerWallet],
    },
  ],
  chains: [mainnet, sepolia],
  ssr: true,
});

const justaNameConfig = {
  networks: [{ chainId: 1, providerUrl: 'https://mainnet.infura.io/v3/YOUR_INFURA_KEY' }],
  ensDomains: [
    { 
      chainId: 1, 
      domain: 'your_ens_domain.eth',
      apiKey: 'your-api-key' // Not recommended for production, use a backend server to protect your API key
    }
  ],
  backendUrl: 'https://your-backend-url.com' // Leave empty for same origin (e.g when using Next.js)
};

export const App = () => {
  return (
    <WagmiConfig client={config}>
      <RainbowKitProvider chains={chains}>
        <JustaNameProvider config={justaNameConfig}>
            <AddSubname />
        </JustaNameProvider>
      </RainbowKitProvider>
    </WagmiConfig>
  );
}

Example: Add a Subname

Below is a complete example of a React component where users can claim a subname using the useAddSubname hook. It also checks subname availability with useIsSubnameAvailable.

tsx
Copy code
import { useAddSubname, useIsSubnameAvailable } from '@justaname.id/react';
import { useState } from 'react';
import { useDebounce } from '@uidotdev/usehooks';
import { ConnectButton } from '@rainbow-me/rainbowkit';
import { useAccount } from 'wagmi';

export const AddSubname = () => {
  const { isConnected } = useAccount();
  const [username, setUsername] = useState<string>('');
  const debouncedUsername = useDebounce(username, 500);
  const { isSubnameAvailable } = useIsSubnameAvailable({ 
    username: debouncedUsername 
  });
  const { addSubname } = useAddSubname();

  return (
    <div>
      <h1>Claim your subdomain</h1>
      <ConnectButton />
      <input
        value={username}
        onChange={(e) => setUsername(e.target.value)}
        placeholder="Enter a subdomain"
      />
      <button
        onClick={() => addSubname({ username })}
        disabled={!isSubnameAvailable || !isConnected || !debouncedUsername}
      >
        Claim
      </button>
    </div>
  );
};

Hooks

The SDK offers various hooks for managing ENS accounts, subnames, and authentication.

Account and ENS Management

  • useAccountEnsNames: Fetch ENS names associated with the user's account.
  • useAddressEnsNames: Fetch ENS names for a given Ethereum address.
  • usePrimaryName: Get the primary ENS name of an address.
  • useAccountInvitations: Get pending invitations for the connected account.
  • useAccountSubnames: Fetch all subnames for the connected account.

Subname Management

  • useIsSubnameAvailable: Check if a subname is available.
  • useAddSubname: Add a new subname off-chain.
  • useAcceptSubname: Accept an invitation for a subname.
  • useRejectSubname: Reject a subname invitation.
  • useRevokeSubname: Revoke an issued subname.
  • useUpdateSubname: Update an ens metadata (off-chain and on-chain).
  • useSearchSubnames: Search for subnames based on given parameters.
  • useSubname: Get the details of a specific subname.
  • useRecords: Fetch records associated with any ENS name.

Authentication

  • useEnsSignIn: Authenticate users with their ENS name.
  • useEnsSignOut: Sign out the connected user.
  • useEnsAvatar: Fetch the avatar of an ENS name.
  • useEnsAuth: Manage authentication state with ENS.

Other Hooks

  • useJustaName: Access the JustaName context directly.
  • useMounted: Check if the component is mounted.
  • useMountedAccount: Get the mounted account details.
  • useOffchainResolvers: Fetch off-chain resolvers.
  • useUpdateChanges: Check for changes in the ENS metadata before updating.
  • useUploadMedia: Upload media for ENS metadata.

Contributing

Contributions are welcome! If you have suggestions or find issues, please open an issue or submit a pull request on the GitHub repository.