Paymaster-fund: Cannot read properties of undefined (reading 'balanceOf')

Hi,
I tried to run npx gsn paymaster-fund as described at last step in command-line tools documentation.
It gives me the error:

TypeError: Cannot read properties of undefined (reading 'balanceOf')
    at ContractInteractor.hubBalanceOf (/Users/vanadain/work/gsn/node_modules/@opengsn/cli/node_modules/@opengsn/common/src/ContractInteractor.ts:665:40)
    at CommandsLogic.fundPaymaster (/Users/vanadain/work/gsn/node_modules/@opengsn/cli/src/CommandsLogic.ts:173:58)
    at /Users/vanadain/work/gsn/node_modules/@opengsn/cli/src/commands/gsn-paymaster-fund.ts:29:31
    at Object.<anonymous> (/Users/vanadain/work/gsn/node_modules/@opengsn/cli/src/commands/gsn-paymaster-fund.ts:31:3)

Then I actually checked this function at ContractInteractor and console.log some information, it helped me to realize that this.relayHubInstance is undefined.

After that I copied code that was creating this instance with _createRelayHub function. And instance was successfully created… But

Next time, when I ran this cli command I got error:

Error: execution reverted
    at /Users/vanadain/work/ecr20_gsn/node_modules/@truffle/hdwallet-provider/node_modules/web3-provider-engine/subproviders/provider.js:18:36
    at XMLHttpRequest.request.onreadystatechange (/Users/vanadain/work/ecr20_gsn/node_modules/web3/node_modules/web3-providers-http/lib/index.js:98:13)
    at XMLHttpRequestEventTarget.dispatchEvent (/Users/vanadain/work/ecr20_gsn/node_modules/xhr2-cookies/xml-http-request-event-target.ts:44:13)
    at XMLHttpRequest._setReadyState (/Users/vanadain/work/ecr20_gsn/node_modules/xhr2-cookies/xml-http-request.ts:219:8)
    at XMLHttpRequest._onHttpResponseEnd (/Users/vanadain/work/ecr20_gsn/node_modules/xhr2-cookies/xml-http-request.ts:345:8)
    at IncomingMessage.<anonymous> (/Users/vanadain/work/ecr20_gsn/node_modules/xhr2-cookies/xml-http-request.ts:311:39)

And now I’m stuck, because I don’t understand at all why execution is reverted.
Address of relayHub is also correct. What can be the problem?

Thanks a lot for your help!

The simplest way to fund a paymaster is to send ether directly to its address.
Note that if you later check its balance it will be zero - because it automatically deposit it into the RelayHub
Also, it will reject the transfer of the RelayHub is not set properly

(we will also look at the problem you describe in the command line tool)

I sent directly to paymaster as you said, and it works!!!
Thank you very much @drortirosh !