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.
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.
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?