Sign GSN relayed call with MetaMask

I was asked if you can sign a Gas Station Network relayed call with a different key e.g. MetaMask account, rather than an Ephemeral Key. (but still have the transaction relayed via the Gas Station Network).

I assume it is possible, though I don’t know what the setup needs to be.

In the GSN Starter Kit which uses an Ephemeral Key the code is as follows:
App.js:

  const signKey = useEphemeralKey();

  // get GSN web3
  const context = useWeb3Network(`wss://rinkeby.infura.io/ws/v3/${infuraToken}`, {
    pollInterval: 15 * 1000,
    gsn: {
      signKey,
    },
  });

Counter component index.js:

const tx = await instance.methods.increaseCounter(number).send({ from: accounts[0] });
1 Like

The solution to use Injected web3 (e.g. MetaMask) for signing is to set the web3 context to useWeb3Injected with GSN true.

  const context = useWeb3Injected({gsn: true});
2 Likes

A post was split to a new topic: How would you add approveFunction to GSN call?