Quiver

website·Indexed 29 days ago

https://raid-guild.github.io/quiver

A collection of React hooks and components designed to simplify the development of frontends for Ethereum dApps. It provides utilities for wallet connection, ENS resolution, contract interaction via useContract and useReadContract, and token balance tracking, with integrations for Gnosis Safe and web3modal.

Tokens
13.3K
Snippets
79
Records
114
Agent score
71%

What's inside Quiver

  1. Overview of Quiver for Ethereum dApp development

    Quiver is a collection of React hooks and components designed to simplify the development of Ethereum dApp frontends. It aims to reduce integration time by providing built-in support for common web3 tasks, including wallet connections via Web3Modal and Ethereum functionality powered by the ethers package. It provides full TypeScript support and integrates with TypeChain for typed contracts.
  2. Overview of Quiver for Ethereum dApp development

    Quiver is a collection of React hooks and components designed to simplify the development of Ethereum dApp frontends. It is built on top of the ethers package for Ethereum functionality and integrates Web3Modal for wallet connectivity. It provides full TypeScript support, including typed contracts via TypeChain.
  3. Switch blockchain networks using useWallet

    The useWallet hook provides a switchNetwork method to programmatically change the user's connected network. This is particularly useful for applications supporting multiple networks where defaultChainId is not provided (as providing a defaultChainId typically enables auto-switching).

    Preconditions for switching networks:

    1. The user must have MetaMask installed.
    2. The target network must already be configured in the user's list of supported networks in their wallet.
    const { switchNetwork } = useWallet();
    
    return (
      <>
        <button onClick={() => switchNetwork("0x1")}>Switch to Mainnet</button>
        <button onClick={() => switchNetwork("0x4")}>Switch to Rinkeby</button>
      </>
    );
  4. Fetch token prices with useCGPrice

    The useCGPrice hook retrieves the current price of a token from CoinGecko. By default, it returns the value in USD. You can specify a tokenId (the CoinGecko ID for the token) and optionally a vsCurrency to get the price in a different currency.
    const { price: ufoPrice } = useCGPrice({ tokenId: "ufo-gaming" });
  5. Integrate Quiver with Gnosis Safe Apps

    Quiver integrates with Gnosis Safe Apps via the safe-apps-web3modal wrapper. To enable this integration, add a manifest.json file to the root of your project. This manifest defines the app's identity, icons, and display settings within the Safe ecosystem.
    {
      "short_name": "Safe App",
      "name": "Gnosis Safe App Starter",
      "description": "Describe your Safe App here",
      "iconPath": "logo.svg",
      "icons": [
        {
          "src": "favicon.ico",
          "sizes": "64x64 32x32 24x24 16x16",
          "type": "image/x-icon"
        },
        {
          "src": "logo192.png",
          "type": "image/png",
          "sizes": "192x192"
        },
        {
          "src": "logo512.png",
          "type": "image/png",
          "sizes": "512x512"
        }
      ],
      "start_url": ".",
      "display": "standalone",
      "theme_color": "#000000",
      "background_color": "#ffffff"
    }
  6. Write to a contract using useWriteContract

    The useWriteContract hook is used to execute public write functions on a smart contract. It requires the contract object, the function name, and an options object to handle the transaction lifecycle. The hook returns a mutate method that triggers the transaction. Arguments for the contract function can be passed directly to the mutate method when called.
    const { mutate: harvestPlasma } = useWriteContract(
      stakingContract,
      "withdrawReward",
      {
        onConfirmation: () => toast.success("Transaction Confirmed"),
        onError: (error) => toast.error(error?.message),
        onResponse: () => toast.success("Waiting for transaction..."),
      }
    );
    
    // Triggering the write
    const claimPlasma = async () => {
      try {
        await harvestPlasma();
      } catch (error) {
        console.error(error);
      }
    };
  7. Integrate Quiver with Gnosis Safe Apps

    Quiver integrates with Gnosis Safe Apps via the safe-apps-web3modal wrapper around web3modal. To enable this integration, add a manifest.json file to the root of your project. This file defines the app's identity, icons, and display settings within the Safe ecosystem.
    {
      "short_name": "Safe App",
      "name": "Gnosis Safe App Starter",
      "description": "Describe your Safe App here",
      "iconPath": "logo.svg",
      "icons": [
        {
          "src": "favicon.ico",
          "sizes": "64x64 32x32 24x24 16x16",
          "type": "image/x-icon"
        },
        {
          "src": "logo192.png",
          "type": "image/png",
          "sizes": "192x192"
        },
        {
          "src": "logo512.png",
          "type": "image/png",
          "sizes": "512x512"
        }
      ],
      "start_url": ".",
      "display": "standalone",
      "theme_color": "#000000",
      "background_color": "#ffffff"
    }
  8. Install Quiver and its dependencies

    Quiver is a library of React hooks and components for Ethereum dApps. It relies on ethers for blockchain functionality, Web3Modal for wallet connectivity, and TypeChain for TypeScript contract typing. To get started, install the core package along with its primary dependencies.
    yarn add @raidguild/quiver ethers web3modal