Skip to main content

useContract

Returns an ethers.Contract instance.

info

Only difference from using the ethers.Contract is that this hook will automatically connect provider or signer to Contract instance. So, instead of using this hook, you can also choose to use ethers.Contract directly and pass the provider or signer yourself.

Usage

import {useContract} from '@incirlabs/react-ethooks';

export default function MyComponent() {
const MyContract = useContract('0x00', MyContractABI);

// Do something with MyContract
}

Parameters

contractAddress

Address of the contract to interact with.

TypeDefault
stringRequired

contractInterface

Interface of the contract (ABI) to interact with.

TypeDefault
ethers.ContractInterfaceRequired

withSigner

Whether to connect signer or provider into the contract instance.

If true, signer will be connected. If false, provider will be connected.

If you do not connect signer, you can not send transactions with it, but you can still call view functions.

However, this is not the case if you pass this contract instance to useContractWrite hook, since it will automatically connect signer in any case.

TypeDefault
booleanfalse

Returns

ethers.Contract instance.