I was deploying a NFT and the VRF coordinator takes too much time to respond and I cant see if the _safemint function is working or not. Also i cant verify the contract on rinkeby.io Is there a way to read some variables from a deployed on chain contract ?

Advanced collectible.sol :

// SPDX-License-Identifier: MIT
pragma solidity ^0.6.0;

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

contract AdvancedCollectible is ERC721, VRFConsumerBase{
    uint256 public tokenCounter;
    bytes32 public keyhash;
    uint256 public fee;
    enum Breed{CAT1, CAT2, NFT1, NFT2}
    mapping(uint256 => Breed) public tokenIdToBreed;
    mapping(bytes32 => address) public requestIdToSender;
    event requestedCollectible(bytes32 indexed requestId, address requester);
    event breedAssigned(uint256 indexed tokenId, Breed breed);

    constructor(address _vrfCoordinator, address _linkToken, bytes32 _keyhash, uint256 _fee) public
    VRFConsumerBase(_vrfCoordinator, _linkToken)
    ERC721("Dogie", "NFT")
        tokenCounter = 0;
        keyhash = _keyhash;
        fee = _fee;

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

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

    function setTokenURI(uint256 tokenId, string memory _tokenURI) public {
        // 11:10:43 / 16:22:11   
        require(_isApprovedOrOwner(_msgSender(), tokenId), "ERC721: caller is not owner no approved");
        _setTokenURI(tokenId, _tokenURI);


import time import brownie from scripts.helpful_scripts2 import fund_with_link, get_account, OPENSEA_URL, get_contract from brownie import AdvancedCollectible, config, network

def deploy_and_create():
    account = get_account()
    # print(get_contract('vrf_coordinator'))
    advanced_collectible = AdvancedCollectible.deploy(
    creating_tx = advanced_collectible.createCollectible({"from":account})
    print('Do not try to sleep!')
    # time.sleep(1)
    print(f'New token has been created!  ≧◠‿◠≦✌, {advanced_collectible.tokenCounter()}') # It prints 0 every time

    return advanced_collectible, creating_tx

def main():
Any help will be appriciated
  • Alright, so you want to read a variable value from a deployed contract? It's possible, but only if the variable is public. (Private variables can be read too, but that is more complex).
    – Sky
    May 30, 2022 at 11:26
  • i cant verify the contract on rinkeby.io -> when you use "^" in your contract then you have this problem. use always a specific solidity compiler version and a specific version of openzeppelin
    – Majd TL
    May 30, 2022 at 11:33

1 Answer 1


Yeah, you can read variables from the deployed contract. (Will work for public variable)

Example for brownie:


Or in your case:


I often do this in brownie tests where I have to assert the value of a variable. For example, I set fee to be 1000 then:

assert 1000 == AdvancedCollectible.fee()

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.