November 2018
Intermediate to advanced
528 pages
13h 21m
English
Every contract must contain a constructor function that is run only once when the contract is first deployed. In our implementation, the constructor takes the initial supply of tokens as a parameter, which is assigned to the owner of the contract. We also emit a Transfer event, indicating a transfer from address 0 to the contract owner's account. This is considered best practice, but is not required by the standard:
constructor(uint256 _initialSupply) public { balanceOf[msg.sender] = _initialSupply; totalSupply = _initialSupply; emit Transfer(address(0), msg.sender, totalSupply);}We've now written sufficient code to have a functional token, though there are still things we must add before it adheres completely to the ERC-20 ...
Read now
Unlock full access