前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >使用zeppelin-solidity建立标准代币

使用zeppelin-solidity建立标准代币

作者头像
foochane
发布2019-05-23 15:41:28
7740
发布2019-05-23 15:41:28
举报
文章被收录于专栏:foochanefoochane

1 构建工程

1.1 使用truffle创建工程 $ truffle init

代码语言:javascript
复制
$ truffle init
Downloading...
Unpacking...
Setting up...
Unbox successful. Sweet!

Commands:

  Compile:        truffle compile
  Migrate:        truffle migrate
  Test contracts: truffle test

1.2 生成package.json文件,运行命令: $ npm init

代码语言:javascript
复制
$ npm init
This utility will walk you through creating a package.json file.
It only covers the most common items, and tries to guess sensible defaults.

See `npm help json` for definitive documentation on these fields
and exactly what they do.

Use `npm install <pkg>` afterwards to install a package and
save it as a dependency in the package.json file.

Press ^C at any time to quit.
package name: (deepcoin) dpc
version: (1.0.0) 
description: 
entry point: (truffle-config.js) 
test command: 
git repository: 
keywords: 
author: 
license: (ISC) 
About to write to /home/fc/work/truffledemo/deepcoin/package.json:

{
  "name": "dpc",
  "version": "1.0.0",
  "description": "",
  "main": "truffle-config.js",
  "directories": {
    "test": "test"
  },
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "author": "",
  "license": "ISC"
}

2 安装OpenZeppelin

OpenZeppelin是一个加密合约函数库,提供了兼容ERC20的智能合约,可以使用它来简化钱包的开发过程。 使用npm进行安装

sudo npm install zeppelin-solidity

3 编写代码

3.1 在contracts目录下,创建DeepCoin.sol文件,内容如下:

代码语言:javascript
复制
pragma solidity ^0.4.4;
import "../node_modules/zeppelin-solidity/contracts/token/ERC20/StandardToken.sol";

contract DeepCoin is StandardToken {
  string public name = "DeepCoin";
  string public symbol = "DPC";
  uint8 public decimals = 4;
  uint256 public INITIAL_SUPPLY = 888888;
  constructor() public{
    totalSupply();
    balances[msg.sender] = INITIAL_SUPPLY;
  }
}

3.2 在migrations下面创建2_deploy_deepcoin.js文件,内容如下:

代码语言:javascript
复制
var DeepCoin = artifacts.require("./DeepCoin.sol");

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

4 编译、部署、运行

进入控制台:$ truffle develop 编译:compile 部署: migrate 第二次部署:migrate --reset 创建实例:let contract = DeepCoin.deployed().then(instance => contract = instance);

Accounts: (0) 0x627306090abab3a6e1400e9345bc60c78a8bef57 (1) 0xf17f52151ebef6c7334fad080c5704d77216b732

contract.name(); contract.symbol(); contract.decimals(); contract.INITIAL_SUPPLY(); contract.balanceOf("0x627306090abab3a6e1400e9345bc60c78a8bef57"); contract.balanceOf("0xf17f52151ebef6c7334fad080c5704d77216b732"); contract.transfer("0xf17f52151ebef6c7334fad080c5704d77216b732",8888);

本文参与 腾讯云自媒体分享计划,分享自作者个人站点/博客。
原始发表:2018.07.08 ,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体分享计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • 1 构建工程
  • 2 安装OpenZeppelin
  • 3 编写代码
  • 4 编译、部署、运行
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档