代币合约二

一:初始化npm

命令:npm init,

初始化完成后 在文件中增加package.json

二:初始化truffle项目

命令:truffle init

三:安装合约依赖模块:

npm install zeppelin-solidity

四:编写合约

pragma solidity ^0.4.4;

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

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

contract BloggerCoin is StandardToken {

  string public name = "BloggerCoin";

  string public symbol = "BLC";

  uint8 public decimals = 4;

  uint256 public INITIAL_SUPPLY2= 666666;

  function BloggerCoin() {

    totalSupply_ = INITIAL_SUPPLY2;

    balances[msg.sender] = INITIAL_SUPPLY2;

  }

}

五:编写部署js代码

var Migrations = artifacts.require("./Migrations.sol");

var BloggerCoin = artifacts.require("./BloggerCoin.sol");

module.exports = function(deployer) {

  deployer.deploy(Migrations);

  deployer.deploy(BloggerCoin);

};

六:编译truffle程序

truffle compile

7:开始使用truffle 进行部署

truffle develop

部署:migrate

实例化:合约对象

测试账号余额:

con.balanceOf('0x627306090abab3a6e1400e9345bc60c78a8bef57')

账号转账测试:

con.transfer('0xf17f52151ebef6c7334fad080c5704d77216b732',666)

代币合约二_第1张图片

本文参考:

http://liyuechun.org/2017/09/21/how-to-code-smart-contract-BloggerCoin/

你可能感兴趣的:(代币合约二)