trust-web3-provider: web3.js v1 not working with Trust Wallet

Can be refer to #3

Currently, I had issue making the code work in TrustWallet, if I write in vanilla js (without webpack or babel), it will work. ( Links to the testing, Code )

I used truffle box to generate a new react project to regenerate the problem.

Version

  • truffle v5.0.5
  • web3 v1.0.0-beta.37
  • TrustWallet Android v1.6.276

Create project

$ npm install -g truffle
$ truffle unbox react
$ cd client
$ yarn
# Change the code in "/src/App.js"
$ yarn dev

On trust wallet, this is what I got:

screenshot_2019-02-27-15-35-04

I added a repo to reproduce this bug. (I tweak a bit of code in “src/App.js”), https://github.com/superoo7/trustwallet-web3-bug

Possible reason

  • Web3 version for Trust Wallet is not v1 yet
  • Babel/Webpack transpile code of async await

About this issue

  • Original URL
  • State: closed
  • Created 5 years ago
  • Comments: 18 (8 by maintainers)

Most upvoted comments

@superoo7 Hi, we’re using web3 0.20.x, it’s not compatible with 1.0 right now

@HoangJerry web3 is quite unstable by nature, we will wait until the final version is released and then adopt, web3 developers tend to break it every other release

Calling async methods is the best practice for using web3.

Trust wallet should be working at ethers.js, if this issue can be fixed. https://github.com/ethers-io/ethers.js/issues/489

Trust wallet should work with web3 1.0 and ethers.js as soon as possible or many new dapps will not work at Trust wallet.

@codydjango readme updated

I tried wrap the function with Promises (error first approach), it still getting that error. The only way i manage to make it work is via “window.web3” with older web3js API (0.20.x)

  public getId(): Promise<number> {
    return new Promise((resolve, reject) => {
      // v1
      this.web3.eth.net.getId((err1, res1) => {
        if (err1) {
          // < v1
          (window.web3!.version as any).getNetwork((err2: any, res2: any) => {
            if (err2) {
              reject(err2);
            }
            resolve(res2);
          });
        } else {
          resolve(res1);
        }
      });
    });
  }