简体   繁体   中英

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?

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM