---
eip: 2771
label: ERC-2771
title: Secure Protocol for Native Meta Transactions
status: Final
type: Standards Track
category: ERC
created: 2020-07-01
official: https://eips.ethereum.org/EIPS/eip-2771
source: https://github.com/ethereum/ERCs/blob/master/ERCS/erc-2771.md
canonical: https://eips.huatuo.xyz/eip-2771/
lang: en
tldr: "A contract-level convention for gasless meta-transactions: a trusted forwarder appends the real signer's address to calldata, and the recipient reads it with _msgSender() instead of msg.sender."
tags: [meta-transactions, gasless, relayer, forwarder, ux]
---

# ERC-2771: Secure Protocol for Native Meta Transactions

> A contract interface for receiving meta transactions through a trusted forwarder

**TL;DR:** A contract-level convention for gasless meta-transactions: a trusted forwarder appends the real signer's address to calldata, and the recipient reads it with _msgSender() instead of msg.sender.

## What problem does it solve?

A user who holds tokens but no ETH cannot pay for gas, so they cannot interact with a contract. A **meta-transaction** solves this: the user signs a request off-chain, and a third party (a *gas relay*) submits it on-chain and pays the gas.

The catch is `msg.sender`. When the relay submits the call, the contract sees the relay (or a forwarder contract) as the sender, not the user. ERC-2771 standardises how the real signer's address is passed through securely, and how wallets can discover that a contract supports this, without any protocol change.

## How it works

Four roles:

- **Transaction Signer**: the user who signs the request.
- **Gas Relay**: an untrusted party that pays gas and submits the transaction.
- **Trusted Forwarder**: a contract that verifies the user's signature and nonce, then calls the recipient.
- **Recipient**: your contract.

The forwarder **must** append the signer's 20-byte address to the end of the calldata. The recipient then:

1. checks that `msg.sender` is a forwarder it trusts;
2. if so, and calldata is at least 20 bytes, reads the last 20 bytes as the real sender;
3. otherwise, uses `msg.sender` as usual.

Contracts expose this through `_msgSender()` (and `_msgData()`, which strips the suffix) and must implement:

```solidity
function isTrustedForwarder(address forwarder) external view returns (bool);
```

It must not revert and should use less than 50,000 gas, so wallets and other contracts can query it.

## Sample code

A recipient with one immutable trusted forwarder (OpenZeppelin ships the same logic as `ERC2771Context`):

```solidity
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.20;

contract Recipient {
    address private immutable _trustedForwarder;
    mapping(address => uint256) public points;

    constructor(address forwarder) { _trustedForwarder = forwarder; }

    function isTrustedForwarder(address forwarder) public view returns (bool) {
        return forwarder == _trustedForwarder;
    }

    function _msgSender() internal view returns (address signer) {
        signer = msg.sender;
        if (msg.data.length >= 20 && isTrustedForwarder(signer)) {
            assembly { signer := shr(96, calldataload(sub(calldatasize(), 20))) }
        }
    }

    function claim() external {
        points[_msgSender()] += 1; // credited to the user, not the relayer
    }
}
```

On the forwarder side, the call looks like:

```solidity
(bool ok, ) = to.call{value: value, gas: gasLimit}(abi.encodePacked(data, from));
```

## Things to know

- **Status: Final.**
- Trusting a forwarder means trusting it with every user's identity: a malicious or buggy forwarder can make `_msgSender()` return any address. Keep the trusted set immutable if possible, and treat an upgradeable forwarder as part of your trust base.
- If the set of trusted forwarders can change, only the contract owner should be able to change it; otherwise an attacker can add their own forwarder and impersonate anyone.
- Combining ERC-2771 with `multicall`/`delegatecall` batching has caused real address-spoofing bugs, because inner calls can carry an attacker-controlled 20-byte suffix. Use library versions that handle this.
- For new designs, smart accounts ([ERC-4337](/eip-4337/), [EIP-7702](/eip-7702/)) with paymasters achieve gasless UX without each contract needing to support a forwarder. For token approvals alone, [ERC-2612](/eip-2612/) `permit` is simpler.


---

This is an unofficial plain-language summary. Read the full specification: https://eips.ethereum.org/EIPS/eip-2771
