0.0.3 • Published 1 month ago
ethers-query v0.0.3
ethers-query
React Query hooks for ethers.js - Build Web3 apps with ease.
Features
- 🔌 Easy Wallet Integration - Simple hooks for connecting to and managing Web3 wallets
- 📊 Smart Contract Interactions - Type-safe hooks for reading from and writing to smart contracts
- 💾 Automatic Caching - Built on React Query for efficient data caching and synchronization
- 🔄 Real-time Updates - Automatic balance updates and contract state synchronization
- 📝 Message Signing - Streamlined hooks for signing and verifying messages
- 🛠️ Type-Safe - Full TypeScript support with type inference
Quick Start
npm install ethers-query @tanstack/react-query ethers@6
import { EthersQueryProvider, Client } from 'ethers-query'
import { QueryClient, QueryClientProvider } from '@tanstack/react-query'
const client = new Client({
connectors: [new InjectedConnector()]
})
const queryClient = new QueryClient()
function App() {
return (
<QueryClientProvider client={queryClient}>
<EthersQueryProvider client={client}>
<YourApp />
</EthersQueryProvider>
</QueryClientProvider>
)
}
Usage Example
import { useAccount, useBalance, useWallet } from 'ethers-query'
function WalletConnection() {
const { connect } = useWallet()
const { address, isConnected } = useAccount()
const { data: balance } = useBalance({
address,
formatUnits: true
})
if (!isConnected) {
return (
<button onClick={() => connect({ connectorId: 'injected' })}>
Connect Wallet
</button>
)
}
return (
<div>
<div>Connected: {address}</div>
<div>Balance: {balance} ETH</div>
</div>
)
}
Documentation
For full documentation, visit ethers-query.recursive.so
License
GPL-3.0