Note: We generally like to call Token as Token, but this is not accurate, if you have to call it Chinese, I agree with the understanding of Token. However, in order to keep the original taste, there is no need to translate it, so this article keeps the English form.

In general, the threshold of Token production is not very high, so everyone has the ability to make their own named Token.

However, you can’t expect to make tokens with extra logic, such as crowdfunding contracts, without learning anything, so there is a cost to doing something different.

To get right to the point, we don’t need to know how to write smart contracts, because the ERC20 protocol provided by Ethereum is silly enough. There is a standard smart contract code as an example to make a simple Token, so we just need to know the process of making smart contracts.

In fact, learning other technical knowledge is the same, we do not rush to pursue very internal things, we need positive feedback learning method, first make some simple Demo, gradually build confidence and stimulate enthusiasm at the same time continue to learn.

Install MetaMask

The first thing you need to do is install MetaMask, a browser plugin by nice, which can be installed on all three major browsers (Google, FireFox, Opera). The process of installing this plug-in is not detailed, but now assuming that we have installed it, click on the plug-in, and after two Accept terms, enter the page for creating an account.

  • The first arrow indicates that we are currently on the Ropsten Test Net Test network. The main difference from the main Ethereum network is that you only recognize the value of Ethereum on the main network, which is mainly used for development testing.
  • The second arrow represents creating an account contract as a legitimate user on the Ethereum network.
  • The third arrow imports an account contract if you have one on the network.

New Contract Account

After entering your password larger than eight characters on the create account page, go to the mnemonic page. These mnemonic words are the only key that will help you save your account contract. Keep them safe.

Buy Ether

Don’t panic. You don’t actually have to pay for it, but it’s just a few clicks of a button on MetaMask’s website to get your Hands on Ether (ether on these test networks has no real value, after all).

Once we’ve saved the mnemonic we’re going to go to the account home page,

Test Ether Faucet

OK, let’s put MetaMask on hold for a while, and then let’s play Remix!

Know want to IDE

Remix is a browser-based Solidity IDE where basic smart contract code development debugging is quite comfortable. Remix – Solidity IDE

  • The first arrow is the project directory bar, where you can create file directories
  • The second arrow is the code bar, where our contract code is written
  • The third arrow is the log bar, where deployment debug log output is displayed
  • The fourth arrow is the debug bar, where contract deployment, debugging and other operations are carried out

Need to be familiar with this tool? Of course, and the more familiar the better, but not now, don’t forget that our goal now is to make our own tokens.

Token contract

The official Ethereum website has a standard Token contract for learners to refer to, as well as detailed tutorials on how to deploy your tokens. Create a cryptocurrency contract in Ethereum

The difference between this paper and the official one is that we use MetaMask, a light wallet, and Remix, an online development environment, for development and debugging deployment. The official Ethereum wallet has a very annoying place for beginners. It is slow to synchronize the data of all nodes of the main network or test network, and it takes up a lot of disk space. Try to keep it light for the first time and don’t leave yourself in a bad mood 🙂

We have copied the official Token contract code into the code column of Remix. The contract code is also attached here:

Pragma solidity ^ 0.4.16; interface tokenRecipient {function receiveApproval(address _from, uint256 _value, address _token, bytes _extraData) public; }

