0

I develop dapp with react-native + ethers + wallet-connect.

I call approve function and go to the metamask, sign with transaction.

the transaction is confirmed, and i back to the my dapp.

my dapp shows error

{code: -32000, message: "Network request failed", transactionHash: xxx...}

why it always return the error ?

here is my code

// package.json
    "react-native": "0.72.8",
    "@walletconnect/modal-react-native": "1.0.0-rc.11",
    "@walletconnect/react-native-compat": "^2.10.1",
    "ethers": "^5.7.2",
const handleApproveWallet = async (provider: ethers.providers.ExternalProvider) => {
    const web3 = new ethers.providers.Web3Provider(provider, 'any');
    const contract = new ethers.Contract(
      Env.NEPTO_TOKEN_CONTRACT_ADDRESS,
      ERC_20_ABI,
      web3.getSigner(),
    );
    const MAX_AMOUNT = '190000000000000000000000000';
    const result: Promise<boolean> = await contract
      .approve(Env.NEPTO_AD_SEND_CONTRACT_ADDRESS, MAX_AMOUNT)
      .then((txHash) => {
        return txHash;
      })
      .catch((err) => {
        switch (err.code) {
          case -32000:
            // always in here, even if the transaction successed.
            return err.transactionHash;

          case 5000:
            Logger.warn("User Rejection");
            return;
        }
      });

    return result;
  };
2
  • Are you sure the contract address is correct and deployed on the network you are using? Commented Jan 18 at 18:31
  • @ruby_newbie yes, allowance function is called successfully.
    – jerrryJ
    Commented Jan 19 at 4:16

1 Answer 1

0

I fixed above issue !

I add rpcMap param inside provider

  const sessionParams = {
    namespaces: {
      eip155: {
        methods: ['eth_sendTransaction', 'eth_sign', 'personal_sign'],
        chains: ['eip155:1'],
        events: ['chainChanged', 'accountsChanged'],
        rpcMap: {
          1: 'https://eth.llamarpc.com',
        },
      },
    },
  };

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.