ERC-1613 · Draft · ERC · 2018-11-18
ERC-1613: Gas Stations Network
The Gas Station Network: relayers pay gas for users' signed requests and are reimbursed from a dapp's or paymaster's deposit, so people without ETH can still use contracts.
What problem does it solve?
To call a contract you need ETH for gas. For a new user that means buying ETH on an exchange before they can even try a dapp, which is a major drop-off point. Dapp owners often would happily pay those fees themselves, or let users pay by card, but Ethereum transactions must be paid by the sender.
The Gas Station Network (GSN) lets a contract accept "collect calls". A user signs a request off-chain, a relay server submits it and pays the gas, and the relay is reimbursed (plus a fee) from a deposit that the dapp or a sponsor has placed on-chain. It needs no protocol change.
How it works
- A dapp owner or sponsor deposits ETH into the RelayHub, earmarked for the contract that will pay.
- A sender with no ETH signs a request describing the call.
- A relay picks up the request, checks it will be paid, and submits it to the hub, paying gas.
- The hub checks signature and nonce, asks the payer to accept, performs the call with the sender's address attached, then pays the relay from the deposit.
- The recipient contract sees the call as coming from the sender, not the relay.
Relays stake ETH in the hub. Misbehaviour that can be proven on-chain (such as signing two transactions with the same nonce) lets anyone claim part of the stake. As long as one honest relay exists, requests cannot be censored.
The spec covers two versions:
| Version 1 | Version 2 | |
|---|---|---|
| Who decides to pay | Recipient's acceptRelayedCall |
Separate Paymaster contract |
| Signature and replay protection | Nonce in RelayHub |
Forwarder (EIP-712, ERC-2771) |
| Reading the real sender | getSender() |
_msgSender() from the last 20 bytes of calldata |
| Stakes | In RelayHub |
In a StakeManager |
Sample code
A Version 2 style recipient that trusts one forwarder and reads the real sender per ERC-2771:
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.20;
contract Counter {
address public immutable trustedForwarder;
mapping(address => uint256) public count;
constructor(address forwarder) { trustedForwarder = forwarder; }
function isTrustedForwarder(address f) public view returns (bool) {
return f == trustedForwarder;
}
function _msgSender() internal view returns (address sender) {
if (msg.sender == trustedForwarder && msg.data.length >= 20) {
assembly { sender := shr(96, calldataload(sub(calldatasize(), 20))) }
} else {
sender = msg.sender;
}
}
function increment() external {
count[_msgSender()] += 1; // credited to the user, not the relay
}
}
Who pays is decided by a separate paymaster, which implements preRelayedCall (revert to reject) and postRelayedCall, and keeps a deposit in the hub.
Things to know
- Status: Draft. The text describes the deployed GSN v1 and v2 systems, but the standard itself is not final.
- A recipient must only trust a forwarder it controls or has audited: a trusted forwarder can impersonate any sender.
- Paymasters carry real financial risk. Accepting anonymous requests invites relays or users to drain the deposit; whitelists, signed approval data and gas-price limits are the usual defences.
- ERC-4337 account abstraction later introduced its own paymaster concept for smart accounts, and is now the more common path to gasless UX.