flutter_web3 icon indicating copy to clipboard operation
flutter_web3 copied to clipboard

How can i check the value of my variable present in the smart contract?

Open deepaklohmod6789 opened this issue 2 years ago • 1 comments

I wanna check the value of tokenCounter. Do I need to create a function which will return the value or I can access it directly with some predefined function present in the package?

contract AdvancedCollectible is ERC721 {
    uint256 public tokenCounter;

    constructor() public ERC721("Birds", "B") {
        tokenCounter = 0;
    }

    function createCollectible(string memory tokenUri)
        public
        returns (uint256)
    {
        uint256 newTokenId = tokenCounter;
        _safeMint(msg.sender, newTokenId);
        _setTokenURI(newTokenId, tokenUri);
        tokenCounter += 1;
        return tokenCounter;
    }
}

deepaklohmod6789 avatar Mar 18 '22 10:03 deepaklohmod6789

Hello, @deepaklohmod6789. As for solidity if you declare a variable public internally the language creates a get for it. Simply means you do not need an extra function to access the variable, just access it by name as you access the functions.

4xMafole avatar Jan 17 '23 23:01 4xMafole