Hello I developed a smart contract and a dapp in react. i try to interact using metamask as provider.When I call a specific contract function during the transaction confirm appear the following message "ALERT: Transaction Error. Exception thrown in contract code", even if the same function worked before. Someone know how to fix it ?

Jan 20, 2021, 10:13 PM
Noone will be able to help without information about the function that was called.
Jan 20, 2021, 11:28 PM
agree
Jan 21, 2021, 5:29 AM
you are right 😅 https://codeshare.io/2EdB3O that's part of the contract. the function that raise the alert is the registerOwner(...)
Jan 21, 2021, 8:20 AM
Where did you see the alert? And did you try it in Mainnet or Testnet?
Jan 21, 2021, 8:26 AM
I try in ropsten testnet. The alert appear on Metamask popup to confirm the transaction
That's the alert
Jan 21, 2021, 8:28 AM
Which compiler version do you use?
Jan 21, 2021, 8:28 AM
0.7.6
I'm using pragma experimental ABIEncoderV2;, I don't kow if it could be the problem. I read that's the only way to return struct in getter functions
Jan 21, 2021, 8:32 AM
Force send the transaction anyway and check if any require statement is getting triggered
Jan 21, 2021, 8:33 AM
I don't get such an error. What values do you try to enter?
That's a good idea, since the requires have a return value you'd see what error it is.
Jan 21, 2021, 8:41 AM
👌👌 I confirmed the transaction but it is still in pending on etherscan
Jan 21, 2021, 8:42 AM
Ok good luck haha
Once confirmed, look at the transaction in Etherscan
Jan 21, 2021, 8:43 AM
I know, the weird thing is that at the beginning the function works correctly and the transaction is confirmed, but after raise this exception
Jan 21, 2021, 8:44 AM
If you mean running the function twice, of course it doesn't work:
require(!owners[msg.sender].isRegistered, "Account already registered as Owner");
Jan 21, 2021, 8:46 AM
It look likes is a gas problem. Therefore why at the beginning works correctly
with different wallet of course
Jan 21, 2021, 8:46 AM
You set your limit to 7,6mln gas but it needs more. Change the gas limit in MetaMask.
What do you mean with at the beginning it worked correctly plus why did the tx you showed take 7 million+ gas?
I have tested with two accounts and have not received any error. Are you sure that you changed the wallets?
Jan 21, 2021, 8:50 AM
Yes I try several times with new metamask wallet.
It means that. I deploy the contract on ropsten -> I run the registerOwner function and it works -> then after a couple of times I rerun registerOwner function even with new wallet on metamask that raise this error
I try to deploy different times the contract and the flow is the same. It works for the first calls then raise this error.
Thanks for the tips, I try it. I think is a metamask problem too. I'll bring you up
Jan 21, 2021, 8:53 AM
I think I know why :)
Make sure that the account in MetaMask is connected to Remix, otherwise the account will stay as the old account and then throw the error
Jan 21, 2021, 9:00 AM
I test the contract not on remix but by my own react application. I developed some api in typescript that intercept the metamask wallet connected and invoke the contract function passing by metamask to sign the transaction
and if the wallet isn't connected the exeption is raised at application layer because api require account paramenter
Jan 21, 2021, 9:22 AM
Then I don't know what it could be sorry
Jan 21, 2021, 9:22 AM
No problem. thanks anyway for your availability :)
Jan 21, 2021, 9:27 AM
You're welcome :)
Jan 21, 2021, 10:11 AM
Just to update you. Increasing the gas of the transaction the alert not appear even if the transaction raise a new error MetaMask - RPC Error: Error: [ethjs-query] while formatting outputs from RPC '{"value":{"code":-32000,"message":"exceeds block gas limit"}}'
exceeds block gas limit I try to compute gasLimit to pass during the contract method call, using the following formula block.gasLimit/block.transactions.length but this solution doesn't fix the problem
Jan 21, 2021, 1:26 PM
What is block.transactions.length? Why use block data here? Can you try with setting a manual limit like i.e. 11 mln
Jan 21, 2021, 1:59 PM

© 2024 Draquery.com All rights reserved.