//Write your own contracts here. Currently compiles using solc v0.4.15+commit.bbb8e64f. pragma solidity ^0.5.0; contract AdvancedToken { // Declare the name, symbol, and decimals of the token string public name = "Advanced Token"; string public symbol = "AT"; uint8 public decimals = 18; // Declare the total supply of the token uint256 public totalSupply; // Mapping of users to their token balances mapping(address => uint256) public balances; // Mapping of users to their allowance of tokens that they have granted to other users mapping(address => mapping(address => uint256)) public allowances; // Event to be emitted when a transfer is made event Transfer(address indexed from, address indexed to, uint256 value); // Event to be emitted when an allowance is granted or updated event Approval(address indexed owner, address indexed spender, uint256 value); // Constructor function to initialize the total supply and assign all tokens to the contract owner constructor(uint256 _totalSupply) public { totalSupply = _totalSupply; balances[msg.sender] = _totalSupply; } // Function to transfer tokens from one user to another function transfer(address _to, uint256 _value) public { // Require that the sender has sufficient balance require(balances[msg.sender] >= _value, "Sender has insufficient balance."); // Transfer the tokens balances[msg.sender] -= _value; balances[_to] += _value; // Emit the Transfer event emit Transfer(msg.sender, _to, _value); } // Function to retrieve the balance of a user function balanceOf(address _owner) public view returns (uint256) { return balances[_owner]; } // Function to grant an allowance of tokens to another user function approve(address _spender, uint256 _value) public { // Set the allowance for the spender allowances[msg.sender][_spender] = _value; // Emit the Approval event emit Approval(msg.sender, _spender, _value); } // Function to retrieve the allowance of a user function allowance(address _owner, address _spender) public view returns (uint256) { return allowances[_owner][_spender]; } // Function to transfer tokens from one user to another, using an allowance granted by the sender function transferFrom(address _from, address _to, uint256 _value) public { // Require that the sender has sufficient balance require(balances[_from] >= _value, "Sender has insufficient balance."); // Require that the spender has sufficient allowance require(allowances[_from][msg.sender] >= _value, "Spender has insufficient allowance."); // Transfer the tokens balances[_from] -= _value; allowances[_from][msg.sender] -= _value; balances[_to] += _value; // Emit the Transfer event emit Transfer(_from, _to, _value); } }
0.4.18