BasicToken¶
Title: | BasicToken |
Description: | Zeppelin Solidity Smart Contract that implements a Basic form of the ERC-20 standard without allowances, approvals, or transferFrom |
Author: | Smart Contract Solutions, Inc. |
Solidity Version: | ^0.4.18 |
Relative Path: | ./contracts/supporting/BasicToken.sol |
License: | MIT License |
Current Version: | 1.4.0 |
Original Source: | BasicToken Source |
1. Imports & Dependencies¶
The following imports and dependencies exist for the BasicToken Smart Contract :
Name | Description |
ERC20Basic | Zeppelin Solidity Smart Contract for a Basic ERC-20 Compliance |
SafeMath | Zeppelin Solidity Library to perform mathematics safely inside Solidity |
2. Variables¶
There are no variables for the BasicToken Smart Contract.
3. Enums¶
There are no enums for the BasicToken Smart Contract.
4. Events¶
There are no events for the BasicToken Smart Contract.
5. Mappings¶
The following mappings exist for the BasicToken Smart Contract:
Name | Mapping Type | Description |
balances | address => uint256 | Mapping to track token balance of an address |
6. Modifiers¶
There are no modifiers for the BasicToken Smart Contract.
7. Functions¶
The following functions exist for the BasicToken Smart Contract:
Name | Description |
transfer | Function to transfer tokens. |
balanceOf | Function to get the token balance of a given address |
transfer¶
Function Name: | transfer |
Description: | Function to transfer tokens |
Function Type: | N/A |
Function Visibility: | Public |
Function Modifiers: | N/A |
Return Type: | bool |
Return Details: | returns true upon successful transfer |
Code¶
The code for the transfer function is as follows:
function transfer(address _to, uint256 _value) public returns (bool) {
require(_to != address(0));
require(_value <= balances[msg.sender]);
// SafeMath.sub will throw if there is not enough balance.
balances[msg.sender] = balances[msg.sender].sub(_value);
balances[_to] = balances[_to].add(_value);
Transfer(msg.sender, _to, _value);
return true;
}
The transfer function performs the following:
- Checks the _to argument is a valid Ethereum address. If not, it will throw.
- Checks that the _value argument is less than or equal to the msg.sender token balance. If not, it will throw
- Removes the _value from the msg.sender token balance. If the balance is insufficient, it will throw
- Adds the _value to the _to token balance.
- Fires the Transfer event
- Returns true
balanceOf¶
Function Name: | balanceOf |
Description: | Function to get the token balance of an address |
Function Type: | View |
Function Visibility: | Public |
Function Modifiers: | N/A |
Return Type: | uint256 |
Return Details: | returns token balance of address |