This article covers the following:

  • The development environment of preparation, the reference for the development of actual combat | 3 steps to teach you on the etheric fang (with process + code) to open a pet store

  • Create projects from Truffle Box

  • Write FakeToken smart contract

  • Build and deploy smart contracts

  • Use the new token to transfer money

Benefits:

  • Actually restore the whole development process of issuing new tokens

  • Provide detailed guidance on smart contract deployment related to tokens

  • Fully interpret the 15 lines of code that publish the new token

Here is the process document Bob compiled according to the development process.

1

Preparation of the development environment

Local Environment Mac

This tutorial will use the following environment:

  • Development environment: Node.js, NPM (Node version, v9.11.1, NPM version v5.6.0)

  • Compile the Deployment environment: Truffle (Version 4.1.5, Solidity 0.4.21)

  • Ethereum Private Chain: Ganache (Version 1.1.0)

Development environment for the operation, you can refer to the development of actual combat | 3 steps to teach you on the etheric fang (with process + code) to open a pet store

2

Create a project

BobJianglocal:truffle bobjiang$ truffle unbox tutorialtoken

Truffle framework directory:

  • Contracts / : Smart contract files exist here, suffix. Sol (solidity)

  • Migrations / : Deployment script

  • Test / : Test script

  • Truffle. Js: truffle configuration file

3

Install OpenZeppelin

BobJianglocal:truffle bobjiang$ npm install zeppelin-solidity

4

Writing smart contracts

Create a faketoken.sol file under contracts/ with the following contents:

Pragma solidity ^ 0.4.17;

import ‘zeppelin-solidity/contracts/token/ERC20/StandardToken.sol’;

contract FakeToken is StandardToken {    string public name = ‘FakeToken’;    string public symbol = ‘TT’;    uint8 public decimals = 2;    uint public INITIAL_SUPPLY = 12000;

function FakeToken() public { totalSupply_ = INITIAL_SUPPLY; balances[msg.sender] = INITIAL_SUPPLY; }}

5

Compile the deployment contract

Compile the contract

BobJianglocal:truffle bobjiang$ truffle compile Compiling ./contracts/FakeToken.sol… Compiling ./contracts/Migrations.sol…

Writing artifacts to ./build/contracts

Where there are warnings, you can ignore them. (The visibility of the function was not specified in the original file)

Deployment of contract

1. Create a new file 2_deploy_comes.js in migratios/ :

var FakeToken = artifacts.require(“FakeToken”);

module.exports = function(deployer) {  deployer.deploy(FakeToken); };

2. Make sure the Ganache is installed

The first startup interface after installation is as follows (borrowed source document picture)

3. Smart contracts deployed on Ethereum (private chain)

BobJianglocal:truffle bobjiang$ truffle migrate Using network ‘development’.

Running migration: 1_initial_migration.js Deploying Migrations… . 0x579459f9d2e89ed07356c7565056e082b540c5f441ffcdc1e4676f42536451d5 Migrations: 0x651ee6754b509e0f3413fcb6c88c6c20dc8c9d28 Saving successful migration to network… . 0xfafeb069ba502196abeabef2c097bdd9e4db9ab02c98a9b98d8db47f7d205a9b Saving artifacts… Running migration: 2_deploy_contracts.js Deploying Adoption… . 0xaee412f76fe2ed3853f8e138f009cd8fca23835547a39e23188affef55665460 Adoption: 0x104ba492f5d8f4e0df6971ae09ca0c9b496ff15b Saving successful migration to network… . 0x9219eeba1a1eb945d4fe1fb1bf6cdb2b70218c22b264134cfd97e2f4dfe026ef Saving artifacts…

After the deployment is complete, you can see that there are four transactions (four blocks) :

6

Transfer new tokens

The front to modify

Example Change the default RPC port 9545 to 7545 of ganache

App. Web3Provider = new Web3. Will. HttpProvider (‘ http://127.0.0.1:9545 ‘);

Modify the script that invokes the contract

Change the following tutorialtoken. json to faketoken. json

$.getJSON(‘TutorialToken.json’, function(data) {

Configuration MetaMask

Configure MetaMask to connect to the local ganache

MetaMask creates a new account (the second account in ganache is automatically added)

Start the local HTTP server

BobJianglocal:truffle bobjiang$ npm run dev

Automatically opens a new page, as shown below

transfer

Our newly released token is stored in the first account by default, we are now transferring from the first account to the second account to test our new token

Select the first account in MetaMask and refresh the page to display the above page

In the first input box, enter the address of the second account

In the second input box, enter the transfer amount (here we set decimals to 2, so the transfer amount will be truncated by 2 decimal places)

Click on the “Transfer”

The following page will pop up (MetaMask Wallet)

Click “Submit”, you will receive the prompt of successful transfer

Return to ganache to view a new transaction

Enter MetaMask, click on the second account, and then refresh the page to see that the second account has received the new token

The new token is displayed in the wallet

1. Open your MetaMask wallet, select your first account, and click on the TOKENS TAB below

2. Enter token Contract Address

3. Find the address to create the token contract in ganache, as shown below

4. After entering the token contract address, token Symbols and Decimals are automatically displayed

5. Click Ok

At this point, we can display our new tokens perfectly in the MetaMask wallet.

Reference document: BUILDING ROBUST SMART CONTRACTS WITH OPENZEPPELIN

(address: http://truffleframework.com/tutorials/robust-smart-contracts-with-openzeppelin)

The following is our community introduction, welcome all kinds of cooperation, exchange, learning 🙂