Crypto-Currency "Coin Contract" Example

So here is my starting point




pragma solidity ^0.4.18;

//Used like an Interface in C# or Java
contract Token {

    function totalSupply() public constant returns (uint256 supply) {}
    function balanceOf(address _owner) public constant returns (uint256 balance) {}
    function transfer(address _to, uint256 _value) public returns (bool success) {}
    function transferFrom(address _from, address _to, uint256 _value) public returns (bool success) {}
    function approve(address _spender, uint256 _value) public returns (bool success) {}
    function allowance(address _owner, address _spender) public constant returns (uint256 remaining) {}

    //needed to Log the Events
    event Transfer(address indexed _from, address indexed _to, uint256 _value);
    event Approval(address indexed _owner, address indexed _spender, uint256 _value);
    
}



contract StandardToken is Token {
    mapping (address => uint256) balances;
    mapping (address => mapping (address => uint256)) allowed;
    uint256 public totalSupply;
   
    function transfer(address _to, uint256 _value) public returns (bool success) {
        //Default assumes totalSupply can't be over max (2^256 - 1).
        //If your token leaves out totalSupply and can issue more tokens as time goes on, you need to check if it doesn't wrap.
        //Replace the if with this one instead.
        //if (balances[msg.sender] >= _value && balances[_to] + _value > balances[_to]) {
        if (balances[msg.sender] >= _value && _value > 0) {
            balances[msg.sender] -= _value;
            balances[_to] += _value;
            Transfer(msg.sender, _to, _value);
            return true;
        } else { return false; }
    }
    function transferFrom(address _from, address _to, uint256 _value) public returns (bool success) {
        //same as above. Replace this line with the following if you want to protect against wrapping uints.
        //if (balances[_from] >= _value && allowed[_from][msg.sender] >= _value && balances[_to] + _value > balances[_to]) {
        if (balances[_from] >= _value && allowed[_from][msg.sender] >= _value && _value > 0) {
            balances[_to] += _value;
            balances[_from] -= _value;
            allowed[_from][msg.sender] -= _value;
            Transfer(_from, _to, _value);
            return true;
        } else { return false; }
    }
    function balanceOf(address _owner) public constant returns (uint256 balance) {
        return balances[_owner];
    }
    function approve(address _spender, uint256 _value) public returns (bool success) {
        allowed[msg.sender][_spender] = _value;
        Approval(msg.sender, _spender, _value);
        return true;
    }
    function allowance(address _owner, address _spender) public constant returns (uint256 remaining) {
      return allowed[_owner][_spender];
    }

}


//name this contract whatever you'd like
contract AreshToken is StandardToken {

    function () public{
        revert();
    }

    /* Public variables of the token */

    string public name;                   //Aresh Coin
    uint8 public decimals;               //Standard 18
    string public symbol; 
    string public version = 'H1.0';       //Coin ContractVersion

    function AreshToken(
        ) public {
        balances[msg.sender] = 100;               // Give the creator all initial tokens (100 for example)
        totalSupply = 100;                        // Update total supply (100 for example)
        name = "ACoin";                                   // Set the name for display purposes
        decimals = 0;                            // Amount of decimals for display purposes
        symbol = "ATS";                               // Set the symbol for display purposes
    }
}


Below Steps to Deploy the Token

Deploy the Contract using Ethereum TestRpc

Make Sure "Injected Web3" is enabled and click "Create" followed by "Submit"

Open Meta Mask and under the "Tokens" Tab click "Add Token" and paste the Contract Value

The "Token Symbol" and "Decimal Precision" will auto populate once you add the Contract Address

Verify you have the Token and you are Done with your CryptoCurrency Token

You have your Token now Ready to be Sent to Any Wallet.
To Send your Token you will need to use the "TRANSFER" function.

The following are what you need to transfer Tokens to another wallet.
1. The Wallet Key ex. 0x89B7330Dafe97F088DB56C25b624191289Db1690
2. How Many Tokens ex. 7


Just add the following to the "transfer" function: "0x89B7330Dafe97F088DB56C25b624191289Db1690",7
And you should see meta mask confirming the transaction. Wait for a minute to see the Change.

once you login to the other Wallet you should see the Token there Transfered


Comments

Popular posts from this blog

Solidity Hash of Structs (Testing hash uniqueness)

Parity installation on Ubuntu Virtual Machine

Is Making the Crypto Space Legally Compliant Paving the Road to Mass (Blockchain) Adoption?