You're Invited:Meet the Socket Team at BlackHat and DEF CON in Las Vegas, Aug 7-8.RSVP
Socket
Socket
Sign inDemoInstall

wagmi

Package Overview
Dependencies
Maintainers
2
Versions
602
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

wagmi

React Hooks for Ethereum


Version published
Weekly downloads
182K
increased by2.61%
Maintainers
2
Created
Weekly downloads
 

Package description

What is wagmi?

The wagmi npm package is a collection of React Hooks for Ethereum, designed to make it easier to work with Ethereum-based applications. It provides a set of tools to manage wallet connections, interact with smart contracts, and handle blockchain data in a React environment.

What are wagmi's main functionalities?

Wallet Connection

This feature allows users to connect and disconnect their Ethereum wallets. It provides hooks to manage the wallet connection state and handle different wallet connectors.

import { useAccount, useConnect, useDisconnect } from 'wagmi';

function Wallet() {
  const { address, isConnected } = useAccount();
  const { connect, connectors } = useConnect();
  const { disconnect } = useDisconnect();

  return (
    <div>
      {isConnected ? (
        <div>
          <p>Connected to {address}</p>
          <button onClick={() => disconnect()}>Disconnect</button>
        </div>
      ) : (
        <div>
          {connectors.map((connector) => (
            <button key={connector.id} onClick={() => connect(connector)}>
              Connect with {connector.name}
            </button>
          ))}
        </div>
      )}
    </div>
  );
}

Smart Contract Interaction

This feature allows users to read from and write to smart contracts. It provides hooks to interact with smart contract functions and manage the state of these interactions.

import { useContractRead, useContractWrite } from 'wagmi';

const contractConfig = {
  addressOrName: '0xContractAddress',
  contractInterface: ContractABI,
};

function ContractInteraction() {
  const { data: balance } = useContractRead({ ...contractConfig, functionName: 'balanceOf', args: ['0xAddress'] });
  const { write: transfer } = useContractWrite({ ...contractConfig, functionName: 'transfer', args: ['0xRecipient', 100] });

  return (
    <div>
      <p>Balance: {balance?.toString()}</p>
      <button onClick={() => transfer()}>Transfer</button>
    </div>
  );
}

Blockchain Data

This feature allows users to access blockchain data such as the current block number and the connected network. It provides hooks to fetch and display this data in a React component.

import { useBlockNumber, useNetwork } from 'wagmi';

function BlockchainData() {
  const { data: blockNumber } = useBlockNumber();
  const { chain } = useNetwork();

  return (
    <div>
      <p>Current Block Number: {blockNumber}</p>
      <p>Connected Network: {chain?.name}</p>
    </div>
  );
}

Other packages similar to wagmi

Readme

Source

wagmi

Documentation

For full documentation and examples, visit wagmi.sh.

Installation

Install wagmi and its viem peer dependency.

npm install wagmi viem

Community

Check out the following places for more wagmi-related content:

Support

If you find wagmi useful, please consider supporting development. Thank you 🙏

Keywords

FAQs

Package last updated on 31 Aug 2023

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc