Skip to main content

useERC20

Returns a ERC20 Contract instance and a bunch of other useful functions from contract address.

Usage

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

export default function MyComponent() {
const {
// Contract instance
contract,

// Other useful functions
getBalance,
getAllowance,
getTotalSupply,
getSymbol,

approve,
transfer,
} = useERC20('0x00');
}

Parameters

address

ERC20 contract address.

TypeDefault
stringRequired

Returns

An object with the following properties:

contract

Contract instance.

Type
ethers.Contract

getBalance

Get the balance of the address

Type
(address: string) => Promise<ContractResult>

getAllowance

Get the allowance of the owner and spender

Type
(owner: string, spender: string) => Promise<ContractResult>

getTotalSupply

Get the total supply of the token

Type
() => Promise<ContractResult>

getSymbol

Get the symbol of the token

Type
() => Promise<ContractResult>

approve

Approve the spender to spend the amount of tokens

Type
(spender: string, amount: number | string) => Promise<ContractResult>

transfer

Transfer the amount of tokens to the recipient

Type
(recipient: string, amount: number | string) => Promise<ContractResult>