We were not able to estimate gas. There might be an error in the contract and this transaction may fail

Hello,
I forked a website, and forked the contract, it is a Baked Beans fork on MATIC, source files and contract are directly copied, and only modified names and contract address on the source files.
I deployed the contract through Remix, now when I try to deposit on the website, Metamask says
"We were not able to estimate gas. There might be an error in the contract and this transaction may fail."
It gives me a gas fee of around 26 MATIC.

Here is the contract:

Hi, welcome to the community! :wave:

Please do not use the words like Help, thanks!

So you mean you can deploy your contracts with Remix, but you can not do this by your website, right? If so, I think maybe there is something wrong your website rather than the contract itself, have a check which contract will it deploy actually when you use website.

Hello, thank you for the response.

My website is an investment platform where anyone can connect with their metamask wallet, deposit, restake, and withdraw MATIC to/from the contract.

Here is where I'm at:

Website works with original contract from where I forked the project from.

I created my own fork of the contract (identical to original contract), when I deploy the contract in Remix, deployment works fine.
I change the config file by replacing the original contract address with mine.

Now the website no longer allows transactions (gives me that gas error, and when I manually set a lower gas fee, it reverts)

Why would the website script work fine with the original contract, but when I replace that contract with mine, which is just a copy of theirs, it fails?

I scanned every file for their contract address and replaced it with mine.. am I missing anything?

Also to add to my previous message,
On mobile metamask browser:
Website fork with the original contract works
Replace contract address with mine, metamask authenticates and the site shows my MATIC balance, but when I click on Buy, nothing pops up (should be popping up with Metamask payment)

Update,
I tried changing the contract address with 2 other contract addresses of other identical forks. They all worked, but the second I switch to my contract address it throws that error.
Does it maybe take a while before it starts estimating the correct gas fees? Or do I need to make multiple transfers first?
I'm completely lost at this point. Why would my website work with every other contract address except for mine, even though it's identical

Update 2,
Even directly sending MATIC to my contract address, it fails and says:
"Warning! Error encountered during contract execution [execution reverted]"
Tried playing around with gas fees, no luck. Must mean something wrong with my contract. But what?

Also here is the errors my websites console shows

Error: Transaction has been reverted by the EVM:
{
  "blockHash": "0x397e1b4cc7b4de7f320c0f473f6a9b80199cdec0ad5809fc6f55cb7f5c9877f1",
  "blockNumber": 27956016,
  "contractAddress": null,
  "cumulativeGasUsed": 13409979,
  "effectiveGasPrice": "0x117b5b01ec",
  "from": "0x793192a51285d446c8f6f16db9333466a98fda85",
  "gasUsed": 23620,
  "logsBloom": "0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000008000000000000000080000000000000000000000000000000000000000800000000000000000000100000000000000000000000000000000000000000000000000000000000080000000000000000000000010000000000000000000000000000000000000000000000000000000201000000000000000000000000000000000000000000000020000000000004000000000000000000001000000000000000000000400000000100000000000000000000000000000000000000000000000000000000000008000000000100000",
  "status": false,
  "to": "0x3ff5aa997f9599a24599ef517b8eb7be804562e7",
  "transactionHash": "0xcf66ea0cbf00069e5074034de3e57930c48f2a37e440cae74c9f028f072e70db",
  "transactionIndex": 70,
  "type": "0x2",
  "events": {
    "0": {
      "address": "0x0000000000000000000000000000000000001010",
      "blockHash": "0x397e1b4cc7b4de7f320c0f473f6a9b80199cdec0ad5809fc6f55cb7f5c9877f1",
      "blockNumber": 27956016,
      "logIndex": 352,
      "removed": false,
      "transactionHash": "0xcf66ea0cbf00069e5074034de3e57930c48f2a37e440cae74c9f028f072e70db",
      "transactionIndex": 70,
      "id": "log_ac0824b2",
      "returnValues": {},
      "signature": null,
      "raw": {
        "data": "0x00000000000000000000000000000000000000000000000000035b4a6462400000000000000000000000000000000000000000000000000050923d2836055dd1000000000000000000000000000000000000000000000d8767e614b7af8391f8000000000000000000000000000000000000000000000000508ee1ddd1a31dd1000000000000000000000000000000000000000000000d8767e9700213e5d1f8",
        "topics": [
          "0x4dfe1bbbcf077ddc3e01291eea2d5c70c2b422b415d95645b9adcfd678cb1d63",
          "0x0000000000000000000000000000000000000000000000000000000000001010",
          "0x000000000000000000000000793192a51285d446c8f6f16db9333466a98fda85",
          "0x000000000000000000000000c6869257205e20c2a43cb31345db534aecb49f6e"
        ]
      }
    }
  }
}
    at Object.TransactionError (errors.js:87:21)
    at Object.TransactionRevertedWithoutReasonError (errors.js:98:21)
    at index.js:393:57
    at s (runtime.js:63:40)
    at Generator._invoke (runtime.js:293:22)
    at Generator.next (runtime.js:118:21)
    at r (asyncToGenerator.js:3:20)
    at o (asyncToGenerator.js:25:9)
    at asyncToGenerator.js:32:7
    at new Promise (<anonymous>)
