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

usechain

v1.1.2

Published

An npm package to connect with web3 wallets and deploy smart contracts

Downloads

10

Readme

useChain Hook

The useChain hook is a custom React hook designed to simplify the process of connecting to a blockchain network, such as Ethereum, and interacting with smart contracts. It provides easy access to the provider, signer, and contract objects, allowing developers to quickly integrate blockchain functionality into their React applications.

Installation

To use the useChain hook in your React project, follow these simple steps:

  1. Install the package via npm:
npm i usechain
  1. Import the hook into your React components:
import useChain from 'usechain';

Usage

Here's a basic example demonstrating how to use the useChain hook:

import React from 'react';
import useChain from 'usechain';
import abi from './Abi.json';

const contractAddress = "0xa1D4f2Cd672ED6EcE465FE85f33DB9D48aC338ab";
const contractABI = abi.abi;

const ExampleComponent = () => {
  const { state, account, login } = useChain(contractAddress, contractABI);

  const handleConnectWallet = async () => {
    await login();
  };

  return (
    <div>
      <button onClick={handleConnectWallet}>Connect Wallet</button>
      <p>Account: {account}</p>
      {console.log("Wallet connected!")}
      {console.log("Provider:", state.provider)}
      {console.log("Signer:", state.signer)}
      {console.log("Contract:", state.contract)}
      {console.log("Account:", account)}
    </div>
  );
};

export default ExampleComponent;

In this example, we import the useChain hook and call it with the contract address and ABI. The hook returns the state object containing the provider, signer, and contract objects, as well as the current user account. We then use this data to connect the wallet and interact with the blockchain.

Benefits

Simplified Blockchain Integration:

With the useChain hook, developers can easily connect their React applications to blockchain networks and interact with smart contracts without the need for complex setup or configuration.

Time-Saving Development:

By abstracting away the intricacies of blockchain development, the useChain hook allows developers to focus on building their applications rather than dealing with low-level blockchain interactions.

Flexibility and Customization:

The useChain hook provides flexibility to developers by allowing them to customize their blockchain integration according to their specific requirements. Developers can easily access the provider, signer, and contract objects and use them as needed.

Conclusion

The useChain hook offers a simple and efficient solution for integrating blockchain functionality into React applications. By providing easy access to essential blockchain components, it empowers developers to build decentralized applications with ease. Try it out in your next project and experience the benefits of streamlined blockchain integration!