咸鱼

咸鱼是以盐腌渍后,晒干的鱼

0%

6.1、基于truffle发布Token到测试私链

在上一篇文章《6、基于truffle框架部署合约》中,我们已经实现了部署一个简单的合约(sayhello和add),并且在控制台可以调用合约的函数。

本文将使用 《5.1、基于Ganache-Cli用Remix发布Token(代币)》 中sol代码,编译一个比较完整的合约,部署。

修改工程配置

  1. sol代码加入到工程
  2. 修改 1_initial_migration.js文件
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    var Token = artifacts.require("./Token.sol");
    var StandardToken = artifacts.require("./StandardToken.sol");
    var TeaToken = artifacts.require("./TeaToken.sol");

    module.exports = function(deployer) {
    deployer.deploy(Migrations);
    deployer.deploy(Token);
    deployer.deploy(StandardToken);

    //四个参数,是TeaToken的构造函数参数。
    deployer.deploy(TeaToken,"10000000000000000000000","BBCoin",18,"BBC");
    };
    TeaToken的构造函数
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    function TeaToken(
    uint256 _initialAmount, //发行量
    string _tokenName, //token名称
    uint8 _decimalUnits, //小数位
    string _tokenSymbol //标识
    ) {
    // Give the creator all initial tokens
    balances[msg.sender] = _initialAmount;

    // Update total supply
    totalSupply = _initialAmount;

    // Set the name for display purposes
    name = _tokenName;
    // Amount of decimals for display purposes
    decimals = _decimalUnits;

    // Set the symbol for display purposes
    symbol = _tokenSymbol;
    }

编译部署

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
$ truffle compile
$
$ truffle migrate --reset
Using network 'development'.

Running migration: 1_initial_migration.js
Replacing Migrations...
... 0x026473e96e19f2a0a32bc787a9cd5ef7c29cab71e5517e803c29b18d6cb08070
Migrations: 0xe70fc286df987d4eace8dc486cc5492c950e50c6
Deploying Token...
... 0xf503e2b6663ade73b5a60ff7f6b82f6f1e87b07e2629bf5fad6a7bc654cb807b
Token: 0x75aa2709dcee2bcd4fcc530924e0fb90e83a58f5
Deploying StandardToken...
... 0x4385d77ebae77be6efe0b65cf925f40bfaa0e0f518518745a4813d92204c2271
StandardToken: 0x2e6487e4d995dbba857362c7a0542bb76a6f11ae
Deploying TeaToken...
... 0x3687702e5287e22cafd2d6ae3e41d0c3455b1306bca805541b2de174c5841a70
TeaToken: 0x6b528b7717777a90f4db0a96be268fc91610be35
Saving successful migration to network...
... 0x374db95d4ff26b0f9a817fd48dfa2e648193333091a92fb001c6338b9f2b49ee
Saving artifacts...

成功了,记下合约地址:TeaToken: 0x6b528b7717777a90f4db0a96be268fc91610be35