{"eip":7758,"title":"Transfer With Authorization","description":"Transfer fungible assets via a signed authorization.","authors":["Peter Jihoon Kim (@petejkim)","Kevin Britz (@kbrizzle)","David Knott (@DavidLKnott)","Dongri Jin (@dongri)"],"status":"Review","type":"Standards Track","category":"ERC","created":"2020-09-28","requires":[20,712],"discussionsTo":"https://ethereum-magicians.org/t/erc-7758-transfer-with-authorization/20859","repo":"ERCs","label":"ERC-7758","officialUrl":"https://eips.ethereum.org/EIPS/eip-7758","sourceUrl":"https://github.com/ethereum/ERCs/blob/master/ERCS/erc-7758.md","url":"https://eips.huatuo.xyz/eip-7758/","tldr":{"en":"Move ERC-20 tokens with an off-chain signature instead of a transaction - anyone can submit it, gas can be paid by a relayer or in the token itself, and random nonces let many authorizations run in parallel. Successor of ERC-3009; implemented by USDC.","ja":"ERC-20 トークンをトランザクションではなくオフチェーン署名で送金する。署名は誰でも提出でき、ガス代はリレイヤーやトークン自体で支払え、ランダム nonce により複数の認可を並行して使える。ERC-3009 の後継で、USDC が実装済み。","ko":"ERC-20 토큰을 트랜잭션 대신 오프체인 서명으로 전송한다. 누구나 서명을 제출할 수 있고, 가스비는 릴레이어나 토큰 자체로 낼 수 있으며, 랜덤 nonce 덕분에 여러 승인을 병렬로 쓸 수 있다. ERC-3009의 후속이며 USDC가 구현했다.","zh":"用链下签名而不是交易来转移 ERC-20 代币：任何人都可以提交签名，gas 可由中继者或用代币本身支付，随机 nonce 让多个授权可以并行。ERC-3009 的后继，USDC 已实现。"},"tags":["token","meta-transaction","gasless","eip-712","usdc","erc-20"],"explainers":{"en":{"lang":"en","tldr":"Move ERC-20 tokens with an off-chain signature instead of a transaction - anyone can submit it, gas can be paid by a relayer or in the token itself, and random nonces let many authorizations run in parallel. Successor of ERC-3009; implemented by USDC.","tags":["token","meta-transaction","gasless","eip-712","usdc","erc-20"],"related":[20,712,2612,3009,4337],"updated":"2026-10-19","url":"https://eips.huatuo.xyz/eip-7758/","markdown":"## What problem does it solve?\n\nTo send an [ERC-20](/eip-20/) token you normally need ETH in the same account to pay gas. A user who was just sent 50 USDC and nothing else is stuck. Protocols also have to make users run two transactions (`approve`, then `transferFrom`) before they can take payment, and the allowance pattern invites \"infinite approval\" habits and multiple-withdrawal attacks.\n\nERC-7758 lets a token holder **sign** a transfer authorization off-chain. Anyone (a relayer, the recipient, a paymaster) can submit that signature to the token contract, which performs the transfer. The holder never needs ETH and never grants an allowance.\n\n[ERC-2612](/eip-2612/) `permit` solves part of this but keeps the allowance model and uses *sequential* nonces, so a user cannot have several authorizations in flight. ERC-7758 uses **random 32-byte nonces**, so authorizations are independent and can be created in any quantity and order.\n\nERC-7758 is the re-submission of [ERC-3009](/eip-3009/) with the same specification, moved into the current review process. USDC has implemented it since 2020, so a very large share of stablecoin \"gasless\" flows already run on this interface.\n\n## How it works\n\nThe token exposes three signature-driven functions. All messages are [EIP-712](/eip-712/) typed data over the token's domain (`name`, `version`, `chainId`, `verifyingContract`).\n\n| Function | Who calls it | Purpose |\n| --- | --- | --- |\n| `transferWithAuthorization(from, to, value, validAfter, validBefore, nonce, v, r, s)` | anyone | Execute a transfer signed by `from` |\n| `receiveWithAuthorization(...)` | only `to` | Same, but the payee must be the caller, so a watcher cannot front-run and steal a deposit flow |\n| `cancelAuthorization(authorizer, nonce, v, r, s)` | anyone | Invalidate an unused nonce (optional) |\n| `authorizationState(authorizer, nonce)` | view | `true` once a nonce has been used or cancelled |\n\nEach authorization has a validity window (`validAfter` / `validBefore`, unix time) and a unique `nonce`. Once consumed, the contract emits `AuthorizationUsed(authorizer, nonce)` and refuses the same nonce again.\n\n## Sample code\n\nSigning an authorization in the browser or backend (ethers v6):\n\n```ts\nimport { Wallet, randomBytes, hexlify, Signature, parseUnits } from \"ethers\";\n\nconst holder = new Wallet(HOLDER_KEY);          // owns the tokens, has no ETH\nconst now = Math.floor(Date.now() / 1000);\n\nconst domain = {\n  name: \"USD Coin\",\n  version: \"2\",\n  chainId: 1,\n  verifyingContract: \"0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48\",\n};\nconst types = {\n  TransferWithAuthorization: [\n    { name: \"from\", type: \"address\" },\n    { name: \"to\", type: \"address\" },\n    { name: \"value\", type: \"uint256\" },\n    { name: \"validAfter\", type: \"uint256\" },\n    { name: \"validBefore\", type: \"uint256\" },\n    { name: \"nonce\", type: \"bytes32\" },\n  ],\n};\nconst message = {\n  from: holder.address,\n  to: MERCHANT,\n  value: parseUnits(\"50\", 6),\n  validAfter: 0,\n  validBefore: now + 3600,            // valid for one hour\n  nonce: hexlify(randomBytes(32)),    // random, not sequential\n};\n\nconst sig = Signature.from(await holder.signTypedData(domain, types, message));\n// hand { message, v: sig.v, r: sig.r, s: sig.s } to the relayer\n```\n\nThe relayer (any account with ETH) submits it:\n\n```ts\nconst usdc = new Contract(domain.verifyingContract, [\n  \"function transferWithAuthorization(address from,address to,uint256 value,uint256 validAfter,uint256 validBefore,bytes32 nonce,uint8 v,bytes32 r,bytes32 s)\",\n], relayerWallet);\n\nawait usdc.transferWithAuthorization(\n  message.from, message.to, message.value,\n  message.validAfter, message.validBefore, message.nonce,\n  sig.v, sig.r, sig.s,\n);\n```\n\nA contract that accepts token deposits atomically, using `receiveWithAuthorization` so the signature can only be used by this contract:\n\n```solidity\ninterface IERC7758 {\n    function receiveWithAuthorization(\n        address from, address to, uint256 value,\n        uint256 validAfter, uint256 validBefore, bytes32 nonce,\n        uint8 v, bytes32 r, bytes32 s\n    ) external;\n}\n\ncontract Vault {\n    IERC7758 public immutable token;\n    mapping(address =\u003e uint256) public deposits;\n\n    constructor(IERC7758 _token) { token = _token; }\n\n    function deposit(\n        address from, uint256 value, uint256 validAfter, uint256 validBefore,\n        bytes32 nonce, uint8 v, bytes32 r, bytes32 s\n    ) external {\n        // `to` must be this contract; the token enforces msg.sender == to.\n        token.receiveWithAuthorization(from, address(this), value, validAfter, validBefore, nonce, v, r, s);\n        deposits[from] += value;\n    }\n}\n```\n\n## Things to know\n\n- Use `receiveWithAuthorization` whenever a contract is the payee. With `transferWithAuthorization` a bot could submit the signature first; the tokens would still arrive, but the contract's own bookkeeping call would never run.\n- Nonces are random `bytes32`, so generate them with a CSPRNG and check `authorizationState` before reuse. The same nonce can be used once per authorizer.\n- Signatures are chain- and contract-specific thanks to the EIP-712 domain; check the token's `name` and `version` (USDC uses version `\"2\"`).\n- Because the signer never pays gas, this pairs naturally with [ERC-4337](/eip-4337/) paymasters and with [EIP-7702](/eip-7702/) sponsored transactions.\n"},"ja":{"lang":"ja","tldr":"ERC-20 トークンをトランザクションではなくオフチェーン署名で送金する。署名は誰でも提出でき、ガス代はリレイヤーやトークン自体で支払え、ランダム nonce により複数の認可を並行して使える。ERC-3009 の後継で、USDC が実装済み。","tags":["token","meta-transaction","gasless","eip-712","usdc","erc-20"],"related":[20,712,2612,3009,4337],"updated":"2026-10-19","url":"https://eips.huatuo.xyz/ja/eip-7758/","markdown":"## 何を解決するのか\n\n[ERC-20](/eip-20/) トークンを送るには、通常は同じアカウントにガス代用の ETH が必要です。50 USDC だけを受け取ったユーザーは身動きが取れません。プロトコル側も支払いを受け取る前にユーザーに 2 回のトランザクション（`approve` → `transferFrom`）を実行させる必要があり、allowance パターンは「無限承認」の習慣や多重引き出し攻撃を招きます。\n\nERC-7758 では、トークン保有者が送金の認可にオフチェーンで**署名**します。誰でも（リレイヤー、受取人、Paymaster）その署名をトークンコントラクトに提出でき、コントラクトが送金を実行します。保有者は ETH を持つ必要も、allowance を与える必要もありません。\n\n[ERC-2612](/eip-2612/) の `permit` はこの一部を解決しますが、allowance モデルを維持し、*連番*の nonce を使うため、ユーザーは複数の認可を同時に発行できません。ERC-7758 は**ランダムな 32 バイトの nonce** を使うため、認可は互いに独立で、数も順序も自由です。\n\nERC-7758 は [ERC-3009](/eip-3009/) を同じ仕様のまま現行のレビュープロセスに再提出したものです。USDC は 2020 年から実装しており、ステーブルコインの「ガスレス」フローの大部分はすでにこのインターフェースの上で動いています。\n\n## 仕組み\n\nトークンは署名駆動の 3 つの関数を公開します。すべてのメッセージは、トークンのドメイン（`name`、`version`、`chainId`、`verifyingContract`）に対する [EIP-712](/eip-712/) 型付きデータです。\n\n| 関数 | 呼び出せる人 | 役割 |\n| --- | --- | --- |\n| `transferWithAuthorization(from, to, value, validAfter, validBefore, nonce, v, r, s)` | 誰でも | `from` が署名した送金を実行 |\n| `receiveWithAuthorization(...)` | `to` のみ | 同上だが受取人が呼び出し元でなければならない。監視者がフロントランして入金フローを横取りするのを防ぐ |\n| `cancelAuthorization(authorizer, nonce, v, r, s)` | 誰でも | 未使用の nonce を無効化（任意） |\n| `authorizationState(authorizer, nonce)` | view | nonce が使用済みまたは取消済みなら `true` |\n\n各認可は有効期間（`validAfter` / `validBefore`、unix time）と一意の `nonce` を持ちます。消費されるとコントラクトは `AuthorizationUsed(authorizer, nonce)` を発行し、同じ nonce を二度と受け付けません。\n\n## サンプルコード\n\nブラウザまたはバックエンドで認可に署名する（ethers v6）:\n\n```ts\nimport { Wallet, randomBytes, hexlify, Signature, parseUnits } from \"ethers\";\n\nconst holder = new Wallet(HOLDER_KEY);          // トークンを保有し、ETH は持たない\nconst now = Math.floor(Date.now() / 1000);\n\nconst domain = {\n  name: \"USD Coin\",\n  version: \"2\",\n  chainId: 1,\n  verifyingContract: \"0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48\",\n};\nconst types = {\n  TransferWithAuthorization: [\n    { name: \"from\", type: \"address\" },\n    { name: \"to\", type: \"address\" },\n    { name: \"value\", type: \"uint256\" },\n    { name: \"validAfter\", type: \"uint256\" },\n    { name: \"validBefore\", type: \"uint256\" },\n    { name: \"nonce\", type: \"bytes32\" },\n  ],\n};\nconst message = {\n  from: holder.address,\n  to: MERCHANT,\n  value: parseUnits(\"50\", 6),\n  validAfter: 0,\n  validBefore: now + 3600,            // 1 時間有効\n  nonce: hexlify(randomBytes(32)),    // 連番ではなくランダム\n};\n\nconst sig = Signature.from(await holder.signTypedData(domain, types, message));\n// { message, v: sig.v, r: sig.r, s: sig.s } をリレイヤーに渡す\n```\n\nリレイヤー（ETH を持つ任意のアカウント）が提出する:\n\n```ts\nconst usdc = new Contract(domain.verifyingContract, [\n  \"function transferWithAuthorization(address from,address to,uint256 value,uint256 validAfter,uint256 validBefore,bytes32 nonce,uint8 v,bytes32 r,bytes32 s)\",\n], relayerWallet);\n\nawait usdc.transferWithAuthorization(\n  message.from, message.to, message.value,\n  message.validAfter, message.validBefore, message.nonce,\n  sig.v, sig.r, sig.s,\n);\n```\n\n`receiveWithAuthorization` を使い、署名をこのコントラクトだけが使えるようにしてトークン入金をアトミックに受け付けるコントラクト:\n\n```solidity\ninterface IERC7758 {\n    function receiveWithAuthorization(\n        address from, address to, uint256 value,\n        uint256 validAfter, uint256 validBefore, bytes32 nonce,\n        uint8 v, bytes32 r, bytes32 s\n    ) external;\n}\n\ncontract Vault {\n    IERC7758 public immutable token;\n    mapping(address =\u003e uint256) public deposits;\n\n    constructor(IERC7758 _token) { token = _token; }\n\n    function deposit(\n        address from, uint256 value, uint256 validAfter, uint256 validBefore,\n        bytes32 nonce, uint8 v, bytes32 r, bytes32 s\n    ) external {\n        // to はこのコントラクトでなければならない。トークン側が msg.sender == to を強制する。\n        token.receiveWithAuthorization(from, address(this), value, validAfter, validBefore, nonce, v, r, s);\n        deposits[from] += value;\n    }\n}\n```\n\n## 知っておくべきこと\n\n- コントラクトが受取人になる場合は必ず `receiveWithAuthorization` を使ってください。`transferWithAuthorization` だとボットが先に署名を提出でき、トークンは届くもののコントラクト側の記帳処理が実行されません。\n- nonce はランダムな `bytes32` なので、CSPRNG で生成し、再利用前に `authorizationState` を確認してください。同じ nonce は認可者ごとに一度だけ使えます。\n- EIP-712 ドメインにより署名はチェーンとコントラクトに固有です。トークンの `name` と `version` を確認してください（USDC は version `\"2\"`）。\n- 署名者はガス代を払わないため、[ERC-4337](/eip-4337/) の Paymaster や [EIP-7702](/eip-7702/) のスポンサー付きトランザクションと自然に組み合わせられます。\n"},"ko":{"lang":"ko","tldr":"ERC-20 토큰을 트랜잭션 대신 오프체인 서명으로 전송한다. 누구나 서명을 제출할 수 있고, 가스비는 릴레이어나 토큰 자체로 낼 수 있으며, 랜덤 nonce 덕분에 여러 승인을 병렬로 쓸 수 있다. ERC-3009의 후속이며 USDC가 구현했다.","tags":["token","meta-transaction","gasless","eip-712","usdc","erc-20"],"related":[20,712,2612,3009,4337],"updated":"2026-10-19","url":"https://eips.huatuo.xyz/ko/eip-7758/","markdown":"## 어떤 문제를 해결하나요?\n\n[ERC-20](/eip-20/) 토큰을 보내려면 보통 같은 계정에 가스비용 ETH가 있어야 합니다. 50 USDC만 받고 다른 건 아무것도 없는 사용자는 꼼짝할 수 없습니다. 프로토콜도 결제를 받기 전에 사용자가 두 번의 트랜잭션(`approve`, 그다음 `transferFrom`)을 실행하게 해야 하고, allowance 패턴은 \"무한 승인\" 습관과 다중 인출 공격을 부릅니다.\n\nERC-7758은 토큰 보유자가 전송 승인에 오프체인으로 **서명**하게 합니다. 누구나(릴레이어, 수취인, Paymaster) 그 서명을 토큰 컨트랙트에 제출할 수 있고, 컨트랙트가 전송을 수행합니다. 보유자는 ETH가 필요 없고 allowance를 부여할 필요도 없습니다.\n\n[ERC-2612](/eip-2612/)의 `permit`은 이 중 일부를 해결하지만 allowance 모델을 유지하고 *순차* nonce를 쓰기 때문에, 사용자가 여러 승인을 동시에 띄울 수 없습니다. ERC-7758은 **랜덤 32바이트 nonce**를 사용하므로 승인들이 서로 독립적이며 개수와 순서에 제한이 없습니다.\n\nERC-7758은 [ERC-3009](/eip-3009/)를 같은 명세 그대로 현재의 검토 프로세스에 다시 제출한 것입니다. USDC는 2020년부터 이를 구현해 왔기 때문에, 스테이블코인 \"가스리스\" 흐름의 상당 부분이 이미 이 인터페이스 위에서 동작합니다.\n\n## 어떻게 동작하나요?\n\n토큰은 서명 기반 함수 세 개를 노출합니다. 모든 메시지는 토큰의 도메인(`name`, `version`, `chainId`, `verifyingContract`)에 대한 [EIP-712](/eip-712/) 타입 데이터입니다.\n\n| 함수 | 호출 가능 주체 | 역할 |\n| --- | --- | --- |\n| `transferWithAuthorization(from, to, value, validAfter, validBefore, nonce, v, r, s)` | 누구나 | `from`이 서명한 전송을 실행 |\n| `receiveWithAuthorization(...)` | `to`만 | 같지만 수취인이 호출자여야 함. 감시자가 프런트런으로 입금 흐름을 가로채는 것을 방지 |\n| `cancelAuthorization(authorizer, nonce, v, r, s)` | 누구나 | 사용되지 않은 nonce를 무효화(선택) |\n| `authorizationState(authorizer, nonce)` | view | nonce가 사용 또는 취소되었으면 `true` |\n\n각 승인은 유효 기간(`validAfter` / `validBefore`, unix time)과 고유한 `nonce`를 가집니다. 소비되면 컨트랙트는 `AuthorizationUsed(authorizer, nonce)`를 발생시키고 같은 nonce를 다시 받지 않습니다.\n\n## 샘플 코드\n\n브라우저나 백엔드에서 승인에 서명하기(ethers v6):\n\n```ts\nimport { Wallet, randomBytes, hexlify, Signature, parseUnits } from \"ethers\";\n\nconst holder = new Wallet(HOLDER_KEY);          // 토큰을 보유, ETH는 없음\nconst now = Math.floor(Date.now() / 1000);\n\nconst domain = {\n  name: \"USD Coin\",\n  version: \"2\",\n  chainId: 1,\n  verifyingContract: \"0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48\",\n};\nconst types = {\n  TransferWithAuthorization: [\n    { name: \"from\", type: \"address\" },\n    { name: \"to\", type: \"address\" },\n    { name: \"value\", type: \"uint256\" },\n    { name: \"validAfter\", type: \"uint256\" },\n    { name: \"validBefore\", type: \"uint256\" },\n    { name: \"nonce\", type: \"bytes32\" },\n  ],\n};\nconst message = {\n  from: holder.address,\n  to: MERCHANT,\n  value: parseUnits(\"50\", 6),\n  validAfter: 0,\n  validBefore: now + 3600,            // 1시간 동안 유효\n  nonce: hexlify(randomBytes(32)),    // 순차가 아닌 랜덤\n};\n\nconst sig = Signature.from(await holder.signTypedData(domain, types, message));\n// { message, v: sig.v, r: sig.r, s: sig.s }를 릴레이어에게 전달\n```\n\n릴레이어(ETH가 있는 아무 계정)가 제출:\n\n```ts\nconst usdc = new Contract(domain.verifyingContract, [\n  \"function transferWithAuthorization(address from,address to,uint256 value,uint256 validAfter,uint256 validBefore,bytes32 nonce,uint8 v,bytes32 r,bytes32 s)\",\n], relayerWallet);\n\nawait usdc.transferWithAuthorization(\n  message.from, message.to, message.value,\n  message.validAfter, message.validBefore, message.nonce,\n  sig.v, sig.r, sig.s,\n);\n```\n\n`receiveWithAuthorization`을 사용해 서명이 이 컨트랙트에서만 쓰이도록 하면서 토큰 입금을 원자적으로 받는 컨트랙트:\n\n```solidity\ninterface IERC7758 {\n    function receiveWithAuthorization(\n        address from, address to, uint256 value,\n        uint256 validAfter, uint256 validBefore, bytes32 nonce,\n        uint8 v, bytes32 r, bytes32 s\n    ) external;\n}\n\ncontract Vault {\n    IERC7758 public immutable token;\n    mapping(address =\u003e uint256) public deposits;\n\n    constructor(IERC7758 _token) { token = _token; }\n\n    function deposit(\n        address from, uint256 value, uint256 validAfter, uint256 validBefore,\n        bytes32 nonce, uint8 v, bytes32 r, bytes32 s\n    ) external {\n        // to는 이 컨트랙트여야 한다. 토큰이 msg.sender == to를 강제한다.\n        token.receiveWithAuthorization(from, address(this), value, validAfter, validBefore, nonce, v, r, s);\n        deposits[from] += value;\n    }\n}\n```\n\n## 알아둘 점\n\n- 컨트랙트가 수취인일 때는 항상 `receiveWithAuthorization`을 사용하세요. `transferWithAuthorization`이면 봇이 서명을 먼저 제출할 수 있습니다. 토큰은 도착하지만 컨트랙트의 자체 장부 처리 호출은 영영 실행되지 않습니다.\n- nonce는 랜덤 `bytes32`이므로 CSPRNG로 생성하고 재사용 전에 `authorizationState`를 확인하세요. 같은 nonce는 승인자당 한 번만 쓸 수 있습니다.\n- EIP-712 도메인 덕분에 서명은 체인과 컨트랙트에 종속됩니다. 토큰의 `name`과 `version`을 확인하세요(USDC는 version `\"2\"`).\n- 서명자가 가스비를 내지 않으므로 [ERC-4337](/eip-4337/) Paymaster나 [EIP-7702](/eip-7702/) 후원 트랜잭션과 자연스럽게 결합됩니다.\n"},"zh":{"lang":"zh","tldr":"用链下签名而不是交易来转移 ERC-20 代币：任何人都可以提交签名，gas 可由中继者或用代币本身支付，随机 nonce 让多个授权可以并行。ERC-3009 的后继，USDC 已实现。","tags":["token","meta-transaction","gasless","eip-712","usdc","erc-20"],"related":[20,712,2612,3009,4337],"updated":"2026-10-19","url":"https://eips.huatuo.xyz/zh/eip-7758/","markdown":"## 它解决什么问题？\n\n要发送 [ERC-20](/eip-20/) 代币，通常同一账户里必须有 ETH 付 gas。一个刚收到 50 USDC、别无他物的用户就动弹不得。协议方也不得不让用户先做两笔交易（`approve`，再 `transferFrom`）才能收款，而 allowance 模式又助长了\"无限授权\"的习惯和多重提款攻击。\n\nERC-7758 让代币持有者在链下**签署**一份转账授权。任何人（中继者、收款方、Paymaster）都可以把这个签名提交给代币合约，由合约执行转账。持有者永远不需要 ETH，也永远不需要授予 allowance。\n\n[ERC-2612](/eip-2612/) 的 `permit` 解决了其中一部分，但保留了 allowance 模型，并使用*顺序* nonce，用户无法同时发出多个授权。ERC-7758 使用**随机 32 字节 nonce**，授权彼此独立，数量和顺序都不受限。\n\nERC-7758 是 [ERC-3009](/eip-3009/) 以相同规范重新提交到当前评审流程的版本。USDC 自 2020 年起就实现了它，因此很大一部分稳定币\"无 gas\"流程已经运行在这个接口之上。\n\n## 它如何运作\n\n代币公开三个由签名驱动的函数。所有消息都是基于代币域（`name`、`version`、`chainId`、`verifyingContract`）的 [EIP-712](/eip-712/) 类型化数据。\n\n| 函数 | 谁可以调用 | 用途 |\n| --- | --- | --- |\n| `transferWithAuthorization(from, to, value, validAfter, validBefore, nonce, v, r, s)` | 任何人 | 执行由 `from` 签名的转账 |\n| `receiveWithAuthorization(...)` | 仅 `to` | 同上，但收款方必须是调用者，防止监听者抢跑并劫持入金流程 |\n| `cancelAuthorization(authorizer, nonce, v, r, s)` | 任何人 | 作废一个未使用的 nonce（可选） |\n| `authorizationState(authorizer, nonce)` | view | nonce 已使用或已取消时返回 `true` |\n\n每个授权都有有效期窗口（`validAfter` / `validBefore`，unix 时间）和唯一的 `nonce`。一旦被消费，合约发出 `AuthorizationUsed(authorizer, nonce)` 并拒绝再次使用同一 nonce。\n\n## 示例代码\n\n在浏览器或后端签署授权（ethers v6）：\n\n```ts\nimport { Wallet, randomBytes, hexlify, Signature, parseUnits } from \"ethers\";\n\nconst holder = new Wallet(HOLDER_KEY);          // 持有代币，没有 ETH\nconst now = Math.floor(Date.now() / 1000);\n\nconst domain = {\n  name: \"USD Coin\",\n  version: \"2\",\n  chainId: 1,\n  verifyingContract: \"0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48\",\n};\nconst types = {\n  TransferWithAuthorization: [\n    { name: \"from\", type: \"address\" },\n    { name: \"to\", type: \"address\" },\n    { name: \"value\", type: \"uint256\" },\n    { name: \"validAfter\", type: \"uint256\" },\n    { name: \"validBefore\", type: \"uint256\" },\n    { name: \"nonce\", type: \"bytes32\" },\n  ],\n};\nconst message = {\n  from: holder.address,\n  to: MERCHANT,\n  value: parseUnits(\"50\", 6),\n  validAfter: 0,\n  validBefore: now + 3600,            // 一小时内有效\n  nonce: hexlify(randomBytes(32)),    // 随机而非顺序\n};\n\nconst sig = Signature.from(await holder.signTypedData(domain, types, message));\n// 把 { message, v: sig.v, r: sig.r, s: sig.s } 交给中继者\n```\n\n中继者（任何有 ETH 的账户）提交：\n\n```ts\nconst usdc = new Contract(domain.verifyingContract, [\n  \"function transferWithAuthorization(address from,address to,uint256 value,uint256 validAfter,uint256 validBefore,bytes32 nonce,uint8 v,bytes32 r,bytes32 s)\",\n], relayerWallet);\n\nawait usdc.transferWithAuthorization(\n  message.from, message.to, message.value,\n  message.validAfter, message.validBefore, message.nonce,\n  sig.v, sig.r, sig.s,\n);\n```\n\n一个原子化接收代币存款的合约，使用 `receiveWithAuthorization` 保证签名只能被本合约使用：\n\n```solidity\ninterface IERC7758 {\n    function receiveWithAuthorization(\n        address from, address to, uint256 value,\n        uint256 validAfter, uint256 validBefore, bytes32 nonce,\n        uint8 v, bytes32 r, bytes32 s\n    ) external;\n}\n\ncontract Vault {\n    IERC7758 public immutable token;\n    mapping(address =\u003e uint256) public deposits;\n\n    constructor(IERC7758 _token) { token = _token; }\n\n    function deposit(\n        address from, uint256 value, uint256 validAfter, uint256 validBefore,\n        bytes32 nonce, uint8 v, bytes32 r, bytes32 s\n    ) external {\n        // to 必须是本合约；代币会强制 msg.sender == to。\n        token.receiveWithAuthorization(from, address(this), value, validAfter, validBefore, nonce, v, r, s);\n        deposits[from] += value;\n    }\n}\n```\n\n## 需要注意\n\n- 当收款方是合约时，一律使用 `receiveWithAuthorization`。若用 `transferWithAuthorization`，机器人可以抢先提交签名：代币照样到账，但合约自己的记账调用永远不会执行。\n- nonce 是随机 `bytes32`，请用密码学安全的随机数生成，并在复用前检查 `authorizationState`。同一 nonce 对每个授权者只能用一次。\n- 由于 EIP-712 域的存在，签名与链和合约绑定；请核对代币的 `name` 和 `version`（USDC 使用 version `\"2\"`）。\n- 因为签名者不付 gas，它天然适合与 [ERC-4337](/eip-4337/) 的 Paymaster 以及 [EIP-7702](/eip-7702/) 的代付交易组合使用。\n"}}}
