Skip to main content

ERC20 Standard

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

Get Token Metadata

const token = await contract.erc20.get();

This snippet is for v3 of the SDK. Learn how to upgrade.

View in React SDK Documentation

Total Supply

Get how much supply has been minted

const { data: totalSupply, isLoading, error } = useTokenSupply(contract);

This snippet is for v3 of the SDK. Learn how to upgrade.

View in React SDK Documentation

View Token Balance

Get the balance of this token for the given address.

const { data: balance, isLoading, error } = useTokenBalance(contract, "{{wallet_address}}");

This snippet is for v3 of the SDK. Learn how to upgrade.

View in React SDK Documentation

Transfer

Transfer tokens from one wallet to another

const Component = () => {
const { contract } = useContract("{{contract_address}}");
const {
mutate: transferTokens,
isLoading,
error,
} = useTransferToken(contract);

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

return (
<button
disabled={isLoading}
onClick={() => transferTokens({ to: "{{wallet_address}}", amount: 1000 })}
>
Transfer
</button>
);
};

This snippet is for v3 of the SDK. Learn how to upgrade.

View in React SDK Documentation

Batch Transfer

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

const Component = () => {
const { contract } = useContract("{{contract_address}}");
const {
mutate: transferBatchTokens,
isLoading,
error,
} = useTransferToken(contract);

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

return (
<button
disabled={isLoading}
onClick={() => transferBatchTokens([{ to: "{{wallet_address}}", amount: 1000 }, { to: "{{wallet_address}}", amount: 2000 }])}
>
Airdrop
</button>
);
};

This snippet is for v3 of the SDK. Learn how to upgrade.

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);

This snippet is for v3 of the SDK. Learn how to upgrade.

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);

This snippet is for v3 of the SDK. Learn how to upgrade.

View in React SDK Documentation