flutter_web3
flutter_web3 copied to clipboard
How can i check the value of my variable present in the smart contract?
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;
}
}
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.