1.创建项目
cd /Users/chenxiao/Desktop/GKT
truffle unbox react
屏幕快照 2018-11-29 下午5.40.02.png
屏幕快照 2018-11-29 下午5.42.10.png
2.安装zeppelin-solidity
npm install zeppelin-solidity
屏幕快照 2018-11-29 下午5.42.01.png
3.新建极客币合约
pragma solidity ^0.4.4;
import "zeppelin-solidity/contracts/token/ERC20/StandardToken.sol";
contract GeekToken is StandardToken {
string public name = "GeekToken";
string public symbol = "GKT";
uint8 public decimals = 4;
uint256 public INITIAL_SUPPLY = 10000;
uint256 totalSupply_;
function GeekToken() public {
totalSupply_ = INITIAL_SUPPLY;
balances[msg.sender] = INITIAL_SUPPLY;
}
}
4.配置
var GeekToken = artifacts.require("./GeekToken.sol");
module.exports = function(deployer) {
deployer.deploy(GeekToken);
};
const path = require("path");
module.exports = {
// See <http://truffleframework.com/docs/advanced/configuration>
// to customize your Truffle configuration!
// contracts_build_directory: path.join(__dirname, "client/src/contracts")
migrations_directory: "./migrations",
networks: {
development: {
host: "localhost",
port: 8545,
network_id: "*" // 匹配任何network id
}
},
rinkeby: {
host: "localhost", // Connect to geth on the specified
port: 8545,
network_id: "*",
}
};
5.编译与部署
cd /Users/chenxiao/Desktop/GKT
truffle compile
truffle migrate
屏幕快照 2018-11-29 下午5.48.44.png
6.合约验证
truffle console
//初始化
GeekToken.deployed().then(instance => contract = instance)
//实例一个合约变量
let contract
//查询总量
contract.balanceOf(web3.eth.coinbase)
//查询第二个账户币的持有量
contract.balanceOf(web3.eth.accounts[1])
//转币
contract.transfer(web3.eth.accounts[1], 5000)
屏幕快照 2018-11-29 下午5.49.49.png
屏幕快照 2018-11-29 下午5.52.02.png