HashLips / hashlips_nft_contract

A simple NFT smart contract that works with the rest of the HashLips ecosystem.
MIT License
835 stars 675 forks source link

Gas estimation failed #20

Open mubasharofficial opened 2 years ago

mubasharofficial commented 2 years ago

when mint nft some other wallets address rise this issue and but remix VM network nft create by other wallets successfullly.

liarco commented 2 years ago

If I'm not mistaken the gas estimation is not handled by the contract, nor by the DAPP. It's the wallet (or the web3 provider in use) that estimates the gas usage for you. This project shouldn't be the culprit IMHO...

mubasharofficial commented 2 years ago

So, why are Rise this error when we call min() function and passed other wallet (except mint wallet address) and number of nft after call function remix ide give Wraning 'Gas estimation errored with the following message .....' if we execute force fully transiction will be failed..

liarco commented 2 years ago

Sorry for the late reply, unfortunately I don't understand the exact issue you are facing, but I would suggest taking a look at the new "lower gas" version of the contract (SimpleNftLowerGas.sol) to see if it solves the gas issue.

jthak052 commented 2 years ago

@liarco Hello, I am facing same issue the error from remix after using mint function is given below, There is enough ethereum and if i force it and metamask will then give error and transaction will fail. i'm doing this all testing on rinkeby testnet

the error from Remix- "Gas estimation errored with the following message (see below). The transaction execution will likely fail. Do you want to force sending? execution reverted: Insufficient funds! { "originalError": { "code": 3, "data": "0x08c379a000000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000013496e73756666696369656e742066756e64732100000000000000000000000000", "message": "execution reverted: Insufficient funds!" } }"

@mubashar-official did you find any solution to this ?

liarco commented 2 years ago

Hi @jthak052, I think that both you and @mubashar-official are facing a problem that has nothing to do with gas. Simply, your wallet is telling you that it's unable to estimate the gas because the transaction is expected to fail for some reason. I don't have any clue about @mubashar-official since he didn't share the whole message, but in your case you can see the following error message: execution reverted: Insufficient funds!. So, I don't know what transaction you are trying to run, but you are sending an invalid amount of ETH along with the transaction data.

I hope this can help you.

jthak052 commented 2 years ago

@liarco I thought the same first but the issue is something else coz minting of 1 token I've kept 0.26 eth and I've above 1 eth in my wallet soo I've attached the Transaction link and I've also published the code flat file on the etherscan soo you can check it out and mint it by yourself soo you can also get the same error

Transaction Error- https://rinkeby.etherscan.io/tx/0x0b5537811145a61c8223effdb9818ca2f9bd725b9db43be318a0b0640c367e94

Code- https://rinkeby.etherscan.io/address/0x0C9Df9ad4dd8b4ee870E6229C0B624a72A66eCe7#code

liarco commented 2 years ago

@jthak052 I'm afraid you are missing how transactions work when you are sending them directly through Etherscan or Remix. As you can see from the transaction you sent above you are trying to mint without passing any ETH with the transaction:

Schermata 2022-01-27 alle 13 18 42

You have to specify the correct amount there, otherwise it will fail. Minting DAPPs are processing this stuff automatically for the user, but both Etherscan and Remix leave that to you so you can perform advanced tasks.

Edit: also, your wallet balance doesn't make any difference. You have to send an ETH value with the transaction explicitly, the amount is not managed by the contract method, it just verifies the requirements.

jthak052 commented 2 years ago

in the code the cost is define

uint256 public cost = 0.26 ether;

and the function mint just ask the number of the token I want to mine and it will multiply it with the cost which is predefined so the amount should be passed right?


function mint(uint256 _mintAmount) public payable mintCompliance(_mintAmount) {
    require(!paused, "The contract is paused!");
    require(msg.value >= cost * _mintAmount, "Insufficient funds!");

    _mintLoop(msg.sender, _mintAmount);
  }  
liarco commented 2 years ago

Ok, so here is the misunderstanding! 😉

The contract cannot ask a person to send a specific amount of crypto with along with the transaction, it can only check that the amount he sends is enough in order to complete the process.

So the values in the code just do the following things:

  1. let people know what is the price for each token
  2. check that the right amount is sent with the transaction when you try to mint N tokens

As I said before, you have to send ETH explicitly when calling the mint(...) function, otherwise it will see your transaction as if you are simply sending 0.0 (and then it fails for Insufficient funds!).

jthak052 commented 2 years ago

Ok, so if I put 0.26 then i get this below error:- transact to SimpleNftLowerGas.mint errored: Error encoding arguments: Error: invalid BigNumber string (argument="value" value="0.26" code=INVALID_ARGUMENT version=bignumber/5.5.0)

and if i put the same amount in wei then i get this error:- Gas estimation errored with the following message (see below). The transaction execution will likely fail. Do you want to force sending? execution reverted: Invalid mint amount! { "originalError": { "code": 3, "data": "0x08c379a000000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000014496e76616c6964206d696e7420616d6f756e7421000000000000000000000000", "message": "execution reverted: Invalid mint amount!" } }

and I checked 0 amount is going in metamask.

jthak052 commented 2 years ago

Ohh I did transaction from etherscan like this and it worked. i saw the video again and got the mistake i was doing. thanks mate.

image

liarco commented 2 years ago

@jthak052 I'm really happy to hear that! 😄 Btw, yes, unfortunately different platforms require different user input (ETH, WEI, dot/comma for decimails, etc.) so you must be very careful to what you are dealing with.

Good luck with your projects.

jthak052 commented 2 years ago

Is there any way we can hire you for the project for your expertise and guidance? You can take your fees.

liarco commented 2 years ago

Is there any way we can hire you for the project for your expertise and guidance? You can take your fees.

Thank you for your request @jthak052. I would be happy to have a chat in order to know a bit more about your project and see if I have enough time to support you as you need. Would you please reach out to me on Discord so we can have a chat?

See you there! :)

mubasharofficial commented 2 years ago

So, why are Rise this error when we call min() function and passed other wallet (except mint wallet address) and number of nft after call function remix ide give Wraning 'Gas estimation errored with the following message .....' if we execute force fully transiction will be failed..

thanks to all Hashlips community. I am fix this error actually do don't put gas fee gei.

uzairasadd commented 2 years ago

Ohh I did transaction from etherscan like this and it worked. i saw the video again and got the mistake i was doing. thanks mate.

image

Can you please tell the mistake? Having same issue

uzairasadd commented 2 years ago

@jthak052