ERCs
ERC-2612 — Permit (gasless approvals)
ERC-20 approvals normally require a transaction. ERC-2612 adds permit(owner, spender, value, deadline, v, r, s) — an EIP-712 signature the owner produces off-chain, then any party submits as a transaction. Gas is paid by whoever submits, not by the owner.
import { permit, nonces, DOMAIN_SEPARATOR } from "@ethernauta/erc/2612";
// step 1: read nonce + domain
const nonce = await nonces({ owner })(token_ctx);
const domain_separator = await DOMAIN_SEPARATOR()(token_ctx);
// step 2: build the EIP-712 typed data, owner signs
// step 3: submit
const hash = await permit({
owner,
spender,
value,
deadline,
v, r, s,
})(signer({ chain_id: eip155_1.chain_id, contract: token })); Surface
| Method | Shape | Purpose |
|---|---|---|
permit({ owner, spender, value, deadline, v, r, s }) | Signable<Hash32> | Submit a permit. |
nonces({ owner }) | Callable<Uint256> | Current permit nonce. |
DOMAIN_SEPARATOR() | Callable<Bytes32> | The EIP-712 domain hash. |
Typed-data payload
The signer signs an EIP-712 message with this shape:
domain: { name, version, chainId, verifyingContract }
types: {
Permit: [
{ name: "owner", type: "address" },
{ name: "spender", type: "address" },
{ name: "value", type: "uint256" },
{ name: "nonce", type: "uint256" },
{ name: "deadline", type: "uint256" }
]
} Hash with hash_typed_data from @ethernauta/eip/712, sign with the signer.