2

I am working on a react application and just can't catch the web3 object of mobile wallets. Catching web3 in Metamask works like a charm.

Here's my code so far:

componentDidMount() {
    window.addEventListener("load", () => {
      let web3 = window.web3;
      if (web3) {
        web3 = new Web3(web3.currentProvider);
        web3.eth.getAccounts().then(accts => {
          web3.eth.net.getNetworkType().then(network => {
            this.setState({
              web3,
              isConnected: true,
              network: network,
              user: accts[0]
            });
          });
        });
      }
    });
  }

So far I've tried Trust Wallet and Status Wallet and none of both works with the existing code.

I have also tried to user web3.currentProvider.isTrust but that doesn't seem to work either.

Edit: I also tried to set an interval to check for the web3 object every few seconds. But that didn't work either.

Edit 2: Since I'm using web3js 1.x I tried the following:

componentDidMount() {

  window.addEventListener("load", () => {
    if (Web3.givenProvider) {
      let web3 = new Web3(Web3.givenProvider);
      alert(web3.currentProvider.host);
      console.log(web3.currentProvider);
      web3.eth.getAccounts((err, accts) => {
        if (!err) {
          web3.eth.net.getNetworkType((err, network) => {
            if (!err) {
              this.setState({
                web3,
                isConnected: true,
                network: network,
                user: accts[0]
              });
            } else {
              alert(err);
            }
          });
        } else {
          alert(err);
        }
      });
    }
  });
}

As you can see I'm trying to get error messages with the alerts. Now status responds with You tried to send "undefined" synchronously. Synchronous requests are not supported, sorry. I don't get it. This is not a synchronous request?!

Trust also tells me Error: Trust does not support calling undefined synchronously without a callback parameter to call undefined asynchronously..

1 Answer 1

2

Trust doesn't support 1.0 beta, no ETA either. I suppose the android/ios bindings they use still haven't been updated. https://github.com/TrustWallet/trust-web3-provider/issues/58.

Edit: I found the code that explains the supported methods: https://github.com/TrustWallet/trust-web3-provider/blob/master/src/index.js#L72

1
  • Thanks for answer. How to use those methods in browser side simple Javascript implementation? I am getting window.web3 object.. but can not call other functions. Any help appreciated. Commented Mar 18, 2020 at 8:20

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.