Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up

React hooks for Cosmos 🪐

License

NotificationsYou must be signed in to change notification settings

graz-sh/graz

Repository files navigation

graz

npm/vnpm/dtstars

graz is a collection of React hooks containing everything you need to start working with theCosmos ecosystem.

Features

  • 🪝 20+ hooks for interfacing with wallets, clients, signers, etc. (connecting, view balances, send tokens, etc.)
  • 💳 Multiple wallet supports (Keplr, Leap, Cosmostation, Vectis, Station, XDefi, Metamask Snap, WalletConnect)
  • ⚙️ Generate mainnet & testnetChainInfo
  • 📚 Built-in caching, request deduplication, and all the good stuff from@tanstack/react-query andzustand
  • 🔄 Auto refresh on wallet and network change
  • 👏 Fully typed and tree-shakeable
  • ...and many more ✨

Requirements

graz requiresreact@>=17 due to usingfunction components and hooks and thenew JSX transform.

Installing

Installgraz usingnpm,yarn, orpnpm:

# using npmnpm install graz# using yarnyarn add graz# using pnpmpnpm add graz

Install peer dependencies

To avoid version mismatch we decided to make these packages as peer dependencies:

# using npmnpm install @cosmjs/cosmwasm-stargate @cosmjs/launchpad @cosmjs/proto-signing @cosmjs/stargate @cosmjs/tendermint-rpc long# using yarnyarn add @cosmjs/cosmwasm-stargate @cosmjs/launchpad @cosmjs/proto-signing @cosmjs/stargate @cosmjs/tendermint-rpc long# using pnpmpnpm add @cosmjs/cosmwasm-stargate @cosmjs/launchpad @cosmjs/proto-signing @cosmjs/stargate @cosmjs/tendermint-rpc long

Quick start

Wrap your React app with<QueryClientProvider /> and<GrazProvider />, and use availablegraz hooks anywhere:

import{QueryClient,QueryClientProvider}from"@tanstack/react-query";import{GrazProvider}from"graz";constqueryClient=newQueryClient();constcosmoshub:ChainInfo={chainId:"cosmoshub-4",chainName:"Cosmos Hub",//... rest of cosmoshub ChainInfo}functionApp(){return(<QueryClientProviderqueryClient={queryClient}><GrazProvidergrazOptions={{chains:[cosmoshub]}}><Wallet/></GrazProvider></QueryClientProvider>);}
import{mainnetChains,useAccount,useConnect,useDisconnect}from"graz";functionWallet(){const{ connect, status}=useConnect();const{data:account, isConnected}=useAccount();const{ disconnect}=useDisconnect();functionhandleConnect(){returnisConnected ?disconnect() :connect();}return(<div>{account ?`Connected to${account.bech32Address}` :status}<buttononClick={handleConnect}>{isConnected ?"Disconnect" :"Connect"}</button></div>);}

Examples

API

You can read more about available hooks and exports onDocumentation Site or viapaka.dev.

Maintainers

License

MIT License, Copyright (c) 2023 Graz


[8]ページ先頭

©2009-2025 Movatter.jp