ERC20 with GSN

Hello. How to do it right?

pragma solidity ^0.5.0;

import "@openzeppelin/contracts-ethereum-package/contracts/token/ERC20/ERC20.sol";
import "@openzeppelin/contracts-ethereum-package/contracts/token/ERC20/ERC20Detailed.sol";
import "@openzeppelin/contracts-ethereum-package/contracts/token/ERC20/ERC20Mintable.sol";
import "@openzeppelin/upgrades/contracts/Initializable.sol";
import "@openzeppelin/contracts-ethereum-package/contracts/GSN/GSNRecipient.sol";

contract GLDToken is Initializable, ERC20, ERC20Detailed, ERC20Mintable, GSNRecipient {
    function initialize(uint256 initialSupply) public initializer {
        ERC20Detailed.initialize("Gold", "GLD", 18);
        _mint(_msgSender(), initialSupply);
    }

    function acceptRelayedCall(
        address relay,
        address from,
        bytes calldata encodedFunction,
        uint256 transactionFee,
        uint256 gasPrice,
        uint256 gasLimit,
        uint256 nonce,
        bytes calldata approvalData,
        uint256 maxPossibleCharge
    ) external view returns (uint256, bytes memory) {
        return _approveRelayedCall();
    }

    // We won't do any pre or post processing, so leave _preRelayedCall and _postRelayedCall empty
    function _preRelayedCall(bytes memory context) internal returns (bytes32) {
    }

    function _postRelayedCall(bytes memory context, bool, uint256 actualCharge, bytes32) internal {
    }
}

Select which function * initialize()
npx oz-gsn fund-recipient --recipient 0x46418e2df00C9Dc013C67f7169e0154DFb25e0d1

But, I do not have "ERC20Detailed" the data my token

or

Select which function * initialize(initialSupply: uint256)
npx oz-gsn fund-recipient --recipient 0x46418e2df00C9Dc013C67f7169e0154DFb25e0d1

I have a mistake: " The relay hub address is set to zero in recipient at.."

How should I do it right? To mint called and ERC20Detailed. And with the GSN on?

Thx

1 Like

Hello @Casper!

The issue you’re facing is caused by your contract not being fully initialized: you are missing the initialize calls for ERC20Mintable and (more importantly) GSNRecipient, which should be added to your own initialize function.

Once you’ve called all initializers, you will be able to use the oz-gsn commands to interact with your contract.

2 Likes

Thanks, I just added GSNRecipient.initialize();

1 Like