Skip to content
Docs
/
Hooks
/
useSigner

useSigner

Hook for accessing ethers 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 Value

{
  data?: ethers.Signer
  error?: Error
  isIdle: boolean
  isLoading: boolean
  isFetching: boolean
  isSuccess: boolean
  isError: boolean
  isFetched: boolean
  isRefetching: 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)
    },
  })
}