(anonymous) @ BakeCard.js:128
s @ runtime.js:63
(anonymous) @ runtime.js:293
(anonymous) @ runtime.js:118
n @ asyncToGenerator.js:3
f @ asyncToGenerator.js:29
Promise.then (async)
n @ asyncToGenerator.js:13
o @ asyncToGenerator.js:25
(anonymous) @ asyncToGenerator.js:32
(anonymous) @ asyncToGenerator.js:21
(anonymous) @ BakeCard.js:146
Qe @ react-dom.production.min.js:52
Ke @ react-dom.production.min.js:52
(anonymous) @ react-dom.production.min.js:53
Sn @ react-dom.production.min.js:100
En @ react-dom.production.min.js:101
(anonymous) @ react-dom.production.min.js:113
Be @ react-dom.production.min.js:292
(anonymous) @ react-dom.production.min.js:50
Nn @ react-dom.production.min.js:105
$t @ react-dom.production.min.js:75
Xt @ react-dom.production.min.js:74
t.unstable_runWithPriority @ scheduler.production.min.js:18
Qa @ react-dom.production.min.js:122
Pe @ react-dom.production.min.js:292
Vt @ react-dom.production.min.js:73



















MetaMask - RPC Error: Internal JSON-RPC error. {code: -32603, message: 'Internal JSON-RPC error.', data: {…}}
(anonymous) @ inpage.js:1
(anonymous) @ inpage.js:17
_runReturnHandlers @ inpage.js:17
_processRequest @ inpage.js:17
await in _processRequest (async)
_handle @ inpage.js:17
handle @ inpage.js:17
_rpcRequest @ inpage.js:1
(anonymous) @ inpage.js:1
request @ inpage.js:1
bound bound request @ util.js:693
f.send @ index.js:155
u @ index.js:615
n @ index.js:647
b._executeMethod @ index.js:768
(anonymous) @ BakeCard.js:90
s @ runtime.js:63
(anonymous) @ runtime.js:293
(anonymous) @ runtime.js:118
n @ asyncToGenerator.js:3
o @ asyncToGenerator.js:25
(anonymous) @ asyncToGenerator.js:32
(anonymous) @ asyncToGenerator.js:21
(anonymous) @ BakeCard.js:109
(anonymous) @ BakeCard.js:128
s @ runtime.js:63
(anonymous) @ runtime.js:293
(anonymous) @ runtime.js:118
n @ asyncToGenerator.js:3
f @ asyncToGenerator.js:29
Promise.then (async)
n @ asyncToGenerator.js:13
o @ asyncToGenerator.js:25
(anonymous) @ asyncToGenerator.js:32
(anonymous) @ asyncToGenerator.js:21
(anonymous) @ BakeCard.js:146
Qe @ react-dom.production.min.js:52
Ke @ react-dom.production.min.js:52
(anonymous) @ react-dom.production.min.js:53
Sn @ react-dom.production.min.js:100
En @ react-dom.production.min.js:101
(anonymous) @ react-dom.production.min.js:113
Be @ react-dom.production.min.js:292
(anonymous) @ react-dom.production.min.js:50
Nn @ react-dom.production.min.js:105
$t @ react-dom.production.min.js:75
Xt @ react-dom.production.min.js:74
t.unstable_runWithPriority @ scheduler.production.min.js:18
Qa @ react-dom.production.min.js:122
Pe @ react-dom.production.min.js:292
Vt @ react-dom.production.min.js:73

















