Moralis react native

hello everyone,I need to implement this in react native, call the two functions and execute this, at the moment I use this function:UseWebExecutefunction and this work but I don’t Know; How to call the two functions at the same time?, at the moment only execute the function in different time

Which functions do you want to call at the same time? Two functions from your contract or two from your React app?

to functions for contract, first a need call buyProduct() from mi contract and next, call select item from my marketplace contract

You can use two instances of useWeb3ExecuteFunction together and call fetch on each. You will still have to sign for each transaction in your wallet (as normal).

const buyProduct = useWeb3ExecuteFunction(...);
const selectItem = useWeb3ExecuteFunction(...);

...

await buyProduct.fetch();
await selectItem.fetch();

If the second transaction depends on the first to be completed, it should only be made when the first transaction is confirmed on-chain.

2 Likes

I did the test in a web environment and it works perfectly, but on mobile, when doing the approval, metamask throws me this error and it is exactly the same code that works on the web, what could be the error?

I am not sure, can you post the transaction hash if you click to view the transaction. Possibly MetaMask on mobile doesn’t like multiple transaction requests made immediately like this, the flow may need to be changed.

https://goerli.etherscan.io/tx/0xfa39043a78592e8f49f9bdea5169d0a9c7e056a592fbce04460fc4419667dd56
how could change the flow??

That looks like the successful transaction that you were able to sign, can you give the failed transaction hash? You can also get it from data from the hook e.g.

useEffect(() => {
  console.log("selectItem", selectItem.data); // or whichever name you gave to the variables
}, [selectItem.data]);

Also check for error as well for both (also from the hook).

{“blockHash”: “0xe5a3644447f5e9a997a1f15187a75ea38bb57563b133cacdca999e916cef009f”, “blockNumber”: 7544768, “contractAddress”: null, “cumulativeGasUsed”: 1782904, “effectiveGasPrice”: 1500000019, “events”: {“0”: {“address”: “0xf0E924533f2561b643125145f58215a789D77b34”, “blockHash”: “0xe5a3644447f5e9a997a1f15187a75ea38bb57563b133cacdca999e916cef009f”, “blockNumber”: 7544768, “event”: undefined, “id”: “log_8c8449f0”, “logIndex”: 21, “raw”: [Object], “removed”: false, “returnValues”: [Result], “signature”: null, “transactionHash”: “0xd7c1861efcbc9ceef634a968886d0c2d8c366ed080d87ddd90e30cc7c4cb2077”, “transactionIndex”: 14}}, “from”: “0x888919a7a32add6479c1a817818f504888a984ee”, “gasUsed”: 29781, “logsBloom”: “0x00000000080000000000000000000000000000000000000000000000000000000000000000000000000000000000000001000000000000000000000000200000000000000400000000080000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000020000000000000000100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000010000000000000010000004000000000000000000000000000000000000010000000000000000”, “status”: true, “to”: “0xf0e924533f2561b643125145f58215a789d77b34”, “transactionHash”: “0xd7c1861efcbc9ceef634a968886d0c2d8c366ed080d87ddd90e30cc7c4cb2077”, “transactionIndex”: 14, “type”: “0x2”}

this was the console, but the metamask alert keeps popping up and since it tells me that: ‘an error occurred’, it never executes my second buyProduct() function

0xd7c1861efcbc9ceef634a968886d0c2d8c366ed080d87ddd90e30cc7c4cb2077

Again. this transaction hash you’ve posted looks to be from the same first function you’re calling because it was successful (so you signed for it), not the second that fails. Try calling the second fetch() in a useEffect only once data from the first is valid.

useEffect(() => {
  if (buyProduct.data) secondFunction.fetch();
}, [buyProduct.data]);

I received this error :[Error: Failed to check for transaction receipt:

Where is this error from exactly? Did you try changing the flow (like in the example with useEffect)?

yes, don’t complite the first function and send me the error

So now the first function call doesn’t work? Where is the error from - is it from logging in code or from the MetaMask app?

Can you post your updated code.

I discovered my problem, when I press the button to execute my function, it directs me to metamask and when I accept the operation it immediately returns me to my app, there is the problem, it returns me too quickly and produces an error. Is there any way to delay that redirection to my app?

it directs me to metamask and when I accept the operation it immediately returns me to my app

You get the error from your own app, not from MetaMask? You haven’t quite explained that yet. If you outline the flow of your app and interaction with MetaMask, and when the error actually happens and where it comes from, that would help.

I’m not sure if you can delay the redirect on MetaMask’s side, that is the typical behaviour.

1 Like

hello i solve this error, but I have another question, is there any way to change the metamask network through moralis?

The user will have to change the network in the MetaMask wallet themselves.

In this case, if the user has a different network than my application (polygon), opening metamask breaks my application, is there a way to prevent that?