ERCs
ERC-20 — Fungible Token Standard
import {
balance_of,
total_supply,
transfer,
approve,
allowance,
transfer_from,
} from "@ethernauta/erc/20"; Core methods
| Method | Shape | Purpose |
|---|---|---|
name | Callable<string> | Token name. |
symbol | Callable<string> | Token symbol. |
decimals | Callable<number> | Decimals exponent. |
total_supply | Callable<Uint256> | Total supply. |
balance_of({ owner }) | Callable<Uint256> | Balance of an account. |
allowance({ owner, spender }) | Callable<Uint256> | Approval amount. |
transfer({ to, amount }) | Signable<Hash32> | Send tokens. |
approve({ spender, amount }) | Signable<Hash32> | Grant allowance. |
transfer_from({ from, to, amount }) | Signable<Hash32> | Transfer using allowance. |
Reading a balance
import { create_contract } from "@ethernauta/transport";
import { balance_of, decimals } from "@ethernauta/erc/20";
import { format_unit } from "@ethernauta/utils";
import { eip155_1 } from "@ethernauta/chain";
const contract = create_contract([eip155_1]);
const ctx = contract({
chain_id: eip155_1.chain_id,
contract: usdc_address,
});
const raw = await balance_of({ owner: holder })(ctx);
const d = await decimals()(ctx);
console.log(format_unit(raw, d), "USDC"); Transferring
import { transfer } from "@ethernauta/erc/20";
import { create_signer } from "@ethernauta/transport";
const signer = create_signer([eip155_1]);
const hash = await transfer({
to: recipient,
amount: parse_unit("100", 6),
})(signer({ chain_id: eip155_1.chain_id, contract: usdc_address })); Wallet handles nonce + gas; to is the token contract, not the recipient. The to recipient is in the call arguments.
Extensions
ERC-20 has several optional extensions, each at a sub-subpath:
| Subpath | Methods |
|---|---|
@ethernauta/erc/20/burnable | burn, burn_from |
@ethernauta/erc/20/capped | cap |
@ethernauta/erc/20/metadata | name, symbol, decimals (re-export) |
@ethernauta/erc/20/mintable | mint |
@ethernauta/erc/20/pausable | pause, unpause, paused |
@ethernauta/erc/20/wrapper | deposit_for, withdraw_to (wrapped-token pattern) |
Import only what you need; tree-shaking removes the rest.
See also
- ERC-2612 — permit (gasless approvals).
- Guide → calling contracts.