delete
delete

Reputation: 19168

How to create gasless-transactions/meta-transaction using ethers.js?

How can I implement a meta-transaction using ethers.js library or at least have another account paying a transaction, which was signed by different account?

Consider a transaction to transfer 100 ERC20-tokens using a ERC20-contract from 0xAccountA to 0xAccountB. The transaction will be signed by 0xAccountA but the gas would be payed by some other 0xAccountC.

Lets initiate a contract:

const abi = ['function transferFrom(address sender, address recipient, uint256 amount)'];

const payer = new ethers.Wallet(privKey, provider);
const contract = new ethers.Contract(contractAddress, abi, payer);

Currently, we create transactions like this;

const contractWithFromAsSigner = contract.connect(from);
const tx = await contractWithFromAsSigner.transferFrom(from, to, amount);

In this case, from has to sign the transaction and is also paying for the transaction.

What I'd like to achieve is that from is signing this transaction, but payer is paying and really broadcasting the transaction, which was signed by from, but paid by payer.

How can I do that?

Upvotes: 2

Views: 756

Answers (1)

Mohamed Sohail
Mohamed Sohail

Reputation: 1867

You are roughly trying to describe a relayer manager. You can have it on-chain. Afaik there aren't many implementations but you can check these resources which have implemented it (EIP 1077) and modify it to your use case:

Your ethers.js would then call the execute fn of the relayer contract.

Upvotes: 2

Related Questions