Quiver
website·Indexed 29 days ago
https://raid-guild.github.io/quiverA 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.
What's inside Quiver
- 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.
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 theetherspackage for Ethereum functionality and integratesWeb3Modalfor wallet connectivity. It provides full TypeScript support, including typed contracts via TypeChain.Switch blockchain networks using useWallet
The
useWallethook provides aswitchNetworkmethod to programmatically change the user's connected network. This is particularly useful for applications supporting multiple networks wheredefaultChainIdis not provided (as providing adefaultChainIdtypically enables auto-switching).Preconditions for switching networks:
- The user must have MetaMask installed.
- 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> </> );Start a project with Quiver starter templates
You can jumpstart your smart contract and web3 development using one of the following official starter projects:
- Hardhat + Create React App: https://github.com/midgerate/smart-contract-cra-starter
- Hardhat + Next.js: https://github.com/midgerate/smart-contract-nextjs-starter
Install Quiver dependencies and requirements
To use Quiver, the following dependencies are required in your project: ethers, react (version 16 or higher), and web3modal.Fetch token prices with useCGPrice
TheuseCGPricehook retrieves the current price of a token from CoinGecko. By default, it returns the value in USD. You can specify atokenId(the CoinGecko ID for the token) and optionally avsCurrencyto get the price in a different currency.const { price: ufoPrice } = useCGPrice({ tokenId: "ufo-gaming" });Integrate Quiver with Gnosis Safe Apps
Quiver integrates with Gnosis Safe Apps via thesafe-apps-web3modalwrapper. To enable this integration, add amanifest.jsonfile 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" }Write to a contract using useWriteContract
TheuseWriteContracthook 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 amutatemethod that triggers the transaction. Arguments for the contract function can be passed directly to themutatemethod 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); } };Install Quiver and peer dependencies
Quiver requires@raidguild/quiver,ethers, andweb3modalto be installed in your project.yarn add @raidguild/quiver ethers web3modalInstall Quiver dependencies
To use Quiver, ensure your project meets the following minimum requirements:
ethersreactversion 16 or higherweb3modal
Integrate Quiver with Gnosis Safe Apps
Quiver integrates with Gnosis Safe Apps via thesafe-apps-web3modalwrapper aroundweb3modal. To enable this integration, add amanifest.jsonfile 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" }Install Quiver and its dependencies
Quiver is a library of React hooks and components for Ethereum dApps. It relies onethersfor blockchain functionality,Web3Modalfor wallet connectivity, andTypeChainfor TypeScript contract typing. To get started, install the core package along with its primary dependencies.yarn add @raidguild/quiver ethers web3modal