PatrickAlphaC / nft-mix

MIT License
824 stars 415 forks source link

Stuck on Create_Collectible.py deployment #102

Closed SiKi02 closed 2 years ago

SiKi02 commented 2 years ago

Error: Gas estimation failed: 'execution reverted'. This transaction will likely revert. If you wish to broadcast, you must set the gas limit manually.

Helpful_scripts.py

from` brownie import AdvancedCollectible, accounts, config, interface, network 

def get_breed(breed_number):
    switch = {0: 'PUG?', 1: 'SHIBA_INU', 2: 'ST_BERNARD'}
    return switch[breed_number]

def fund_advanced_collectible(nft_contract):
    dev = accounts.add(config['wallets']['from_key'])
    link_token = interface.LinkTokenInterface(config['networks'][network.show_active()]['link_token'])
    link_token.transfer(nft_contract, 1000000000000000000, {'from':dev})

AdvancedCollectible.sol

// SPDX-License-Identifier: MIT
pragma solidity 0.6.6;

import "@openzeppelin/contracts/token/ERC721/ERC721.sol";
import "@chainlink/contracts/src/v0.6/VRFConsumerBase.sol";

contract AdvancedCollectible is ERC721, VRFConsumerBase {

    bytes32 internal keyHash;
    uint256 public fee;
    uint256 tokenCounter;

    enum Breed{PUG, SHIBA_INU, ST_BERNARD}

    mapping(bytes32 => address) public requestIDToSender;
    mapping(bytes32 => string) public requestIDToTokenURI; 
    mapping(uint256 => Breed) public tokenIDToBreed;
    mapping(bytes32 => uint256) public requestIDToTokenID;

    event RequestedCollectible(bytes32 indexed requestID);

    constructor(address _VRFCoordinator, address _LinkToken, bytes32 _keyhash) public
    VRFConsumerBase(_VRFCoordinator, _LinkToken)
    ERC721("Doggies", "DOG")
    {
        keyHash = _keyhash;
        fee= 0.1 * 10 ** 18; //0.1 LINK
        tokenCounter = 0;
    }

    function createCollectible(string memory tokenURI) public returns (bytes32) {
        bytes32 requestID = requestRandomness(keyHash, fee);
        requestIDToSender[requestID] = msg.sender;
        requestIDToTokenURI[requestID] = tokenURI;
        emit RequestedCollectible(requestID);
    }

    function fulfillRandomness(bytes32 requestID, uint256 randomNumber) internal override {
        address dogOwner = requestIDToSender[requestID];
        string memory tokenURI = requestIDToTokenURI[requestID];
        uint256 newItemID = tokenCounter;
        _safeMint(dogOwner, newItemID);
        _setTokenURI(newItemID, tokenURI);
        Breed breed = Breed(randomNumber % 3);
        tokenIDToBreed[newItemID] = breed;
        requestIDToTokenID[requestID] = newItemID;
        tokenCounter = tokenCounter + 1;
        }

    function setTokenURI(uint256 tokenID, string memory _tokenURI) public {
        require(
            _isApprovedOrOwner(_msgSender(), tokenID),
            "ERC721: transfer caller is not owner nor approved"
        );
        _setTokenURI(tokenID, _tokenURI);
    }
}

Create_collectible.py

from brownie import AdvancedCollectible, accounts, config
from scripts.helpful_scripts import get_breed
import time

def main():
    dev = accounts.add(config['wallets']['from_key'])
    advanced_collectible = AdvancedCollectible[len(AdvancedCollectible) - 1]
    transaction = advanced_collectible.createCollectible("None", {'from': dev},)
    transaction.wait(1)
    time.sleep(35)
    requestId = transaction.events['RequestedCollectible']['requestID']
    token_id = advanced_collectible.requestIDToTokenID(requestId)
    breed = get_breed(advanced_collectible.tokenIDToBreed(token_id))
    print('Dog breed of token ID {} is {}'.format(token_id, breed))

Brownie-config.yaml

dependencies:
  - smartcontractkit/chainlink-brownie-contracts@1.1.1
  - OpenZeppelin/openzeppelin-contracts@3.4.0
compiler:
  solc:
    remappings:
      - "@chainlink=smartcontractkit/chainlink-brownie-contracts@1.1.1"
      - "@openzeppelin=OpenZeppelin/openzeppelin-contracts@3.4.0"
wallets:
  from_key: ${PRIVATE_KEY}
dotenv: .env
networks:
  default: development
  rinkeby:
    vrf_coordinator: "0x6168499c0cFfCaCD319c818142124B7A15E857ab"
    link_token: "0x01BE23585060835E02B77ef475b0Cc51aA1e0709"
    keyhash: "0xd89b2bf150e3b9e13446986e571fb9cab24b13cea0a43ea20a6049a85cc807cc"
    fee: 100000000000000000

Complete error tab:

brownie run scripts/advanced_collectible/create_collectible.py --network rinkeby
Brownie v1.18.2 - Python development framework for Ethereum

ScratchProject is the active project.

Running 'scripts/advanced_collectible/create_collectible.py::main'...
  File "brownie/_cli/run.py", line 51, in main
    return_value, frame = run(
  File "brownie/project/scripts.py", line 110, in run
    return_value = f_locals[method_name](*args, **kwargs)
  File "./scripts/advanced_collectible/create_collectible.py", line 8, in main
    transaction = advanced_collectible.createCollectible("None", {'from': dev},)
  File "brownie/network/contract.py", line 1861, in __call__
    return self.transact(*args)
  File "brownie/network/contract.py", line 1734, in transact
    return tx["from"].transfer(
  File "brownie/network/account.py", line 644, in transfer
    receipt, exc = self._make_transaction(
  File "brownie/network/account.py", line 727, in _make_transaction
    raise VirtualMachineError(e) from None
  File "brownie/exceptions.py", line 93, 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.

Thanks people!

PatrickAlphaC commented 2 years ago

What happens when you git clone the repo and try to run it from the start?

SiKi02 commented 2 years ago

Sorry Patrick, I'm barely learning how to use everything in this world. Should I git clone this repo or should I make a repo with my code, clone it and then running it again?

thanks!

PatrickAlphaC commented 2 years ago

Ah sorry, yes git clone this repo (my code) and see if you still get this error.

Basically, let's isolate where the issue is. We want to rule out whether or not it's an issue with the code I wrote, or a simple mistake somewhere.

SiKi02 commented 2 years ago

Hi Patrick, been trying to work on the repo and now I get this error.

brownie run scripts/advanced_collectible/create_collectible.py --network rinkeby Brownie v1.18.2 - Python development framework for Ethereum

NftMixProject is the active project.

Running 'scripts/advanced_collectible/create_collectible.py::main'...
  File "brownie/_cli/run.py", line 51, in main
    return_value, frame = run(
  File "brownie/project/scripts.py", line 110, in run
    return_value = f_locals[method_name](*args, **kwargs)
  File "./scripts/advanced_collectible/create_collectible.py", line 9, in main
    advanced_collectible = AdvancedCollectible[len(AdvancedCollectible) - 1]
  File "brownie/network/contract.py", line 192, in __getitem__
    return self._contracts[i]
IndexError: list index out of range

I thought i needed to compile first the advancedcollectible.sol contract, but it didn't work.

SiKi02 commented 2 years ago

Hi once again Patrick, I found my mistake while deploying your repo. I didn't deploy and fund before running the create collectible.py. After doing that I get the same error as my code above. Look.

brownie run scripts/advanced_collectible/deploy_advanced.py --network rinkeby
Brownie v1.18.2 - Python development framework for Ethereum

NftMixProject is the active project.

Running 'scripts/advanced_collectible/deploy_advanced.py::main'...
rinkeby
Transaction sent: 0x63ff69a87f3327b8e73335b36a7bc8c0f1bdf5ef734c8631f976682388e0403c
  Gas price: 1.099995462 gwei   Gas limit: 2559546   Nonce: 92
  AdvancedCollectible.constructor confirmed   Block: 10989825   Gas used: 2326860 (90.91%)
  AdvancedCollectible deployed at: 0xe9Da9A3329B3ac935EdcC517bf708fF766aA10F5

Transaction sent: 0x56679025bd6983773d4a819de6e634e66d83b979fa200f7f4897d9531fbe7561
  Gas price: 1.099995462 gwei   Gas limit: 56992   Nonce: 93
  LinkToken.transfer confirmed   Block: 10989826   Gas used: 51811 (90.91%)

Funded 0xe9Da9A3329B3ac935EdcC517bf708fF766aA10F5
------------

export IPFS_URL=http://127.0.0.1:5001

------------
brownie run scripts/advanced_collectible/fund_collectible.py --network rinkeby
Brownie v1.18.2 - Python development framework for Ethereum

NftMixProject is the active project.

Running 'scripts/advanced_collectible/fund_collectible.py::main'...
Transaction sent: 0x4a486da75ff30ec0ee1753485f04e699b847b34f6aaa4e59dd42abd3e87491ff
  Gas price: 1.099995462 gwei   Gas limit: 38182   Nonce: 94
  LinkToken.transfer confirmed   Block: 10989830   Gas used: 34711 (90.91%)

Funded 0xe9Da9A3329B3ac935EdcC517bf708fF766aA10F5

---------
brownie run scripts/advanced_collectible/create_collectible.py --network rinkeby
Brownie v1.18.2 - Python development framework for Ethereum

NftMixProject is the active project.

Running 'scripts/advanced_collectible/create_collectible.py::main'...
Transaction sent: 0xe908dd75386d1aa71437e2d5f82f8d6c846c34ec1ec5bb3c900bbb228638faf0
  Gas price: 1.099995461 gwei   Gas limit: 38182   Nonce: 95
  LinkToken.transfer confirmed   Block: 10989835   Gas used: 34711 (90.91%)

Funded 0xe9Da9A3329B3ac935EdcC517bf708fF766aA10F5
  File "brownie/_cli/run.py", line 51, in main
    return_value, frame = run(
  File "brownie/project/scripts.py", line 110, in run
    return_value = f_locals[method_name](*args, **kwargs)
  File "./scripts/advanced_collectible/create_collectible.py", line 11, in main
    transaction = advanced_collectible.createCollectible("None", {"from": dev})
  File "brownie/network/contract.py", line 1861, in __call__
    return self.transact(*args)
  File "brownie/network/contract.py", line 1734, in transact
    return tx["from"].transfer(
  File "brownie/network/account.py", line 644, in transfer
    receipt, exc = self._make_transaction(
  File "brownie/network/account.py", line 727, in _make_transaction
    raise VirtualMachineError(e) from None
  File "brownie/exceptions.py", line 93, 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.
SiKi02 commented 2 years ago

Hi @PatrickAlphaC ! Could you find the answer to the problem?

PatrickAlphaC commented 2 years ago

Please start from scratch and let me know on what step you get the error:

  1. Clone this repo

    brownie bake nft-mix
    cd nft
  2. Add your environment variables to the .env file:

export WEB3_INFURA_PROJECT_ID=<PROJECT_ID>
export PRIVATE_KEY=<PRIVATE_KEY>
  1. Run the scripts:
brownie run scripts/advanced_collectible/deploy_advanced.py --network rinkeby
brownie run scripts/advanced_collectible/fund_collectible.py --network rinkeby
brownie run scripts/advanced_collectible/create_collectible.py --network rinkeby

Wait a few minutes, then run:

brownie run scripts/advanced_collectible/create_metadata.py --network rinkeby
brownie run scripts/advanced_collectible/set_tokenuri.py --network rinkeby
SiKi02 commented 2 years ago

Hi @PatrickAlphaC Good Night. I succesfully clone the repo and runned all the command lines on my terminal with success.

Nevertheless I still get a problem with my orginal code which is the one of your youtube video. https://www.youtube.com/watch?v=p36tXHX1JD8 1:22:30

When I deploy the createcollectible.py I get this error: Gas estimation failed: 'execution reverted'. This transaction will likely revert. If you wish to broadcast, you must set the gas limit manually.

Here is my code for the create_collectible.py file.

from brownie import AdvancedCollectible, accounts, config
from scripts.helpful_scripts import get_breed
import time

def main():
    dev = accounts.add(config['wallets']['from_key'])
    advanced_collectible = AdvancedCollectible[len(AdvancedCollectible) - 1]
    transaction = advanced_collectible.createCollectible("None", {'from': dev},)
    transaction.wait(1)
    time.sleep(35)
    requestId = transaction.events['RequestedCollectible']['requestID']
    token_id = advanced_collectible.requestIDToTokenID(requestId)
    breed = get_breed(advanced_collectible.tokenIDToBreed(token_id))
    print('Dog breed of token ID {} is {}'.format(token_id, breed))

You can note that you have the STATIC_SEED VARIABLE in this part of the video, when I deploy it like that I get the following error:

createCollectible Sequence has incorrect length, expected 1 but got 2

Which I think is because I give "None" and STATIC_SEED as parameters when the function in the contract only accepts one.

Thanks.

PatrickAlphaC commented 2 years ago

Ahhh, yes. This is outdated, the code in the repo is correct, the video is incorrect. Thanks for finding this!