Docs
/Hooks
/useSigner
useSigner
Hook for accessing ethers.js Signer object for connected account.
import { useSigner } from 'wagmi'
Usage
The following examples use the ENS Registry Contract.
import { useContract, useSigner } from 'wagmi'
function App() {
const { data: signer, isError, isLoading } = useSigner()
const contract = useContract({
addressOrName: '0x00000000000C2E074eC69A0dFb2997BA6C7d2e1e',
contractInterface: ensRegistryABI,
signerOrProvider: signer,
})
}
Return Values
{
data?: ethers.Signer
error?: Error
isError: boolean
isFetched: boolean
isFetching: boolean
isIdle: boolean
isLoading: boolean
isRefetching: boolean
isSuccess: boolean
status: 'idle' | 'error' | 'loading' | 'success'
}
Configuration
onError (optional)
Function to invoke when an error is thrown while fetching new data.
import { useContract, useSigner } from 'wagmi'
function App() {
const { data: signer } = useSigner({
onError(error) {
console.log('Error', error)
},
})
}
onSettled (optional)
Function to invoke when fetching is settled (either successfully fetched, or an error has thrown).
import { useContract, useSigner } from 'wagmi'
function App() {
const { data: signer } = useSigner({
onSettled(data, error) {
console.log('Settled', data, error)
},
})
}
onSuccess (optional)
Function to invoke when fetching new data is successful.
import { useContract, useSigner } from 'wagmi'
function App() {
const { data: signer } = useSigner({
onSuccess(data) {
console.log('Success', data)
},
})
}