1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

[Ethereum] macで俺々トークンを作ってみる(調査)

Posted at

概要

SmartContractで自由にトークン発行できるらしいので、
とりあえずエミュレータ上でデプロイと動作確認までやってみる。

Tokenの規格

メジャーなのはこんな感じ。ERC20以外はまだドラフトぽい

  • ERC20
    • 一番ベーシックかつメジャー。弱点はアドレス間違うと戻せない
  • ERC223
    • 間違えた時にリバートできる機能を追加。今後こっちがメジャーになるんじゃないかとの噂
  • ERC721
    • メタデータぶっこめる+委譲できないトークンの作成が可能
    • クリプトキティーはこれ

他165,820などがあるので後日調査

とりあえずERC20で練習

truffleとzeppelinを入れるといいらしい。

npm install -g truffle
mkdir my_erc20_token
cd my_erc20_token
truffle init
-bash: truffle: command not found

パス通ってない。ログ見よう

# これか
> /Users/hoge/.anyenv/envs/ndenv/versions/v6.11.2/bin/truffle -> /Users/hoge/.anyenv/envs/ndenv/versions/v6.11.2/lib/node_modules/truffle/build/cli.bundled.js
vim ~/.bashrc
export PATH=$PATH:/Users/hoge/.anyenv/envs/ndenv/versions/v6.11.2/bin
source ~/.bashrc
truffle init
> Unbox successful. Sweet!
npm init -f
npm install zeppelin-solidity --save

初期設定が済んだので、必要なファイル作成。

vim contracts/MaruToken.sol
===========================
pragma solidity^0.4.19;

contract ERC20Interface {
    function totalSupply() public constant returns (uint);
    function balanceOf(address tokenOwner) public constant returns (uint balance);
    function transfer(address to, uint tokens) public returns (bool success);
    event Transfer(address indexed from, address indexed to, uint tokens);
}

contract MaruToken is ERC20Interface {
    string public symbol;
    string public  name;
    uint8 public decimals;
    uint public _totalSupply;

    mapping(address => uint) balances;
    function MaruToken(uint initialSupply) public {
        symbol = "MRTK";
        name = "MARUTOKEN";
        decimals = 18;
        _totalSupply = initialSupply;
        balances[msg.sender] = initialSupply;
    }

    function totalSupply() public constant returns (uint) {
        return _totalSupply - balances[address(0)];
    }

    function balanceOf(address owner) public constant returns (uint balance){
        return balances[owner];
    }

    function transfer(address to, uint value) public returns (bool success) {
        require(balances[msg.sender] >= value && value > 0);
        balances[msg.sender] = balances[msg.sender] - value;
        balances[to] = balances[to] + value;
        Transfer(msg.sender, to, value);

        return true;

    }
}
vim migrations/2_deploy_contracts.js
========================================
// 拡張子をとったsolidityファイル名を指定
var MaruToken = artifacts.require('MaruToken');

module.exports = function(deployer) {
    const initialSupply = 50000e18
    deployer.deploy(MaruToken, initialSupply);
}
truffle compile
truffle develop 
truffle(develop)> migrate
## 確認
truffle(develop)> maruToken = MaruToken.at(MaruToken.address)
truffle(develop)> maruToken.name()
truffle(develop)> maruToken.totalSupply()
truffle(develop)> maruToken.balanceOf(web3.eth.accounts[0])
truffle(develop)> maruToken.transfer(web3.eth.accounts[1], 1000e18)

できた。なーんか通貨として使うにはガバガバな気がする。
あとで調整。

参考

メモ

solidityが会話に出ると「ソリッディ...」「ソリッド...」等、後半よく聞き取れない事が多かったので調べてみた。

サァリィダァティィ  
http://en.hatsuon.info/word/solidity

1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?