StandardToken¶
Title: | StandardToken |
Description: | Zeppelin Solidity Smart Contract that provides a standard ERC-20 compliant token. |
Author: | Smart Contract Solutions, Inc. |
Solidity Version: | ^0.4.18 |
Relative Path: | ./contracts/supporting/StandardToken.sol |
License: | MIT License |
Current Version: | 1.4.0 |
Original Source: | StandardToken Source |
1. Imports & Dependencies¶
The following imports and dependencies exist for the StandardToken Smart Contract:
Name | Description |
BasicToken | Zeppelin Solidity Smart Contract that implements a Basic form of the ERC-20 standard without allowances, approvals, or transferFrom |
ERC20 | Zeppelin Solidity Smart Contract that provides the interface required to implement an ERC20 compliant token. |
2. Variables¶
There are no variables for the StandardToken Smart Contract.
3. Enums¶
There are no enums for the StandardToken Smart Contract.
4. Events¶
TThere are no events for the StandardToken Smart Contract.
5. Mappings¶
The following mappings exist for the StandardToken Smart Contract:
Name | Mapping Type | Description |
allowed | address => mapping( address => uint256) | Mapping to allowance authorisation |
6. Modifiers¶
There are no modifiers for the StandardToken Smart Contract.
7. Functions¶
The following functions exist for the StandardToken Smart Contract:
Name | Description |
transferFrom | Function transfer tokens from an address to another invoked by an authorised spender address |
approve | Function to approve a particular allowance to be transferred by that spender address on the target address |
allowance | Function to get the approved allowance for a transfer of tokens from an address by a spender address |
increaseApproval | Function to allow increase approved allowance for a spender on a given address |
decreaseApproval | Function to allow decrease approved allowance for a spender on a given address |
transferFrom¶
Function Name: | transferFrom |
Description: | Function transfer tokens from an address to another invoked by an authorised spender address |
Function Type: | N/A |
Function Visibility: | Public |
Function Modifiers: | N/A |
Return Type: | bool |
Return Details: | returns where the transfer was successful or not |
Code¶
The code for the transferFrom function is as follows:
function transferFrom(address _from, address _to, uint256 _value) public returns (bool) {
require(_to != address(0));
require(_value <= balances[_from]);
require(_value <= allowed[_from][msg.sender]);
balances[_from] = balances[_from].sub(_value);
balances[_to] = balances[_to].add(_value);
allowed[_from][msg.sender] = allowed[_from][msg.sender].sub(_value);
Transfer(_from, _to, _value);
return true;
}
The transferFrom 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 _from token balance. If not, it will throw
- Checks that _value argument is less than or equal to the allowed balance for the msg.sender. If not it will throw.
- Removes the _value from the _from token balance. If the balance is insufficient, it will throw
- Adds the _value to the _to token balance.
- Removes the _value from the allowance for this spender on this address.
- Fires the Transfer event
- Returns true
Usage¶
The transferFrom function has the following usage syntax and arguments:
Argument | Type | Details | |
1 | _from | address | Address transfer tokens from |
2 | _to | address | Address transfer tokens to |
3 | _value | uint256 | Number of tokens to transfer |
transferFrom(0x123456789abcdefghijklmnopqrstuvwxyz98765,
0x543456789abcdefghijklmnopqrstuvwxyz12234,
100);
approve¶
Function Name: | approve |
Description: | Function to approve a particular allowance to be transferred by that spender address on the target address |
Function Type: | N/A |
Function Visibility: | Public |
Function Modifiers: | N/A |
Return Type: | bool |
Return Details: | Returns where the approval was successful or not |
Code¶
The code for the approve function is as follows:
function approve(address _spender, uint256 _value) public returns (bool) {
allowed[msg.sender][_spender] = _value;
Approval(msg.sender, _spender, _value);
return true;
}
The approve function performs the following:
- Sets the allowance for the _spender on the msg.sender address to the _value
- Fires the Approval event
- Returns true
allowance¶
Function Name: | allowance |
Description: | Function to approve a particular allowance to be transferred by that spender address on the target address |
Function Type: | View |
Function Visibility: | Public |
Function Modifiers: | N/A |
Return Type: | uint256 |
Return Details: | Returns the Current balance of approved tokens an address can transfer |
increaseApproval¶
Function Name: | increaseApproval |
Description: | Function to increase the existing approved allowance of a spender address on the target address |
Function Type: | N/A |
Function Visibility: | Public |
Function Modifiers: | N/A |
Return Type: | bool |
Return Details: | Current balance of approved tokens an address can transfer |
Code¶
The code for the increaseApproval function is as follows:
function increaseApproval(address _spender, uint _addedValue) public returns (bool) {
allowed[msg.sender][_spender] = allowed[msg.sender][_spender].add(_addedValue);
Approval(msg.sender, _spender, allowed[msg.sender][_spender]);
return true;
}
The increaseApproval function performs the following:
- Adds the _addedValue argument to the current allowance
- Fires the Approval event
- Returns true
Usage¶
The increaseApproval function has the following usage syntax and arguments:
Argument | Type | Details | |
1 | _spender | address | Address to increase the allowance for |
2 | _addedValue | address | Amount to add to the allowance |
increaseApproval(0x123456789abcdefghijklmnopqrstuvwxyz98765,
100);
decreaseApproval¶
Function Name: | decreaseApproval |
Description: | Function to increase the existing approved allowance of a spender address on the target address |
Function Type: | N/A |
Function Visibility: | Public |
Function Modifiers: | N/A |
Return Type: | bool |
Return Details: | Current balance of approved tokens an address can transfer |
Code¶
The code for the increaseApproval function is as follows:
function decreaseApproval(address _spender, uint _subtractedValue) public returns (bool) {
uint oldValue = allowed[msg.sender][_spender];
if (_subtractedValue > oldValue) {
allowed[msg.sender][_spender] = 0;
} else {
allowed[msg.sender][_spender] = oldValue.sub(_subtractedValue);
}
Approval(msg.sender, _spender, allowed[msg.sender][_spender]);
return true;
}
The decreaseApproval function performs the following:
- Calculates the current approved allowance
- If the current value is less than the _subtractedValue argument, the allowance is set to zero
- Otherwise it removes the _subtractedValue argument from the allowance
- Fires the Approval event
- Returns true
Usage¶
The decreaseApproval function has the following usage syntax and arguments:
Argument | Type | Details | |
1 | _spender | address | Address to decrease the allowance for |
2 | _subtractedValue | address | Amount to remove from the allowance |
decreaseApproval(0x123456789abcdefghijklmnopqrstuvwxyz98765,
100);