EIP-2612 là Tiện ích mở rộng ERC-20 Permit cho phép người nắm giữ token cấp quyền chi tiêu cho một hợp đồng thông minh hoặc tài khoản khác bằng chữ ký ngoài chuỗi thay vì giao dịch phê duyệt trên chuỗi. Bằng cách nhúng dữ liệu đã ký vào một lệnh gọi permit() duy nhất, người dùng tiết kiệm gas và các nhà tích hợp có thể gộp phê duyệt + hành động thành một giao dịch nguyên tử.
Key Characteristics
- Gasless, single-call approvals: Người nắm giữ ký một thông điệp EIP-712 ngoài chuỗi và một lệnh gọi permit() ngay lập tức thiết lập quyền chi tiêu trong khi xác minh chữ ký, loại bỏ nhu cầu phê duyệt riêng biệt trên chuỗi và tối ưu hóa trải nghiệm người dùng.
- Security & backward compatibility: Each permit consumes a unique, ever-increasing nonce and the signature is bound to the token's EIP-712 domain (name, chain ID, contract address). The extension adds < 200 bytes to a standard ERC-20, leaving balances and transfers untouched.
- Seamless DeFi & wallet integration: DEXs, lending protocols, routers, and meta-TX relayers can batch permit -> action in one atomic transaction, while wallets like MetaMask and Ledger present it as a familiar Sign Message flow instead of a gas-priced approval.
Tại sao EIP-2612 không cần thiết trên Solana
Vì Solana cho phép bạn kết hợp phê duyệt và hành động trong một giao dịch nguyên tử, và mặc định cho phép người khác chi trả phí, hai điểm khó khăn mà EIP-2612 giải quyết trên Ethereum (phê duyệt lặp lại và người dùng phải trả gas) đã được loại bỏ ngay ở cấp độ giao thức. Không cần thêm hàm permit, miền dữ liệu có kiểu (typed-data domain) hay nâng cấp hợp đồng; chương trình SPL-Token tiêu chuẩn đáp ứng các yêu cầu đó ngay từ đầu.
Mô hình phê duyệt token
Trên Ethereum, việc chuyển token ERC20 giữa hai địa chỉ thường yêu cầu approve + transferFrom nếu bạn thực hiện thay mặt người dùng. Trên Solana, mỗi người dùng đã có sẵn một ATA (associated token account) được Token Program nhận diện. Một giao dịch Solana duy nhất có thể gọi nhiều lệnh theo cách nguyên tử (atomic), nên không cần bước phê duyệt riêng. Bạn có thể chuyển trực tiếp từ token account của người dùng này sang người dùng khác chỉ trong một lần.
Mô hình Fee-Payer (Ủy quyền Gas)
Mỗi giao dịch Solana đều chỉ định rõ cả người ký và fee-payer (người trả phí). Người dùng có thể ký giao dịch trong khi chỉ định một bên thứ ba (dịch vụ ví, backend của dApp hoặc relayer) trả phí. Nhờ đó, giao thức mang lại trải nghiệm không cần trả gas cho người dùng giống như mục tiêu của EIP-2612, nhưng không cần đưa vào một lược đồ chữ ký off-chain đặc biệt như EIP-712.
Cách thực hiện EIP-2612 trên Solana
Dưới đây là hai ví dụ tối giản, có thể sao chép và dùng ngay, ánh xạ hai kịch bản permit -> action phổ biến nhất sang các primitive gốc của Solana. Cả hai đều sử dụng @solana/web3.js và @solana/spl-token.
1. Chủ sở hữu trả phí (Chuyển tiền tự tài trợ)
Chủ sở hữu vừa ký vừa trả phí. Tất cả những gì chúng ta làm là gộp Approve -> Transfer vào một giao dịch nguyên tử duy nhất, không cần thêm hàm permit.
import { Connection, Keypair, PublicKey, Transaction } from "@solana/web3.js";
import {
createApproveInstruction,
createTransferInstruction,
getAssociatedTokenAddressSync
} from "@solana/spl-token";
const connection = new Connection("https://api.devnet.solana.com");
const owner = Keypair.generate();
const delegate = owner.publicKey;
const recipient = new PublicKey("DESTINATION_WALLET");
const mint = new PublicKey("TOKEN_MINT");
const amount = 1_000_000;
const ownerATA = getAssociatedTokenAddressSync(mint, owner.publicKey);
const recipientATA = getAssociatedTokenAddressSync(mint, recipient);
const ixApprove = createApproveInstruction(ownerATA, delegate, owner.publicKey, amount);
const ixTransfer = createTransferInstruction(ownerATA, recipientATA, owner.publicKey, amount);
const tx = new Transaction().add(ixApprove, ixTransfer);
tx.feePayer = owner.publicKey;
tx.recentBlockhash = (await connection.getLatestBlockhash()).blockhash;
tx.sign(owner);
const sig = await connection.sendRawTransaction(tx.serialize());
console.log("Sent (self-sponsored):", sig);2. Bên thứ ba trả phí (Chuyển tiền qua relayer)
Ở đây, người nắm giữ ký lệnh, nhưng một relayer (hoặc backend của dApp) chi trả phí SOL. Solana hỗ trợ điều này một cách gốc thông qua trường feePayer cùng với chữ ký từng phần.
import { Connection, Keypair, PublicKey, Transaction } from "@solana/web3.js";
import { createTransferInstruction, getAssociatedTokenAddressSync } from "@solana/spl-token";
const connection = new Connection("https://api.devnet.solana.com");
const owner = Keypair.generate(); // replace with real keypair
const feePayer = Keypair.generate(); // replace with real keypair
const recipient = new PublicKey("DESTINATION_WALLET");
const mint = new PublicKey("TOKEN_MINT");
const amount = 500_000;
const ownerATA = getAssociatedTokenAddressSync(mint, owner.publicKey);
const recipientATA = getAssociatedTokenAddressSync(mint, recipient);
const ix = createTransferInstruction(ownerATA, recipientATA, owner.publicKey, amount);
const tx = new Transaction().add(ix);
tx.feePayer = feePayer.publicKey;
tx.recentBlockhash = (await connection.getLatestBlockhash()).blockhash;
tx.partialSign(owner);
tx.sign(feePayer);
const sig = await connection.sendRawTransaction(tx.serialize());
console.log("Sent (relayer-sponsored):", sig);
Node lưu trữ toàn bộ dữ liệu và tham gia đồng thuận
- Ethereum: Archive Node
- Solana: [không áp dụng]
Node lưu trữ một phần dữ liệu và tham gia đồng thuận
- Ethereum: Full Node
- Solana: Consensus Node
Node lưu trữ một phần dữ liệu và không tham gia đồng thuận
- Ethereum: Light Node
- Solana: RPC Node