Enabling an ERC20 and a contract receiving the ERC20 token for Gas Station Network

Hi @Moun,

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

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.


Alternatively to ERC20 you could look at creating ERC777 tokens (no need to do approve and transferFrom in two separate transactions). See the documentation for details: https://docs.openzeppelin.com/contracts/2.x/tokens#ERC777

To use the GSN, the ERC777 token would need to be GSN enabled.


To make a contract GSN enabled the contract would need to inherit from GSNRecipient and include functionality to decide which relayed calls to accept. I suggest reading the documentation on Writing GSN-capable contracts:
https://docs.openzeppelin.com/contracts/2.x/gsn

When looking at enabling a contract for the Gas Station Network, I recommend also looking at the documentation for GSN Bouncers on how to approve GSN relay calls.

@Dennison has created a tutorial on using GSNBouncerSignature: Advanced GSN: GSNBouncerSignature.sol

1 Like