contract TokenERC20 {
    // Public variables of the token
    string public name;
    string public symbol;
    uint8 public decimals = 18;
    // 18 decimals is the strongly suggested default, avoid changing it
    uint256 public totalSupply;

    // This creates an array with all balances
    mapping (address => uint256) public balanceOf;
    mapping (address => mapping (address => uint256)) public allowance;

    // This generates a public event on the blockchain that will notify clients
    event Transfer(address indexed from, address indexed to, uint256 value);

    // This notifies clients about the amount burnt
    event Burn(address indexed from, uint256 value);

    /**
     * Constructor function
     *
     * Initializes contract with initial supply tokens to the creator of the contract
     */
    function TokenERC20(
        uint256 initialSupply,
        string tokenName,
        string tokenSymbol
    ) public {
        totalSupply = initialSupply * 10 ** uint256(decimals);  // Update total supply with the decimal amount
        balanceOf[msg.sender] = totalSupply;                // Give the creator all initial tokens
        name = tokenName;                                   // Set the name for display purposes
        symbol = tokenSymbol;                               // Set the symbol for display purposes
    }

    /**
     * Internal transfer, only can be called by this contract
     */
    function_transfer(address _from, address _to, uint _value) internal { // Prevent transfer to 0x0 address. Use burn() instead require(_to ! = 0x0); // Checkif the sender has enough
        require(balanceOf[_from] >= _value);
        // Check for overflows
        require(balanceOf[_to] + _value > balanceOf[_to]);
        // Save this for an assertion in the future
        uint previousBalances = balanceOf[_from] + balanceOf[_to];
        // Subtract from the sender
        balanceOf[_from] -= _value;
        // Add the same to the recipient
        balanceOf[_to] += _value;
        Transfer(_from, _to, _value);
        // Asserts are used to use static analysis to find bugs in your code. They should never fail
        assert(balanceOf[_from] + balanceOf[_to] == previousBalances);
    }

    /**
     * Transfer tokens
     *
     * Send `_value` tokens to `_to` from your account
     *
     * @param _to The address of the recipient
     * @param _value the amount to send
     */
    function transfer(address _to, uint256 _value) public {
        _transfer(msg.sender, _to, _value);
    }

    /**
     * Transfer tokens from other address
     *
     * Send `_value` tokens to `_to` on behalf of `_from`
     *
     * @param _from The address of the sender
     * @param _to The address of the recipient
     * @param _value the amount to send
     */
    function transferFrom(address _from, address _to, uint256 _value) public returns (bool success) {
        require(_value <= allowance[_from][msg.sender]);     // Check allowance
        allowance[_from][msg.sender] -= _value;
        _transfer(_from, _to, _value);
        return true;
    }

    /**
     * Set allowance forother address * * Allows `_spender` to spend no more than `_value` tokens on your behalf * * @param _spender The address  authorized to spend * @param _value the max amount they can spend */function approve(address _spender, uint256 _value) public
        returns (bool success) {
        allowance[msg.sender][_spender] = _value;
        return true;
    }

    /**
     * Set allowance for other address and notify
     *
     * Allows `_spender` to spend no more than `_value` tokens on your behalf, and then ping the contract about it
     *
     * @param _spender The address authorized to spend
     * @param _value the max amount they can spend
     * @param _extraData some extra information to send to the approved contract
     */
    function approveAndCall(address _spender, uint256 _value, bytes _extraData)
        public
        returns (bool success) {
        tokenRecipient spender = tokenRecipient(_spender);
        if (approve(_spender, _value)) {
            spender.receiveApproval(msg.sender, _value, this, _extraData);
            return true;
        }
    }

    /**
     * Destroy tokens
     *
     * Remove `_value` tokens from the system irreversibly
     *
     * @param _value the amount of money to burn
     */
    function burn(uint256 _value) public returns (bool success) {
        require(balanceOf[msg.sender] >= _value);   // Check if the sender has enough
        balanceOf[msg.sender] -= _value;            // Subtract from the sender
        totalSupply -= _value;                      // Updates totalSupply
        Burn(msg.sender, _value);
        return true;
    }

    /**
     * Destroy tokens from other account
     *
     * Remove `_value` tokens from the system irreversibly on behalf of `_from`.
     *
     * @param _from the address of the sender
     * @param _value the amount of money to burn
     */
    function burnFrom(address _from, uint256 _value) public returns (bool success) {
        require(balanceOf[_from] >= _value);                // Check if the targeted balance is enough
        require(_value <= allowance[_from][msg.sender]);    // Check allowance
        balanceOf[_from] -= _value;                         // Subtract from the targeted balance
        allowance[_from][msg.sender] -= _value;             // Subtract from the sender's allowance totalSupply -= _value; // Update totalSupply Burn(_from, _value); return true; }}Copy the code

Deployment of contract

Next we select the version of our compiler for the first line of the contract code with the pragma Solidity ^0.4.16 version number

Click the TAB of arrow 1 to enter the Settings screen, then click arrow 2 to select the appropriate compiler version, in this case 0.4.16.

Then click the Compile TAB to see that it has been compiled successfully

Then click the Run TAB to deploy

  • The first arrow selects the deployment environment, which automatically detects the network on which our MetaMask is currently located (Ropsten Test Net).
  • The second arrow enters some basic information about our Token
    • The first parameter represents the total number of tokens issued, and I filled in 10 million
    • The second parameter represents the Token name
    • The third parameter indicates the Token symbol, which is generally used as the Token identifier in circulation
  • The third arrow click creates a deployment transaction sheet to begin the final deployment

The only things that can be changed here are the Gas Limit and Gas Price, which are automatically generated based on the current contract complexity and market average. So you don’t need to change these two values. If you’re strapped for cash, you can change them a little lower, but you may run out of Gas (once Gas runs out and the contract is not deployed on the network, all operations will be rolled back except the miner’s fee you paid).

Click SUBMIT and wait for the release to be successful!

The MetaMask page opens

The picture above is in release state and the picture below is in release state. At this point, we can see that our account balance has decreased a bit because it was used to pay miners’ fees for release contracts.

It is not clear whether the Token has been successfully released. Click the transaction sheet to enter the transaction details page, and when you see Success at arrow 1, it means that our Token has been successfully released.

Click the contract address link at arrow 2 to enter the contract details page

Click the Token address link at the arrow to enter the Token details page

At this point our Token is done!

The Token is displayed in the wallet

Let’s take MetaMask as an example to demonstrate that other wallets, such as ImToken, also need to copy the Token address to the past can be seen.

Switch to the Token TAB first

Click Add Token and enter the Token contract address

Click the Add button to see our own tokens on MetaMask.

summary

In the whole process of making Token, there is no difficulty, but most people do not know the process, when they do it once they can immediately start. We’ll go on to play with some more sophisticated smart contracts later, but again, some basic Solidity programming language knowledge and blockchain knowledge is needed. Solidity, the standard ethereum programming language, will be covered in more detail in future articles

Welcome to pay attention to the public account: “Bitbuckle”, and explore the world of blockchain with me.