ethers-io / ethers.js

Complete Ethereum library and wallet implementation in JavaScript.
https://ethers.org/
MIT License
7.8k stars 1.8k forks source link

Does etherjs V5 work in TrustWallet? #1025

Closed jamesmorgan closed 3 years ago

jamesmorgan commented 3 years ago

Hi everyone, I have a little dapp thats using etherjs but I cant seem to get it working in TrustWallet?

I have no empirical evidence that the reason is etherjs V5 at all but I wondered if anyone has successfully used it with TrustWallet?

The reason I ask is that after looking at TW github here - https://github.com/trustwallet/trust-web3-provider - It states that it comes bundled with web3 0.20.x. which is not only an ancient and deprecated lib, but may also not be compatable with ethers V5?

Anyway, thanks for any help or answers.

ricmoo commented 3 years ago

I don't know of any reason it won't be compatible, but I haven't tested it myself.

It works in node 8 and above, ES3 (ish) and above (for browsers) and with the included shims file enables it in React Native. If you are having an issue, you might want to try including the shims package, in case TrustWallet is build using a limited version of JavaScriptCore?

Do you get any errors?

jamesmorgan commented 3 years ago

Thanks @ricmoo I'll have a look at shims. It's. Nuxtjs app so may need something extra as you say.

TBH it's probably something I am doing but just seems odd why I can't get it working in TW but does in others. Will report back any findings I get.

jamesmorgan commented 3 years ago

I actually got it working, it an ordering thing with the ssr client/server logic. 😄

I have found one thing which you may be able to help with. I am migrating a web3 dapp to nuxt and etherjs - one problem which has come up today is about message signing.

Previous I used to use this from web3js:

web3.eth.personal.sign(Web3.utils.toHex(`Hello world`), account)

And I have migrated it to use this ethersjs library, but I cant seem to get it to generate a valid signature against our API when inside some wallets e.g. trust, coinbase wallet, but works find on MetaMask. Am I using the wrong method?

provider.getSigner().signMessage(`Hello world`);

Provider being the unlocked in web3 account provider.

Any ideas?

jamesmorgan commented 3 years ago

I have actually got it working however made the rpc call manually like this:

web3.provider.sendAsync({
          method: 'personal_sign',
          params: [ethers.utils.hexlify(ethers.utils.toUtf8Bytes(`Hello world`)), account]
        }, (error, response) => {
          if (error) {
            return reject(error);
          }
          return resolve(response.result);
        })
ricmoo commented 3 years ago

The JsonRpcSigner uses the eth_sign RPC method. I'm guessing Trust Wallet doesn't support it in favour of the personal_sign RPC method.

I'll try it out and see if there is a way to detect that eth_sign isn't available and fall back onto personal_sign...

pinpong commented 3 years ago

Hello, i'm also not able to connect within the trust wallet browser for dapps. Any news on this issue?

ricmoo commented 3 years ago

This will be TransactionResponse ned in #1544.

I'll close this issue, as that issue better covers the problem, and what I need form everyone to move forward with a solution.

Thanks! :)