Problem connecting to GSN Web3 Provider

My app deployed, tested and worked with GSN fine with web3 0.20.x But now cannot find Provider HTTP connection with web3 v1.2.x. Web3 code was refactored and tested fine however with Truffle testing (which has it’s own internal web3). Right now I’m trying to simply connect to my working VPS deployed Ganache dev chain (v.6.9.) on port 9545 (with RelayHub and Relayer deployed and working with contracts deployed and Initialized with OZ Create)

However, any version of web3 1.2.x result in web console errors. My preference would be to use GSNprovider and web3 v1.2.1 (which seems prevalent in most OZ tooling).

Here,below for comment, are patterns I used followed by a snapshot of my package.json. (they are based on OZ Network.js, GSN and Starter kit Vanilla js documentation.

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
GSN:
import Web3 from 'web3'
import GSNProvider from '@openzeppelin/gsn-provider'
const web3 = new Web3(new GSNProvider("http://xxx.xxx.xxx.xxx:9545"))
as shown in GSN docs

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

WEB3:
import Web3 from 'web3'
const web3 = new Web3('http://xxx.xxx.xxx.xxx:9545')
or
web3 = new Web3(new Web3.providers.HttpProvider('http://xxx.xxx.xxx.xxx:9545'))

I get error console.log(web3.version) :
_stream_writable.js?dc14:57 Uncaught TypeError: Cannot read property 'slice' of undefined

If I omit import Web3 from 'web3'
console.log(web3.version) —>Object { api: "0.20.7", node: Getter...

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

NETWORK JS:
import { fromInjected, fromConnection } from '@openzeppelin/network'

 web3Context = await fromConnection('http://xxx.xxx.xxx.xxx:9545', {
      gsn: { signKey: ephemeral() }
      });

      this.accounts = web3Context.accounts
      this.networkId = web3Context.networkId //etc..

web console error:
SyntaxError: missing : after property id....["./node_modules/@openzeppelin/network/lib/context/Web3Context.js"]()

line 46: async poll() {
// TODO: Fiture out elegant way retrive property name dynamically const networkIdName = 'networkId'; const accountsName = 'accounts'; const connectedName = 'connected';....

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

Node 10.16.3
Package.json deps:

 "dependencies": {
    "@openzeppelin/gsn-provider": "^0.1.6",
    "@openzeppelin/network": "^0.4.2",
    "vue": "^2.5.13",
    "vue-router": "^3.0.1",
    "vuex": "^3.0.1",
    "web3": "^1.2.1"
  },
  "devDependencies": {
    "@openzeppelin/cli": "^2.8.2",
    "@openzeppelin/gsn-helpers": "^0.2.3",
    etc..
2 Likes

Hi @Steeve,

It may be worth running through Building a GSN-powered DApp and connecting to your setup to track down the issue.

Prior to updating my web3 from v0.20 to v1.2.1 my Dapp connection to GSN relayer worked fine without import or require GSNProvider in my code. Now, with web3 v 1.x.x, the line:
import Web3 from 'web3' is what gives me scrypt related errors. I had to comment out every web3 related line in my code to discover that. In fact, any package that imports web3 resulted in errors. Until instead i imported web3.min.js directly in my code from my node_modules/web3 folder. Then i get a connection at browser page load console.log(web3.version) --> 1.2.1

I also noticed scrypt package error messages at compile time.

It may be also that Yarn isn’t updating scrypt because of nodr version mismatch. I use Node 10.16.3

1 Like

@abcoathup After chasing down errors it seems many are resolved by upgrading web3 to >v.1.2.2 . Which I have done however Openzeppelin/cli is using truffle-provider with a web 1.2.1 dependency.

npm list web3
....
+-- @openzeppelin/cli@2.8.0-rc.0
| +-- @openzeppelin/upgrades@2.8.0-rc.0
| | `-- web3@1.2.2  deduped
| +-- truffle-config@1.1.16
| | `-- truffle-provider@0.1.16
| |   +-- truffle-interface-adapter@0.2.5
| |   | `-- web3@1.2.1 
| |   `-- web3@1.2.1 
| +-- typechain-target-web3-v1@1.0.4
| | `-- web3@1.2.6 
| `-- web3@1.2.2  deduped
+-- @openzeppelin/gsn-helpers@0.2.3
| `-- web3@1.2.6 
+-- @openzeppelin/gsn-provider@0.1.10
| `-- web3@1.2.6 
`-- web3@1.2.2 

Is there a simple hack to force update truffle-provider to web3 v1.2.2+?

1 Like

One thing I noticed is that you are using OpenZeppelin CLI 2.8 rc.0

The CLI is now at 2.8.2. You may want to update.