1

i can't figured out why when i call a method with provider, walletconnect keeps redirecting me in https://link.trustwallet.com instead of open me the app to approve the transaction. I've wrote the code for metamask and walletconnect and i used ethersjs to handle the provider.

Here's code for connection

const getBlockchain = (typew) =>
  new Promise(async (resolve) => {
    var provider;
    if(typew == "metamask"){
      /* @ts-ignore */
      if(window.ethereum) {
        /* @ts-ignore */
        await window.ethereum.enable();
        /* @ts-ignore */
        provider = new ethers.providers.Web3Provider(window.ethereum);
      }
    }
      
    if(typew == "walletconnect"){
        providerEth = new WalletConnectProvider({
          chainId: 56,
          rpc: {
            56: "https://bsc-dataseed.binance.org",
          }
        });

        await providerEth.enable();
        provider = new ethers.providers.Web3Provider(providerEth); 

        provider.off("disconnect");
        provider.on("disconnect", () => {
          closeBlockhain();
        })
    }
    
    
    if(provider !== undefined){
      const signer = provider.getSigner();
      /* @ts-ignore */
      const signerAddress:any = await signer.getAddress();

      const contract = new Contract(
        Contract.networks[56].address,
        Contract.abi,
        signer
      );

      const contract_two = new Contract(
        Contract_two.networks[56].address,
        Contract_two.abi,
        signer
      );

      configConnections = {
        connected: true,
        provider,
        contract,
        contract_two,
        signerAddress: signerAddress
      }

      resolve(configConnections);
    }
  
  resolve(configConnections);
 }); 

Can't explain to myself why if i open the app on mobile and try to call method, the browser redirects me on other page not on the TrustWallet or Metamask App.

I've tried to remove the axios before the contract call and it worked. I can't figured out why if i put a setTimeout before or i wait for a response, the app redirects me. All Code:

if(configConnections.connected){ 
            setDisabled(true); 
            const res = await axios.post(API_ENDPOINTS.ORIGINAL+API_ENDPOINTS.CREATE, { values,image }); 
            if(res.data !== false){ 
                let takeOn = await configConnections.contract.awardItem(ethers.utils.formatBytes32String("1"),res.data.hash);               
await takeOn.wait().then(function(x) {}) } }

Thank you

1
  • If i comment the Axios request, all works.
    – Simon D
    Jul 19 at 14:53

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.