i want to do a transaction in ethereum from account A but the transaction fee should be paid from account B. is it possible in ethereum?
-
HI. Have any updation for your issue now...? – salman faris Oct 25 '19 at 10:16
-
Now we are at the end of the 2020. Are there any solutions for this problem yet? – captainblack Oct 17 '20 at 17:25
6 Answers
Currently, there isn't any in-built provision to allow other users to pay the gas fees for a particular transaction. However, the concept of a contract paying the gas fees by refunding the user exists and can be implemented. This, of course, opens the possibility of attacks on this function to deplete the funds.
There is an ongoing discussion here for a future release (Serenity) that can work around the concept of only the account sending the transaction paying the fees.

- 31
- 4
There is no built-in support in ethereum for that functionality. But there is a popular approach for that problem called Gas Station Network aka GSN. OpenGSN (https://opengsn.org/) provides an implementation. To quickly grasp the idea, read (now depricated) https://docs.openzeppelin.com/learn/sending-gasless-transactions
Let me just quote the relevant part from OZ docs:
This is a fancy name for a simple idea: a third-party (called a relayer) can send another user’s transactions and pay themselves for the gas cost. In this scheme, users sign messages (not transactions) containing information about a transaction they would like to execute. Relayers are then responsible for signing valid Ethereum transactions with this information and sending them to the network, paying for the gas cost. A base contract preserves the identity of the user that originally requested the transaction. In this way, users can interact directly with smart contracts without needing to have a wallet or own Ether.
This means that, in order to support meta transactions in your application, you need to keep a relayer process running - or leverage a decentralized relayer network.

- 31
- 2
There is no native support for that in the Ethereum network.
However THIS particular issue has been actively discussed for a while now.
Though the issue above discusses mainly about account B
doing token transfer for the account A
and earning some tokens for account B
as a fee.
A user has even mentioned a full working example at http://lavawallet.io

- 917
- 1
- 11
- 20
As of now, It is possible with Permit
function. This kind of transaction is also called gasless transaction
.
With erc20 in order to send token, we have to approve the transaction first to allow an address to transfer, and then we call transferFrom
. with permit, instead of calling two functions we are going to call only one function.
For gas-less transaction, we are going to sign the transaction off-chain so that we are not going to pay any gas fee. Then we send the v,r,s
of the signatures to Permit function, and after some checks, if we pass the all the checks, permit()
will call approve
to the transaction and then spender will be able to execute the transaction.
this is from Uniswap ERC721Permit.sol
function permit(address spender,uint256 tokenId,uint256 deadline,uint8 v,bytes32 r,bytes32 s
) external payable override {
// set a deadline for the transaction
require(_blockTimestamp() <= deadline, 'Permit expired');
bytes32 digest =
keccak256(
abi.encodePacked(
'\x19\x01',
// DOMAIN_SEPARATOR a hash value that calculated to ensure uniquness of the signature
DOMAIN_SEPARATOR(),
keccak256(abi.encode(PERMIT_TYPEHASH, spender, tokenId, _getAndIncrementNonce(tokenId), deadline))
)
);
address owner = ownerOf(tokenId);
require(spender != owner, 'ERC721Permit: approval to current owner');
// this function uses assembly extcodesize func to check if the adddress is a contract
if (Address.isContract(owner)) {
require(IERC1271(owner).isValidSignature(digest, abi.encodePacked(r, s, v)) == 0x1626ba7e, 'Unauthorized');
} else {
address recoveredAddress = ecrecover(digest, v, r, s);
require(recoveredAddress != address(0), 'Invalid signature');
require(recoveredAddress == owner, 'Unauthorized');
}
// after passing all the checks,we approve the spender to transfer the token
_approve(spender, tokenId);
}
}
You can read EIP712

- 35,338
- 10
- 157
- 202
This can be done only if the wallet is a contract. in general there are 2 types of accounts
- accounts with private key (normal wallet)
- accounts without private key( contract wallets)
we can achieve your target with contract address, users deposit and can do any thing, later if we want to make a transaction of withdraw or transfer, user pays the transaction fee where in result the funds move from contract wallet to other wallet.

- 51
- 2