Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

invalid op code in create collectible #89

Open
0xVinx opened this issue Mar 10, 2022 · 5 comments
Open

invalid op code in create collectible #89

0xVinx opened this issue Mar 10, 2022 · 5 comments

Comments

@0xVinx
Copy link

0xVinx commented Mar 10, 2022

image
in the advanced collectible, it works fine till deploying and funding with link but throws when createCollectible

this is how the solidity looks

function createCollectible() 
        public returns (bytes32){
            bytes32 requestId = requestRandomness(keyhash, fee);
            requestIdToSender[requestId] = msg.sender;
            emit requestedCollectible(requestId, msg.sender);
    }

function fulfillRandomness(bytes32 requestId, uint256 randomNumber) internal override {
    Breed breed = Breed(randomNumber%3);
    uint256 newTokenId = tokenCounter;
    tokenIdToBreed[newTokenId] = breed;
    emit BreedAssigned(newTokenId, breed);
    address owner = requestIdToSender[requestId];
    _safeMint(owner, newTokenId);
    // _setTokenURI(newTokenId, tokenURI);
    tokenCounter = tokenCounter + 1;

}

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

and this is how the python looks

def deploy_and_create():
    account = get_account()
    advanced_collectible = AdvancedCollectible.deploy(
        get_contract("vrf_coordinator").address,
        get_contract("link_token").address,
        config["networks"][network.show_active()]["fee"],
        config["networks"][network.show_active()]["keyhash"],
        {"from": account},
        publish_source=config["networks"][network.show_active()].get("verify", False)
    )
    fund_with_link(advanced_collectible.address)
    tx = advanced_collectible.createCollectible({"from":account})
    tx.wait(1)
    print("created ")

@PatrickAlphaC
Copy link
Owner

Could you please copy paste and format the error?

@0xVinx
Copy link
Author

0xVinx commented Mar 10, 2022

Could you please copy paste and format the error?

Transaction sent: 0xe599c62bfbe22ae839dee3bc8c5132c1bff0ae3f6afd7bd2aa6ff72f7ce20eaa
  Gas price: 0.0 gwei   Gas limit: 12000000   Nonce: 5
  AdvancedCollectible.createCollectible confirmed (invalid opcode)   Block: 6   Gas used: 11812927 (98.44%)

  File "C:\Users\VINAY\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\site-packages\brownie\_cli\run.py", line 51, in main
    return_value, frame = run(
  File "C:\Users\VINAY\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\site-packages\brownie\project\scripts.py", line 103, in run
    return_value = f_locals[method_name](*args, **kwargs)
  File ".\scripts\advanced_collectible\deploy_and_create.py", line 26, in main
    deploy_and_create()
  File ".\scripts\advanced_collectible\deploy_and_create.py", line 17, in deploy_and_create
    tx = advanced_collectible.createCollectible({"from":account})
  File "C:\Users\VINAY\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\site-packages\brownie\network\contract.py", line 1710, in __call__
    return self.transact(*args)
  File "C:\Users\VINAY\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\site-packages\brownie\network\contract.py", line 1583, in transact
    return tx["from"].transfer(
  File "C:\Users\VINAY\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\site-packages\brownie\network\account.py", line 682, in transfer
    receipt._raise_if_reverted(exc)
  File "C:\Users\VINAY\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\site-packages\brownie\network\transaction.py", line 446, in _raise_if_reverted
    raise exc._with_attr(
VirtualMachineError: revert: invalid opcode
Trace step 449, program counter 2265:
  File "C:/Users/VINAY/.brownie/packages/smartcontractkit/chainlink-brownie-contracts@1.1.1/contracts/src/v0.4/vendor/SafeMathChainlink.sol", line 40, in SafeMathChainlink.sub: 

    function sub(uint256 _a, uint256 _b) internal pure returns (uint256) {
      assert(_b <= _a);
      return _a - _b;
Terminating local RPC client...

This is the complete error I get after the link token transfer is complete.

@PatrickAlphaC
Copy link
Owner

Are you running the fund_collectible script? What network is this on?

@0xVinx
Copy link
Author

0xVinx commented Mar 18, 2022

The network is Rinkeby, you can find the deployed contract at https://rinkeby.etherscan.io/address/0x90921d22059d38844f14d84C45003B8E2D7f8CC7#code

the error comes with the createCollectible function after the link token has been transferred as 0.1 link is there in the contract.

this time when I did it, a different error came (idk how), it was :

File "C:\Users\VINAY\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\site-packages\brownie\_cli\run.py", line 51, in main
    return_value, frame = run(
  File "C:\Users\VINAY\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\site-packages\brownie\project\scripts.py", line 103, in run
    return_value = f_locals[method_name](*args, **kwargs)
  File ".\scripts\advanced_collectible\deploy_and_create.py", line 26, in main
    deploy_and_create()
  File ".\scripts\advanced_collectible\deploy_and_create.py", line 17, in deploy_and_create
    tx = advanced_collectible.createCollectible({"from":account})
    return tx["from"].transfer(  File "C:\Users\VINAY\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\site-packages\brownie\network\account.py", line 644, in transfer
    receipt, exc = self._make_transaction(  File "C:\Users\VINAY\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\site-packages\brownie\network\account.py", line 727, in _make_transaction
    raise VirtualMachineError(e) from None  File "C:\Users\VINAY\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\site-packages\brownie\exceptions.py", line 93, in __init__
    raise ValueError(str(exc)) from NoneValueError: Gas estimation failed: 'execution reverted'. This transaction will likely revert. If you wish to broadcast, you must set the gas limit manually.

deploy function in python:

def deploy_and_create():
    account = get_account()
    advanced_collectible = AdvancedCollectible.deploy(
        get_contract("vrf_coordinator").address,
        get_contract("link_token").address,
        config["networks"][network.show_active()]["fee"],
        config["networks"][network.show_active()]["keyhash"],
        {"from": account},
        publish_source=config["networks"][network.show_active()].get("verify", False)
    )
    fund_with_link(advanced_collectible.address)
    tx = advanced_collectible.createCollectible({"from":account})
    tx.wait(1)
    print("created ")

the fund_with_link and everything works fine so I think python is good and the problem is in solidity.
I have looked at it many times and still cannot find what I am doing wrong, google isn't helping much either, am stuck here for a long time now :(

@ReasonZx
Copy link
Contributor

ReasonZx commented Aug 7, 2023

0xVinx what values are you using for the keyhash and fee?

Can you send the full smart contract?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants