The Iron Coin, Solidity, and Remix

in solidity •  7 years ago 

IronCoin.jpg
I wrote this on Remix, using Solidity.

The Iron Coin is a class that is ERC-20 compatible token that I am playing with in the JavaScript VM.

6 Specific functions must be included and exact to enable ERC-20 compatibility:

  1. totalSupply [Get the total token supply]
  2. balanceOf(address _owner) constant returns (uint256 balance) [Get the account balance of another account with address _owner]
  3. transfer(address _to, uint256 _value) returns (bool success) [Send _value amount of tokens to address _to]
  4. transferFrom(address _from, address _to, uint256 _value) returns (bool success)[Send _value amount of tokens from address _from to address _to]
  5. approve(address _spender, uint256 _value) returns (bool success) [Allow _spender to withdraw from your account, multiple times, up to the _value amount. If this function is called again it overwrites the current allowance with _value]
  6. allowance(address _owner, address _spender) constant returns (uint256 remaining) [Returns the amount which _spender is still allowed to withdraw from _owner]

It is very basic, composed of 76 lines of code, and is a proof of concept token coin. Solidity is a language that models itself closely to JavaScript, but its file extension is .sol instead of .js

// IronCoin.sol
// "We pay the Iron Price"
//  ~dwulf
// 76 lines of code

// The version of Solidity
pragma solidity ^0.4.0;


// The class of the IronCoin
contract IronCoin {
    
    mapping(address => uint) balances;
    mapping(address => mapping(address => uint)) approved;
    
    uint supply;
    
    // ERC-20
    // These 6 functions must be included to be ERC-20 compatable
    
    function totalSupply() constant returns (uint totalSupply){
        return supply;
    }
    
    
    function balanceOf(address _owner) constant returns (uint balance){
        return balances[_owner];
    }
    
    function transfer(address _to, uint _value) returns (bool success){
        
        if(balances[msg.sender] >= _value && _value > 0){
            
            balances[msg.sender]-=_value;
            balances[_to] += _value;
            
            // Successful Transaction
            return true;
            
        }
        else{
            // Failed Transaction
            return false;
            
        }
    }
    
    function approve(address _spender. uint _value) returns (bool success){
        
        if(balances[msg.sender] >= _value){
            approved[msg.sender][_spender] = _value;
            return true;
        }
        
        return false;
        
    }
    
    function allowance(address _owner, address _spender) constant returns (uint remaining){
        
        return approved[_owner][_spender];
        
    }

    
    // Our own functions not apart of the 6 ERC-20 standard functions
    function mint(uint numberOfCoins){
        balances[msg.sender] += numberOfCoins;
        supply += numberOfCoins;
    }
    
    function getMyBalance() returns (uint){
        return balances[msg.sender];
    }
}// end The class of the IronCoin

Remember in crypto we pay the Iron Price:

Iron price. The iron price in crypto/blockchain culture refers to warriors acquiring possessions by taking them from defeated adversaries (banks, federal reserve, and tyrannical governments), rather than purchasing items with (fiat) currency, which is referred to as the gold price.

Authors get paid when people like you upvote their post.
If you enjoyed what you read here, create your account today and start earning FREE STEEM!