1

I am using angular with walletconnectprovider and web3 I have this issue with calling any methods from the contract where web3 is not returning any response.

This is how I initialized my provider

this.provider = new WalletConnectProvider({
  // infuraId: "27e484dcd9e3efcfd25a83a78777cdf1",
  rpc: {
    56: "https://bsc-dataseed.binance.org/"
  },
  chainId: 56
});

Initialized web3 and contract

const web3 = await new Web3(this.provider as any);

const contract = new web3.eth.Contract(JSON.parse(this.smartContract.abi),this.smartContract.contractAddress,{
  from: this.provider.wc.accounts[0]
});

And everytime i call this method all codes from below it is not executing. I also check my network tab it seems there is no running Http request at all.

await contract.methods.balanceOf(this.toAddress).call()
// codes here is not called
TylerH
  • 20,799
  • 66
  • 75
  • 101
Arianne
  • 69
  • 11
  • Just to update the .call will work with @wallet-connect/ethereum-provider but .send will not work, the transaction will sign and complete but the promise won’t resolve or catch – SpitefulG Oct 25 '21 at 16:28

1 Answers1

1

In the function, add before the contract iteraction the following sentence:

provider.enable();

For me it is working fine. If I do not include this sentence before, nothing executes.

cigien
  • 57,834
  • 11
  • 73
  • 112
Gorlami
  • 11
  • 1
  • Your answer could be improved with additional supporting information. Please [edit] to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Dec 23 '21 at 20:38