beanrewards Error: Internal JSON-RPC error.
{
  "code": 3,
  "message": "execution reverted",
  "data": "0x4e487b710000000000000000000000000000000000000000000000000000000000000012"
}
    at Object._fireError (index.js:49:17)
    at c (index.js:539:30)
    at c (util.js:689:22)
    at C (util.js:666:10)
    at h.run (browser.js:153:14)
    at l (browser.js:123:42)
(anonymous) @ BakeCard.js:66
Promise.catch (async)
(anonymous) @ BakeCard.js:90
s @ runtime.js:63
(anonymous) @ runtime.js:293
(anonymous) @ runtime.js:118
n @ asyncToGenerator.js:3
o @ asyncToGenerator.js:25
(anonymous) @ asyncToGenerator.js:32
(anonymous) @ asyncToGenerator.js:21
(anonymous) @ BakeCard.js:109
(anonymous) @ BakeCard.js:128
s @ runtime.js:63
(anonymous) @ runtime.js:293
(anonymous) @ runtime.js:118
n @ asyncToGenerator.js:3
f @ asyncToGenerator.js:29
Promise.then (async)
n @ asyncToGenerator.js:13
o @ asyncToGenerator.js:25
(anonymous) @ asyncToGenerator.js:32
(anonymous) @ asyncToGenerator.js:21
(anonymous) @ BakeCard.js:146
Qe @ react-dom.production.min.js:52
Ke @ react-dom.production.min.js:52
(anonymous) @ react-dom.production.min.js:53
Sn @ react-dom.production.min.js:100
En @ react-dom.production.min.js:101
(anonymous) @ react-dom.production.min.js:113
Be @ react-dom.production.min.js:292
(anonymous) @ react-dom.production.min.js:50
Nn @ react-dom.production.min.js:105
$t @ react-dom.production.min.js:75
Xt @ react-dom.production.min.js:74
t.unstable_runWithPriority @ scheduler.production.min.js:18
Qa @ react-dom.production.min.js:122
Pe @ react-dom.production.min.js:292
Vt @ react-dom.production.min.js:73

When trying to query anything on the contract within Remix, I get:

call to BakedOnions.beanRewards errored: Internal JSON-RPC error.
{
  "code": 3,
  "message": "execution reverted",
  "data": "0x4e487b710000000000000000000000000000000000000000000000000000000000000012"
}

Re-compiled the contract in Hardhat instead of Remix, tried sending 1 Matic to the contract address from my Metamask, failed with "execution reverted"

I did realize last night that direct transactions cannot be sent to it, has to be done through the website, or by executing the buy eggs command. Now I'm back at square one. Website works with original contract that I copied from, but when I replace it with my contract (identical), I get the gas estimation error, and when I set manual gas fees, it fails with the reverted error.

Running buyEggs from within Polygonscan:

Original Contract (Success) :

My Contract copy (Fail) :

What's the difference? The contracts are the same, why does mine fail? Also on mine it fails to estimate gas fee, so I have to set it manually

Polygon network always got some problems with estimate gas, to be sure you do not got ant problems with contracts try to set GasPrice + 30 Gwei, If tx pass, that's problem with your gas estimation, if not that's problem with contract.

Usually this happen when your Dapp is trying to call a smart contract function with less value than the required value statement inside the function.

Example:

I call in dapp the exampleFunction with 100 value.

and exampleFunction has:

require(msg.value > 150)

Metamask will say:

"We were not able to estimate gas. There might be an error in the contract and this transaction may fail."

(Sorry for my english)

I hope it helps!

Did you ever solve this issue? I am doing almost the same thing and having the same problem. I have a Python script that interacts with the original contract without a problem, but I get this same issue if I interact with my contract.

I think I figured it out... at least it worked for my issue. On this contract, you have to use the "SeedMarket" function to add initial funds to the contract, then the other functions should work.

I did face this issue recently and I have been tryna figure out what really was going wrong with my contract, then figured that only the owner had the perms to call that specific function and I had to enable the perms for all to let anyone address call the function, due to which the transaction was being reverted, of course internally this could be one of the many reasons we might come across, not the only definitive solution or aspect to look at when confronting such an error.

Hope this helps!