command list of how to build your very own token.
1. Install NodeJS
$ npm i -g ganache-cli
$ npm i -g truffle
$ mkdir basic_token
$ cd basic_token
truffle init
$ touch contracts/BasicToken.sol
$ touch migrations/2_deploy_basic_token.js
module.exports = {
networks: {
development: {
host: "127.0.0.1",
port: 8545,
network_id: "*",
}
}
}
$ ganache-cli -u 0
pragma solidity ^0.4.24;
contract BasicToken {
mapping(address => uint256) balances;
string public constant NAME = "BasicToken";
string public constant SYMBOL = "BTN";
uint256 totalSupply_;
event Transfer(address indexed from, address indexed to, uint256 values);
constructor(uint256 INTIAL_SUPPLY) public {
totalSupply_ = INTIAL_SUPPLY;
balances[msg.sender] = INTIAL_SUPPLY;
emit Transfer(0x0, msg.sender, INTIAL_SUPPLY);
}
function totalSupply() public view returns(uint256) {
return totalSupply_;
}
function transfer(address _to, uint256 _value) public returns(bool) {
require(_to != address(0), "Unauthorized");
require(_value <= balances[msg.sender], "Unauthorized");
balances[msg.sender] = balances[msg.sender] - _value;
balances[_to] = balances[_to] _value;
emit Transfer(msg.sender, _to, _value);
return true;
}
function balanceOf(address _owner) public view returns(uint balance) {
return balances[_owner];
}
}
const BasicToken = artifacts.require('./BasicToken.sol');
module.exports = deployer => deployer.deploy(BasicToken, 100000000);
$ truffle migrate
$ truffle console
truffle(development)> BasicToken.deployed().then(t => token = t)
truffle(development)> token.totalSupply().then(s => s.toNumber())
> token.balanceOf(web3.eth.accounts[0]).then(b => b.toNumber())
truffle(development)> token.transfer(web3.eth.accounts[1], 10000)
> token.balanceOf(web3.eth.accounts[0]).then(b => b.toNumber())
> token.balanceOf(web3.eth.accounts[1]).then(b => b.toNumber())