I'm learning solidity on remix I'm also referencing this open source api for token creation.

Right here they provide a _totalSupply() function that I'd like to wire to my smart contract so it shows the total amount of tokens why I deploy it.

What am doing wrong here?

pragma solidity ^0.8.0; import ""; contract Foobar is ERC20 { constructor(uint256 initialSupply) public ERC20("Foobar", "FOO") { _mint(msg.sender, initialSupply); // add totalSupply here _totalSupply(uint256 5000000000000000000000000000000000000000); } } 

2 Answers

OpenZeppelin ERC20 _totalSupply is a private property, which means you can't access it from a derived contract (in your case Foobar).

Also your syntax is incorrect. If the property were at least internal, you could set its value as

_totalSupply = 5000000000000000000000000000000000000000; 

or in a more readable way

_totalSupply = 5 * 1e39; 

If you want to change its visibility, you'll need to copy the (parent) ERC20 contract to your IDE and change the import statement to reflect the new (local) location. Then you'll be able to update the property visibility in your local copy of the contract.

Mind that the OpenZeppelin ERC20 contains relative import paths (e.g. import "./IERC20.sol";). You'll need to rewrite these in your local copy as well, so that they point back to the GitHub locations. Otherwise, the compiler would be trying to import non-existing local files.

1

OpenZeppelin contracts automatically update totalSupply when you mint or burn tokens. They also automatically expose this as a variable you can read. You do not need, and you should not and you cannot set totalSupply by hand, because then the number of distributed tokens would not match the total supply.

2

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy