一:
代币合约代码:
contract EncryptedToken {
uint256 INITIAL_SUPPLY = 666666;
mapping(address => uint256) balances;
function EncryptedToken() {
balances[msg.sender] = INITIAL_SUPPLY;
}
// 转账到一个指定的地址
function transfer(address _to, uint256 _amount) {
assert(balances[msg.sender] < _amount);
balances[msg.sender] -= _amount;
balances[_to] += _amount;
}
// 查看指定地址的余额
function balanceOf(address _owner) constant returns (uint256) {
return balances[_owner];
}
}
二:
部署代币合约:
三:启动truffle
a:编译
truffle complie
b:启动truffle develop
c:migrate :发布
d:实例化合约对象
var daibi
daibi = EncryptedToken.deployed().then(instance => daibi = instance)
测试:当前账号余额
daibi.balanceOf("0x627306090abab3a6e1400e9345bc60c78a8bef57")
测试目标账号:
向目标账号完成转账:
daibi.transfer("0x5aeda56215b167893e80b4fe645ba6d5bab767de",1000)
转账之后 测试目标账号:
测试原账号:
减少2000