0

Actually I'm trying to figure out the best way to implement gasless call to transferFrom of a ERC-20 token.

I'm not very familiar with GSN so maybe it could be a best way to achieve this.

I wrote a smart contract with ERC2771Recipient and I call the transferFrom function from myToken ERC-20 contract.

This is the contract:

// SPDX-License-Identifier: MIT
pragma solidity ^0.8.7;

import "@opengsn/contracts/src/ERC2771Recipient.sol";
import "./token.sol";

contract MyContract is ERC2771Recipient {
    event TransferredFromTokenGSN(address from, address to, uint256 amount);

    token public myToken;

    constructor(address _trustedForwarder, address _Token) {
        _setTrustedForwarder(_trustedForwarder);
        myToken = Token(_Token);
    }

    function transferFromTokenGSN(address from, address to, uint256 amount) external {
        myToken.transferFrom(from, to, amount);

        emit TransferredFromTokenGSN(from, to, amount);
    }
}

The problem obviously is that the msg.sender and so the spender of the transferFrom function is the myContract address instead of the original address that submit the transaction.

Any suggestions to set the original wallet address as spender of the transferFrom function?

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.