0

I want to interact with my smart contract to use their functions. I am using the ethereum-react-native-boilerplate example and I’m trying to execute a smart contract function using the useWeb3ExecuteFunction hook. I run this example and its works fine but when I try to interact smart contract with react-moralis it's not working and only redirecting to metamask and not calling the function of the smart contract. Below code is called on button click for calling smart contract function.

 const ops = {
        contractAddress: "0x878......",
        functionName: "add_data",
        abi: [{"inputs": [{"internalType": "uint256","name": "amount","type": "uint256"},{"internalType": "uint256","name": "total_user","type": "uint256"},{"internalType": "address","name": "token","type": "address"},{"internalType": "string","name": "_value","type": "string"},{"internalType": "string","name": "symbol","type": "string"}],"name": "add_data","outputs": [],"stateMutability": "nonpayable","type": "function"}],
        params: {
          amount: 123333,
          total_user: 6,
          token: "0x34EE........",
          _value: "ABC Coin",
          symbol: "ABC",
        },
      };

      await contractProcessor.fetch({
        params: ops,
        onSuccess: () => {
          console.log("Approval Received");


        },
        onError: (error) => {
   
        },
      });

I followed the official documentation of react-moralis https://github.com/MoralisWeb3/react-moralis#useweb3executefunction

rescobar
  • 1,261
  • 15
  • 25
  • If you are building an end-user application that interacts with smart contract, I'd recommend - Allowing user to bring their own wallet app - Connect your app to a wallet app using [WalletConnect protocol](https://walletconnect.com/) - The user can then confirm any smart contract transaction with their wallet - which may also include a hardware wallet devices – Mikko Ohtamaa Jan 11 '22 at 08:22
  • Yes I am already using WalletConnect but whenever I call the useWeb3ExecuteFunction function It pops up the wallet but the wallet doesn’t show anything – berg media Jan 13 '22 at 08:48

1 Answers1

0

Use Moralis npm module contains for React Native environments.

  • npm i moralis
  • const Moralis = require('moralis');
Peter Csala
  • 17,736
  • 16
  • 35
  • 75