Welcome to the community forum . Thanks for posting your question here.
I was curious why you were only covering
transferFrom. I would have thought that end users would be using transfer and either approve or increaseAllowance with users calling other contracts which would then would call
- Does extending GSNRecipient means that all function calls will automatically attempt ‘relaying’?
If your token inherits from GSNRecipient then all functions can be called via the GSN. Your contract should then decide which calls you are willing to pay for.
I recommend reading the Writing GSN-capable contracts documenation.
I also suggest having a look at GSN Bouncers documentation on ways to decide which relayed calls to accept.
GSNBouncerSignature appears to be a potential option for you.
- Is it possible to get the function that is being relayed from the encodedFunction argument passed into the acceptRelayedCall callback? If yes, how do I get the function name? (This way I can check if it’s a transferFrom or transfer call and make a decision based on that)
You can get the function name in
encodedFunction is the relayed call calldata, so its first four bytes are the function selector.
If you use
GSNBouncerSignature you can decide whether to sign or not sign the relayed call parameters (including based on the
There is a tutorial on using off-chain signing to approve relayed calls with: Advanced GSN: GSNBouncerSignature.sol
- Even if 2. is possible, I still don’t know how to make sure all other calls are treated normally (i.e not relayed)
Your contract (or off-chain signing) will need to use your logic to decide which relayed calls to accept. So you can reject relayed calls for any function that you don’t want to pay for.
- Maybe I’m getting it wrong and the dApp doesn’t attempt to call my contract at all. I think I read something about the call to the relayer being something that happens offchain. Is this the case?
Your dapp can call a GSN relayer (for functions that it wants to use the GSN for) which will then relay the calls (that your contract accepts based on its business logic).
Your dapp call call a function using injected Web3 (e.g. MetaMask) for functions that you don’t want to pay for.
If you haven’t already, I recommend playing with the GSN Starter Kit
Feel free to ask all the questions that you need.