How to use GSN Provider in tandem with standard web3 provider

@PaulRBerg asked in Telegram how to use GSN Provider in tandem with a standard web3 provider.

To use GSN Provider with another provider you can either:

  1. Use multiple providers OR
  2. Use a single GSN provider and enable GSN support selectively

Single GSN Provider

You can use a single GSN Provider with useGSN set to false, and enable GSN support selectively:

const gsnProvider = new GSNProvider('http://localhost:8545', { useGSN: false });

// Sends a regular transaction
await myContract.methods.myFunction().send({ from });

// Sends the transaction via the GSN
await myContract.methods.myFunction().send({ useGSN: true });

The useGSN flag on construction can also be a function that receives a payload, so you can put your logic there. We don’t have guides featuring this yet, but you can look at the provider options in the config section of the readme: https://github.com/OpenZeppelin/openzeppelin-gsn-provider#configuration

1 Like