创建文件夹:mkdir BLC
进入后执行:truffle init
再执行:npm init,一直回车
再执行:npm install zeppelin-solidity
hisee@liu:/media/hisee/本地磁盘2/MyCodes/BlockChain/BLC$ npm install zeppelin-solidity
npm WARN deprecated zeppelin-solidity@1.12.0: This package has been renamed to openzeppelin-solidity. Please update your dependency, or you will no longer receive updates.
npm notice created a lockfile as package-lock.json. You should commit this file.
npm WARN blc@1.0.0 No description
npm WARN blc@1.0.0 No repository field.
+ zeppelin-solidity@1.12.0
added 1 package from 1 contributor in 1.891s
hisee@liu:/media/hisee/本地磁盘2/MyCodes/BlockChain/BLC$
hisee@liu:/media/hisee/本地磁盘2/MyCodes/BlockChain/BLC$ ll
总用量 4
drwxrwxrwx 1 hisee hisee 520 10月 7 14:32 ./
drwxrwxrwx 1 hisee hisee 536 10月 7 14:07 ../
drwxrwxrwx 1 hisee hisee 0 10月 7 14:16 contracts/
drwxrwxrwx 1 hisee hisee 0 10月 7 14:16 migrations/
drwxrwxrwx 1 hisee hisee 168 10月 7 14:32 node_modules/
-rwxrwxrwx 1 hisee hisee 311 10月 7 14:32 package.json*
-rwxrwxrwx 1 hisee hisee 334 10月 7 14:32 package-lock.json*
drwxrwxrwx 1 hisee hisee 0 10月 7 14:16 test/
-rwxrwxrwx 1 hisee hisee 545 10月 7 14:16 truffle-config.js*
-rwxrwxrwx 1 hisee hisee 545 10月 7 14:16 truffle.js*
hisee@liu:/media/hisee/本地磁盘2/MyCodes/BlockChain/BLC$
创建BloggerCoin合约
pragma solidity ^0.4.4;
import "zeppelin-solidity/contracts/token/ERC20/StandardToken.sol";
contract BloggerCoin is StandardToken {
string public name = "BloggerCoin";
string public symbol = "BLC";
uint8 public decimals = 4;
uint256 public INITIAL_SUPPLY = 10000000;
constructor() {
uint256 totalSupply = INITIAL_SUPPLY;
balances[msg.sender] = INITIAL_SUPPLY;
}
}
接着执行 truffle develop ---> compile
创建2_deploy_BloggerCoin.js文件
var BloggerCoin = artifacts.require("./BloggerCoin.sol");
module.exports = function(deployer) {
deployer.deploy(BloggerCoin);
};
再执行:migrate
声明一个contract变量,并赋值。
truffle(develop)> let contract
undefined
truffle(develop)> contract = BloggerCoin.deployed().then(instance => contract = instance)
进行查询转账等操作
truffle(develop)> contract.name();
'BloggerCoin'
truffle(develop)> contract.symbol()
'BLC'
truffle(develop)> contract.INITIAL_SUPPLY()
BigNumber { s: 1, e: 7, c: [ 10000000 ] }
truffle(develop)> contract.balanceOf(web3.eth.coinbase)
BigNumber { s: 1, e: 7, c: [ 10000000 ] }
truffle(develop)> contract.balanceOf(web3.eth.accounts[1])
BigNumber { s: 1, e: 0, c: [ 0 ] }
truffle(develop)> contract.transfer(web3.eth.accounts[1],1000)
{ tx: '0x0dfe484bd557e4fbdf44769f1bd58ef1dcbd055a0ea37c26147f4e0828bd1d13',
receipt:
{ transactionHash: '0x0dfe484bd557e4fbdf44769f1bd58ef1dcbd055a0ea37c26147f4e0828bd1d13',
transactionIndex: 0,
blockHash: '0xcc76adb90e1ea1c0226083df7df1072a8811596c3bf75041b79f1e7389789670',
blockNumber: 5,
gasUsed: 51633,
cumulativeGasUsed: 51633,
contractAddress: null,
logs: [ [Object] ],
status: '0x01',
logsBloom: '0x00000000000000000000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000000010000008000000000000000000010000000080000000000000000000000000000000000000000000000000000000000000000010000000000000000000010000000000000000000000000000000000000000010000000002000000000000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000000000010000000000000' },
logs:
[ { logIndex: 0,
transactionIndex: 0,
transactionHash: '0x0dfe484bd557e4fbdf44769f1bd58ef1dcbd055a0ea37c26147f4e0828bd1d13',
blockHash: '0xcc76adb90e1ea1c0226083df7df1072a8811596c3bf75041b79f1e7389789670',
blockNumber: 5,
address: '0x345ca3e014aaf5dca488057592ee47305d9b3e10',
type: 'mined',
event: 'Transfer',
args: [Object] } ] }
truffle(develop)> contract.balanceOf(web3.eth.accounts[1])
BigNumber { s: 1, e: 3, c: [ 1000 ] }
truffle(develop)>