How to whitelist functions within preRelayedCall

I would like to write a require statement in preRelayedCall to only accept calls to certain functions on my BaseRelayRecipient. Is there a way to do this? Or do I need to split out my functionality into a new contract?

Add this to your preRelayedCall:

function preRelayedCall(...) {

  bytes4 sig = GsnUtils.getMethodSig(;
  require(sig == MyContract.myMethod.selector, "calling wrong method" );
1 Like

Actually what we want here is to use .selector and not .signature.

require(sig == MyContract.myMethod.selector, "calling wrong method" );

of course, you’re right. thank you for correcting my typo…
“myMethod.signature” was a typo, and it should be “myMethod.selector”

In this case, would my Paymaster still be charged even if it rejects the call? Or could this be possible in some other examples, if not so for this one? Because some users could keep calling it and empty the Paymaster balance.