其他分享
首页 > 其他分享> > truffle官网demo TUTORIALTOKEN

truffle官网demo TUTORIALTOKEN

作者:互联网

项目地址:https://www.trufflesuite.com/boxes/tutorialtoken

项目结构

{
  "#name": "定义项目的名称,版本",
  "name": "tutorialtoken",
  "version": "1.0.0",
  "description": "",
  "main": "truffle-config.js",
  "directories": {
    "test": "test"
  },
  "#scripts": "定义可执行的脚本,在执行项目的时候npm run dev,这个dev取决于配置的这个名字",
  "scripts": {
    "//":"lite-server,可以用来搭建本地server服务器,默认读取bs-config.json文件",
    "dev": "lite-server",
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "author": "",
  "license": "ISC",
  "devDependencies": {
    "#lite-server": "lite-server,可以用来搭建本地server服务,默认读取bs-config.json",
    "lite-server": "^2.3.0"
  }
}
{
  "//":"将端口变为4000",
  "port":"4000",
  "server": {
    "baseDir": ["./src", "./build/contracts"]
  }
}

C:\Users\28694\Desktop\token\token>cnpm install openzeppelin-solidity

在 /contracts 目录下创建 TutorialToken.sol

pragma solidity ^0.5.0;

import 'openzeppelin-solidity/contracts/token/ERC20/ERC20.sol';

// 使用is 來繼承ERC20合約
contract TutorialToken is ERC20 {

    string public name = 'TutorialToken';
    // 代币符号
    string public symbol = 'TT';
    //代币精度
    uint public decimals = 2;
    // 发行代币的总数量
    uint public INITIAL_SUPPLY = 12000;

    //构造函数
    construct() public {
      _mint(msg.sender,INITIAL_SUPPLY);
    }

    function () {
      totalSupply = INITIAL_SUPPLY;
      balances[msg.sender] = INITIAL_SUPPLY;
    }
}


创建迁移文件 2_initial_migration.js

var TutorialToken = artifacts.require("TutorialToken");

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

部署操作

C:\Users\28694\Desktop\token\token>truffle develop
C:\Users\28694\Desktop\token\token>migrate

报错

truffle(develop)> deploy --reset

Compiling your contracts...
===========================
> Compiling .\contracts\Migrations.sol
> Compiling .\contracts\TutorialToken.sol
> Compiling openzeppelin-solidity/contracts/token/ERC20/ERC20.sol

openzeppelin-solidity/contracts/token/ERC20/ERC20.sol:85:45: ParserError: Expected '{' but got reserved keyword 'override'
    function decimals() public view virtual override returns (uint8) {
                                            ^------^

Compilation failed. See above.

openzeppelin版本问题 重新安装2.0.0版本(未解决)

标签:TUTORIALTOKEN,function,contracts,App,TutorialToken,web3,token,truffle,官网
来源: https://www.cnblogs.com/zcmuer/p/14815871.html