'I want to interact smart contract with react native mobile application
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
Solution 1:[1]
Use Moralis npm module contains for React Native environments.
npm i moralisconst Moralis = require('moralis');
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Peter Csala |
