通过zeppelin-solidity建立标准代币

1、新建目录BLC,进入BLC

2、npm init ;  //初始化package.json

     truffle init; //初始化代币项目

     npm install zeppelin-solidity;//安装代币标准依赖

3、添加合约代码:

pragma solidity >=0.4.24 <0.5.0;
//import编辑器会提示报错,但是不影响
import "zeppelin-solidity/contracts/token/ERC20/StandardToken.sol";

/*solium-disable */
contract SevenCoin is StandardToken {
  string public name = "SevenCoin";
  string public symbol = "Seven";
  uint8 public decimals = 2;
  uint256 public INITIAL_SUPPLY = 666666;

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

4、sudo truffle deploy  //部署合约

5、compile //编译,

这里遇到个坑,当我在编译的时候总是遇到错误,如下:

zeppelin-solidity/contracts/token/ERC20/ERC20Basic.sol:1:1: SyntaxError: Source file requires different compiler version (current compiler is 0.5.0+commit.1d4f565a.Emscripten.clang - note that nightly builds are considered to be strictly less than the released version
pragma solidity ^0.4.24;
^----------------------^
,zeppelin-solidity/contracts/math/SafeMath.sol:1:1: SyntaxError: Source file requires different compiler version (current compiler is 0.5.0+commit.1d4f565a.Emscripten.clang - note that nightly builds are considered to be strictly less than the released version
pragma solidity ^0.4.24;
^----------------------^
,zeppelin-solidity/contracts/token/ERC20/BasicToken.sol:1:1: SyntaxError: Source file requires different compiler version (current compiler is 0.5.0+commit.1d4f565a.Emscripten.clang - note that nightly builds are considered to be strictly less than the released version
pragma solidity ^0.4.24;
^----------------------^
,zeppelin-solidity/contracts/token/ERC20/ERC20.sol:1:1: SyntaxError: Source file requires different compiler version (current compiler is0.5.0+commit.1d4f565a.Emscripten.clang - note that nightly builds are considered to be strictly less than the released version
pragma solidity ^0.4.24;
^----------------------^
,zeppelin-solidity/contracts/token/ERC20/StandardToken.sol:1:1: SyntaxError: Source file requires different compiler version (current compiler is 0.5.0+commit.1d4f565a.Emscripten.clang - note that nightly builds are considered to be strictly less than the released version
pragma solidity ^0.4.24;
^----------------------^
,/Users/seven/Developer/contract/BLC/contracts/SevenCoin.sol:1:1: SyntaxError: Source file requires different compiler version (current compiler is 0.5.0+commit.1d4f565a.Emscripten.clang - note that nightly builds are considered to be strictly less than the released version
pragma solidity ^0.4.24;
^----------------------^

看着报错的意思,大概是编译环境的版本与依赖库版本不符合导致,依赖库不能大于0.5.0,当前编译环境可能大于了,

于是我就去找到truffle-config.js中的compiler项,将里面的version:"0.4.24",之后在编译就好了。

 

6、migrate ;//部署成功

     let constract;

     constract = SevenCoin.deployed().then(instance => contract = instance);

 

7、查看信息:

    constract.totalSupply();//总发行量

     constract.name();//查看当前币的名字,SevenCoin

     constract.symbol();//当前币的简称,Seven

     constract.balanceOf("dizhi");//查看余额

     constract.transfer("dizhi",amount);//转账 

      。。。。。等等  

你可能感兴趣的:(通过zeppelin-solidity建立标准代币)