Skip to main content

ERC20 Standard

You can utilize these features of the SDK on your contract if it implements ERC20.

Get Token Metadata

const token = await contract.erc20.get();
View in React SDK Documentation

Total Supply

Get how much supply has been minted

const { data: totalSupply, isLoading, error } = useTokenSupply(<YourTokenContractInstance>);
View in React SDK Documentation

View Token Balance

Get the balance of this token for the given address.

const { data: balance, isLoading, error } = useTokenBalance(<YourTokenContractInstance>);
View in React SDK Documentation

Transfer

Transfer tokens from one wallet to another

const Component = () => {
const {
mutate: transferTokens,
isLoading,
error,
} = useTransferToken(">>YourERC20ContractInstance<<");

if (error) {
console.error("failed to transfer tokens", error);
}

return (
<button
disabled={isLoading}
onClick={() => transferTokens({ to: "0x...", amount: 1000 })}
>
Transfer
</button>
);
};
View in React SDK Documentation

Batch Transfer

Transfer tokens from the connected wallet to many wallets in one transaction.

const Component = () => {
const {
mutate: transferBatchTokens,
isLoading,
error,
} = useTransferToken(">>YourERC20ContractInstance<<");

if (error) {
console.error("failed to transfer batch tokens", error);
}

return (
<button
disabled={isLoading}
onClick={() => transferBatchTokens([{ to: "0x...", amount: 1000 }, { to: "0x...", amount: 2000 }])}
>
Transfer Batch
</button>
);
};
View in React SDK Documentation

Token Allowance

Allowance refers to the number of tokens that a wallet is allowed to transfer on behalf of another wallet.

Grant Allowance

Allows the specified spender wallet to transfer the given amount of tokens to another wallet

// Address of the wallet to allow transfers from
const spenderAddress = "0x...";
// The number of tokens to give as allowance
const amount = 100
await contract.erc20.setAllowance(spenderAddress, amount);
View in React SDK Documentation

View Token Allowance

Get the allowance of one wallet over another wallet's funds - the allowance of a different address for a token is the amount of tokens that the wallet is allowed to spend on behalf of the specified wallet.

// Address of the wallet who owns the funds
const owner = "{{wallet_address}}";
// Address of the wallet to check token allowance
const spender = "0x...";
const allowance = await contract.erc20.allowanceOf(owner, spender);
View in React SDK Documentation