Running relayer on custom network?

The Issue -
is there a way to run npx oz-gsn run-relayer command with a custom node? I understand there is a flag i can use, which is --ethereumNodeURL but its execution gives me the following error -

Could not connect to node (Error: Found no accounts with sufficient balance (10000000000000000000 wei)).

is there some way i could specify my account details here? giving in just the address in --from flag doesnt work.

I was wondering if there is some way npx oz-gsn run-relayer command could pick the network object from networks.js file from the directory?

What I am trying to do -
I’d like to use GSN in a DApp deployed on a public network - Matic network, RPC for which is https://testnet2.matic.network
I understand a Relayer contract is required to be deployed on this network and as far as the docs have guided me, the oz-gsn tool has commands for the same (gsn-helpers). I’m just stuck on how to use this tool to deploy and run a relayer on a custom network.

1 Like

Hi @nglglhtr,

Welcome to the community :wave:

My understanding is that you could use npx oz-gsn run-relayer with a local ethereum node.

Are you running a node for the Matic testnet? (I am not familiar with Matic, so not sure how this works).

To use GSN on a custom network I assume you will need to do at least the following:

  • Run a relayer process
  • Deploy a new relay hub
  • Register a relayer in the hub
  • Fund a recipient contract in the hub

Tagging @lukaslukac as he successfully set this up on the Lightstream’s network.

Hey @abcoathup! :grin:
i’m not running a node, Matic is a public network (ethereum plasma side chain) - that i’d like to connect to.
So the end goal is to enable meta transactions on matic network using GSN. For which i believe at the minimum i’d need

  1. A running relayer on a host (off-chain)
  2. the relay hub contract
  3. and working relayer in the network.

:question: Questions:

  • the documentation say there is supposed to be a single address for the relay hub contract on all networks - was wondering if that will be true for networks where it isn’t deployed yet ie., Matic network?
  • let’s say we have deployed a relay hub contract on matic, now for the requirement of a relayer on matic - is it the registerRelayer command i have to use?

I may be missing something here, about the process, please correct me if i’m wrong :slight_smile:

1 Like

Hi @nglglhtr,

I have only used the GSN on ganache-cli and on Rinkeby.
I haven’t tried this on a public network that didn’t already have the RelayHub deployed.

I will need some help from the community on answering your questions.

the documentation say there is supposed to be a single address for the relay hub contract on all networks - was wondering if that will be true for networks where it isn’t deployed yet ie., Matic network?

I assume the same process that was used to deploy on other public networks to get a single address can be used to have the same address on any Ethereum based network.

let’s say we have deployed a relay hub contract on matic, now for the requirement of a relayer on matic - is it the registerRelayer command i have to use?

Yes, though there are multiple steps here according to the EIP: https://eips.ethereum.org/EIPS/eip-1613
My understanding is that this is what the GSN Helpers do for a local network and the tools https://gsn.openzeppelin.com/recipients and https://gsn.openzeppelin.com/relays do for a public network.

1 Like

Okay, so this process is something GSN does for developers on different networks or are there certain steps I’d need to follow to deploy an instance of RelayHub on Matic?

So i guess the first step would be to get a RelayHub contract instance on Matic, then:

  • a running relayer
  • register that relayer with RelayHub

Is that correct?

1 Like

You will need to create the RelayHub on the Matic network.
Then run a relayer.
Then register the relayer.

In the meantime, if you haven’t already I suggest trying the GSN Starter Kit
https://docs.openzeppelin.com/starter-kits/2.3/gsnkit

1 Like

Hey, thank you for being so responsive :smiley:

Can you guide me through the steps i’d need to take for that?

This is something off-chain right?

1 Like

Hi @nglglhtr,

For using GSN on a testnet, you should run a real relayer, and not the script via gsn-helpers, since it’s meant to be used for local development or testing.

Deploy RelayHub

You can build your own script, importing the gsn-helpers.

You should create a simple JavaScript file that creates a new web3 object, pointing to the Matic network, and using an offline signer: this could be either by using the hdwallet provider, or by registering the private key on the web3 object (see https://web3js.readthedocs.io/en/v1.2.2/web3-eth-accounts.html#wallet-add).
Once you have a web3 object, you can just import the gsn-helpers package, and call deployRelayHub:

Run a Relayer

Next step would be to run a relayer.

That’s a matter of downloading the latest binary for your operating system from https://github.com/OpenZeppelin/openzeppelin-gsn-helpers/releases and running it, making sure its URL is reachable by you.

If you want to run it on a server for the entire Matic network, (which would be awesome by the way), and you need help with the setup, this guide could help:

Register the Relayer

Then you need to register the relayer.

Same as before: if you set up a JavaScript file that initializes the web3 object with a signer, you can call into the gsn-helpers registerRelay method:

Fund dapp (Recipient contract)

Finally, you need to fund their app (i.e. recipient contract).

You need to do the same as the previous step, but this time calling into fundRecipient:


Alternatively, you could just modify the commands so they can receive another option (like a private key or mnemonic) and use it to create a web3 object that has offline signing.

You would need to change the new web3(...) line on every command (e.g. https://github.com/OpenZeppelin/openzeppelin-gsn-helpers/blob/master/oz-gsn-fund-recipient.js#L14).

If you were to create such a PR, then this could be merged, so you wouldn’t need to build your own scripts.

1 Like

Awesome! @abcoathup, Thank you for this answer, gonna try this out super soon. Thank you so much. Will report back on this thread if I stumble upon something :smiley:

1 Like

hey! @abcoathup,
was having some trouble in the second step,

I’m using macOS Catalina (v10.15.1), could you guide me through the steps to installing the binary?

1 Like

Also, was wondering, if running a relayer is only about getting a reachable URL - is it independent of the network RelayHub is deployed on?
if yes, then is there a general purpose Relayer available, URL for which can be used directly?

1 Like

Will answer in: Running a Relayer