PatrickAlphaC/nft-mix

Polygon-Main Gas Estimation Error on Mint

Equious opened this issue · 2 comments

To start with, this works on the Mumbai Testnet. I can fund and create nfts, no problems.

I managed to get the contract deployed at : 0xd686D76F4B969F2Ec3363f5504010D5eCa7dcdd5 on Polygon-Main. I managed to get it funded, but when I go to create_collectable. I get this:

Running 'scripts\NFT_Pets\create_collectable.py::main'... File "C:\Users\Equio\AppData\Local\Programs\Python\Python310\lib\site-packages\brownie\_cli\run.py", line 49, in main return_value, frame = run( File "C:\Users\Equio\AppData\Local\Programs\Python\Python310\lib\site-packages\brownie\project\scripts.py", line 103, in run return_value = f_locals[method_name](*args, **kwargs) transaction = NFTPet.mintNFT("none", {"from": dev}) File "C:\Users\Equio\AppData\Local\Programs\Python\Python310\lib\site-packages\brownie\network\contract.py", line 1693, in __call__ return self.transact(*args) File "C:\Users\Equio\AppData\Local\Programs\Python\Python310\lib\site-packages\brownie\network\contract.py", line 1566, in transact return tx["from"].transfer( File "C:\Users\Equio\AppData\Local\Programs\Python\Python310\lib\site-packages\brownie\network\account.py", line 642, in transfer receipt, exc = self._make_transaction( File "C:\Users\Equio\AppData\Local\Programs\Python\Python310\lib\site-packages\brownie\network\account.py", line 725, in _make_transaction File "C:\Users\Equio\AppData\Local\Programs\Python\Python310\lib\site-packages\brownie\exceptions.py", line 121, in __init__ raise ValueError(str(exc)) from None ValueError: Gas estimation failed: 'execution reverted'. This transaction will likely revert. If you wish to broadcast, you must set the gas limit manually.

Here are my functions and addresses:

Create Collectable

`
from brownie import NFTPets, accounts, config
from scripts.helpful_scripts import get_mood, get_name
import time

STATIC_SEED = 42069

def main():
dev = accounts.add(config["wallets"]["from_key"])
NFTPet = NFTPets[len(NFTPets) - 1]
transaction = NFTPet.mintNFT("none", {"from": dev})
transaction.wait(1)
time.sleep(30)
requestId = transaction.events["requestedCollectable"]["requestID"]
transaction.wait(1)
time.sleep(30)
token_id = NFTPet.requestIdtoTokenId(requestId)
mood = get_mood(NFTPet.tokenIdToMood(token_id))
name = get_name(NFTPet.tokenIdToName(token_id))
print("{} (TokenID: {}) is super {}".format(name, token_id, mood))
`

Mint and Fulfill Randomness:

`
function mintNFT(string memory tokenURI) public returns (bytes32) {
bytes32 requestID = requestRandomness(keyHash, fee);
requestIdToSender[requestID] = msg.sender;
requestIdToTokenURI[requestID] = tokenURI;
emit requestedCollectable(requestID);
}

function fulfillRandomness(bytes32 requestID, uint256 randomNumber)
    internal
    override
{
    address petOwner = requestIdToSender[requestID];
    string memory tokenURI = requestIdToTokenURI[requestID];
    uint256 newItemId = tokenCounter;
    _safeMint(petOwner, newItemId);
    setTokenURI(newItemId, tokenURI);
    Mood petMood = Mood(randomNumber % 5);
    tokenIdToMood[newItemId] = petMood;
    Name petName = Name(randomNumber % 4);
    tokenIdToName[newItemId] = petName;
    tokenIdToIndex[newItemId] = (randomNumber % 5);
    requestIdtoTokenId[requestID] = newItemId;
    tokenCounter = tokenCounter + 1;
}`

Config Addresses:

networks: default: development polygon-main: vrf_coordinator: '0x3d2341ADb2D31f1c5530cDC622016af293177AE0' link_token: '0x53E0bca35eC356BD5ddDFebbD1Fc0fD03FaBad39' keyhash: '0xf86195cf7690c55907b2b611ebb7343a6f649bff128701cc542f0569e2c549da' fee: 100000000000000000 eth_usd_price_feed: '0xF9680D99D6C9589e2a93a78A04A279e509205945' verify: True polygon-test: vrf_coordinator: '0x8C7382F9D8f56b33781fE506E897a4F1e2d17255' link_token: '0x326C977E6efc84E512bB9C30f76E30c160eD06FB' keyhash: '0x6e75b569a01ef56d18cab6a8e71e6600d6ce853834d4a5748b720d06f878b3a4' fee: 100000000000000000 eth_usd_price_feed: '0xF9680D99D6C9589e2a93a78A04A279e509205945' verify: True

Appreciate any insight. Getting discouraged :(

Hello, since no one has responded to you yet, I figured I would give it a shot. Keep in mind, I haven't worked with the Polygon chain specifically, but my assumption is my Ethereum knowledge should suffice. Also, I'm assuming you're using web3.py and I haven't personally worked with it before.

The error output reminds me of some errors I've seen when setting up my first transactions.

I noticed that in this line:

transaction = NFTPet.mintNFT("none", {"from": dev})

You aren't setting a gas price or gas limit. You could try something like:

transaction = NFTPet.mintNFT("none", {"from": dev, "gasPrice": somePrice, "gasLimit": someLimit})

For example, for my ethers.js transactions I always send:

const txData = {
    gasPrice: 9000000000,
    gasLimit: 900000
}

Not sure if these values will work for you. And it was a different library.

You should experiment with the different gas price settings in your transaction. When I was getting a similar error, I had to play with the 'gasPrice' and 'gasLimit' (ethers.js not web3.py) values until my transaction was working correctly. After that, I just saved what I had so that my unit tests and testnet transactions no longer have this issue. FYI, I was using ethers.js.

Here's the web3.py doc section explaining the different values you can send in the transaction for gas fees.

Also, keep in mind, there is probably a better way of doing this using the estimate_gas() method

My assumption is that it worked on one chain but not the other because there are a bunch of different factors that go into gas fees. When not specifying gas fees in the transaction, the library you're using will use some default values. Maybe the network that you're using now has gas fees that those default values aren't sufficient to pay.

Hope this helps and sorry if it doesn't.

Appreciate the response none the less. Seems the issue was related to changes in setTokenURI in ERC 751 since the tutorial I was following was made. I made a couple changes and rebuilt the function and things seem to be working now :)

Love this community. Love programming, it's so satisfying when you get things working.