GSN with ERC20 Compliant Smart Contract

I am trying to transfer ERC20 tokens from one address to another address with no ether via OpenZeppelin GSN.

:computer: Environment
@openzeppelin/gsn-provider”: “^0.1.9”,
@openzeppelin/gsn-helpers”: “^0.2.1”,

I’m following the tutorial here: And I have successfully done everything required (though locally on Ganache). But i’m facing a problem. I am building an ERC20 compliant smart contract. And i need to call approve() before calling transferFrom() but if I call the approve() function it returns "Error: Could not get relay hub address from recipient at ". And i guess the reason is because the ERC20 token is not configured to accept relayed calls. But i can’t call the transferFrom() function because it will revert. Please, how do i go about this problem with GSN?

Note: For now (development phase), i am developing both the ERC20 token and contract transferring the token. But in production, i would use ERC20 tokens already deployed.

:1234: Code to reproduce
Implement ERC20 compliant smart contract that transfers tokens from an address to another address with transferFrom

1 Like

Hi @sirphemmiey,

Welcome to the community forum :wave: Thanks for posting your question here.

The issue is that the ERC20 token is not GSN enabled.

To use an ERC20 token with a contract receiving tokens requires two transactions:

  1. Approve : The user calls approve to set an allowance for the ERC20 token to use with the contract receiving tokens. (or use increaseAllowance )
  2. Transfer From : The user calls the contract which then calls the ERC20 token transferFrom function to transfer an amount of ERC20 token to the contract receiving tokens.

If only the contract is GSN enabled, then users would still need to have Ether to call approve to set an allowance.

Otherwise for users not to require Ether, both the ERC20 token and the contract receiving tokens would both need to be GSN enabled. This would still require two transactions.

Is there a specific ERC20 token that you are looking at?
How will your users obtain the ERC20 tokens?

One potential solution (depending on the token and how they obtain it) could be: