Hi 游客

更多精彩,请登录!

比特池塘 区块链技术 正文

教程:用以太坊制作自已的竞争币

忆神姆原们
147 0 0
本教程主要参考以太坊官方博客,外加自己的实践。创建代币不需要自己写代码,只要会复制粘贴就可以搞定,这也是以太坊强大之处。下载钱包首先到这里(https://github.com/ethereum/mist/releases)根据自己的操作系统下载相应的钱包。然后,创建一个以太坊账户。
5 M' A$ P5 v" y4 V9 L# h3 q' `7 A# f( D, O
另外,你还需要一点以太币,大多数合约只需要价值不要1毛钱的以太币。如果你没有以太币,又不想到国外交易所折腾,可以选择用微信扫描下面的二维码直接在微信中购买:+ g7 t6 F% t! }/ a( x( f

5 p- t% b  h7 q$ l; G0 F创建账户并购买到1个以太币以后,钱包界面如下,创建新币合约我们要创建的第一个合约是一个代币合约。
4 W3 [# A+ P; j
3 o& S2 o7 D; W8 X) v, A以太坊生态系统中的代币可以代表任何可以交易的东西:币(coin)、积分、黄金证券、欠条(IOU)等。0 `: z0 m1 c4 d; S. K2 E; n
6 M* I$ n% Z% o5 l; @" r; m
因为所有的代币都以标准化的方式实现一些基本的特性,这样意味着你自己创建的代币将于以太坊钱包、使用相同标准的任何其它客户端或者合约相兼容。点击红框中的Contract(合约)。
1 D' @$ i! h0 t6 \* q
" E* l/ m# N5 o将红框中原有的代码删除,将下面的代码粘贴到里面。0 u' u3 b, p* C& l$ E! J
  1. /*! g2 s& t1 g$ A( p3 M+ F% q
  2. This creates a public tradeable fungible token in the Ethereum Blockchain.% U4 n! {- l) u
  3. https://github.com/ethereum/wiki/wiki/Standardized_Contract_APIs
    ( u& K: O6 d* b( u
  4. Unmodified this will create a cryptoasset with a fixed market cap; C6 C- ], z# `6 \* R4 N# A" m
  5. wholly owned by the contract creator. You can create any function" N5 H# L  P6 d+ v( f! J% \
  6. to change this contract, like allowing specific rules for the issuance,, V3 I% l: K. s) [! E& `  Q
  7. destruction and freezing of any assets. This contract is intended for- x5 l$ F. s& e3 w. n+ y; G% s
  8. educational purposes, you are fully responsible for compliance with5 T9 @- h7 I( O+ Y. I. o& }
  9. present or future regulations of finance, communications and the
    $ j: N7 V, |; B
  10. universal rights of digital beings.
    1 A1 l6 Q! [9 {7 L: g8 v
  11. Anyone is free to copy, modify, publish, use, compile, sell, or
    2 r( q1 x# U9 T: T6 k/ r9 `3 e6 X
  12. distribute this software, either in source code form or as a compiled$ F8 `* n7 J" N9 b3 V- {
  13. binary, for any purpose, commercial or non-commercial, and by any
    ; Y5 a& u" u  J( w! A. M/ r( H
  14. means.
    4 V4 \! J- Q0 e
  15. In jurisdictions that recognize copyright laws, the author or authors2 k+ y" |, h& _
  16. of this software dedicate any and all copyright interest in the+ K; V9 D$ o6 ^4 m
  17. software to the public domain. We make this dedication for the benefit" T; X( M( t, X; f( |
  18. of the public at large and to the detriment of our heirs and
    ! m7 }. b! Z* `: h
  19. successors. We intend this dedication to be an overt act of
    4 @$ E! N9 _7 ^2 `% r1 M4 P
  20. relinquishment in perpetuity of all present and future rights to this9 n( |! k# C6 g5 p. m
  21. software under copyright law.( }6 S" {$ ?7 k. |0 q
  22. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
    ! Y6 l5 n7 T- \
  23. EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
    - i4 D+ W* n, X7 e) k( w3 e( j
  24. MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
    5 d: P* E  _0 ~
  25. IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR: I8 q  V: |2 S% q. E( }2 a- ^( q
  26. OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,! i6 \5 ?7 Z" D" ^* `1 u% I$ \* Z' d
  27. ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR; y+ _5 V; f7 ^
  28. OTHER DEALINGS IN THE SOFTWARE.  z! M' u+ p! a3 _2 _" B( F' _
  29. For more information, please refer to 4 \  R# z& e4 x0 l6 y+ Z
  30. */
    - o0 y. d- {$ J6 e
  31. contract MyToken {8 s! K! Q9 A* F/ {! u' \9 j" U0 [) e
  32.     /* Public variables of the token */
    9 X% P. f& \8 T6 D% A( l. R
  33.     string public name;
    % f# p1 C! {* I8 d
  34.     string public symbol;
    7 L$ P. P" X* J" I1 K& N
  35.     uint8 public decimals;
    8 F" w0 J, c4 g( J
  36.     /* This creates an array with all balances */& g; M# @  q' d2 v3 Q
  37.     mapping (address => uint256) public balanceOf;8 k+ e7 b; ^& U  Q3 i6 P+ Z8 Q" f3 J
  38.     /* This generates a public event on the blockchain that will notify clients */
    ) u: G+ d, A: g  c
  39.     event Transfer(address indexed from, address indexed to, uint256 value);
    - A) }' i0 P/ S9 ?/ Q
  40.     /* Initializes contract with initial supply tokens to the creator of the contract */
    $ w# v% X- ?4 i% C5 S
  41.     function MyToken(uint256 _supply, string _name, string _symbol, uint8 _decimals) {
    + L  B' Q5 V# k# [8 \
  42.         /* if supply not given then generate 1 million of the smallest unit of the token */6 u/ t6 }; f  T
  43.         if (_supply == 0) _supply = 1000000;3 k7 w3 V) j/ m" ~
  44.         /* Unless you add other functions these variables will never change */
    * R  c' h* e5 `  B  G# y
  45.         balanceOf[msg.sender] = _supply;
    # p1 A; Y+ A2 b) A
  46.         name = _name;
    4 }& b+ }, e. m, U( }' _0 A
  47.         symbol = _symbol;
      F4 A/ `3 @2 N6 F5 ^
  48.         /* If you want a divisible token then add the amount of decimals the base unit has  */8 w) `* [0 `2 p- m  I) T
  49.         decimals = _decimals;' n! I* }3 J) B2 F, d5 k! P7 S, d
  50.     }
    ! U+ j# t- O2 ^/ _
  51.     /* Send coins */5 O+ T" O# x: j
  52.     function transfer(address _to, uint256 _value) {
    . j, Y' H* [  o8 `; l2 z1 b
  53.         /* if the sender doenst have enough balance then stop */
    6 ?2 j$ I. S2 n9 y
  54.         if (balanceOf[msg.sender] ( N2 w, |0 G& m, N9 e
  55.         if (balanceOf[_to] + _value 1 [4 o9 F% A  t7 o% `; ?5 Z
  56.         /* Add and subtract new balances */
    * C. F) _% j7 Q
  57.         balanceOf[msg.sender] -= _value;% Z8 G9 Y7 ~6 Q0 d. ~" c; O) x
  58.         balanceOf[_to] += _value;5 \/ c8 a3 I3 }- \" N
  59.         /* Notifiy anyone listening that this transfer took place */, g% U: G3 e" F/ v: x; L
  60.         Transfer(msg.sender, _to, _value);- k6 Q5 `* ~' Z- p
  61.     }
    3 q( s( D6 g6 A# p; v
  62. }
复制代码

9 H0 s6 S+ g3 L. {如果代码编译成功,在左边将看到Pick contract,如下图:
+ I6 r- D" W) Q8 k; @: l; p7 y6 W0 v& g0 o: @2 f; j# f
然后,选择MyToken选项,如下图:. Z  J% F; B0 e
2 V. o3 B4 v0 k" |' h
然后,在右边更改系数,定制自己的货币。supply: 货币总量,name: 货币名字,symbol:货币符号,decimals:货币单位精确到小数点后几位。3 w$ e! a4 [0 N' S# _) m

! J# o  {& ?, e  Z) P下图定制的Shaopingcoin(少平币),总量10000个,货币符号:WL,货币单位精确到小数点后八位。根据自己的喜好,填写即可。 SELECT FEE(选择费用),左右拖动横轴选择支付多少手续费(这里就需要用到前面购买到的以太币了),越靠近右边,费用越高,完成合约的速度越快。例如,我选择了0.016131个以太币,大约需要30秒完成合约。完成后,点击DEPLOY(部署)。
- s( F( h4 ^6 ~1 M: @* ^* K/ ?' t7 Z( E' k8 X+ H, t' i
点击DEPLOY后,自动转到如下界面,输入密码(即创建账户时设置的 密码),点击SEND TRANSACTION(发送交易)。7 J- [( x6 \7 o

& \6 f8 O( v' U4 L8 _然后,会跳转到钱包主界面,你会看到下面红色方框中的信息,大约需要3-4分钟的确认时间,完成12个确认就可以了。
5 n/ L% b/ O4 A6 A' w
/ F& Z1 M  g8 s# i6 F$ @9 r显示新创建的货币。确认完毕,然后再进入CONTRACTS(合约)页面,你将看到刚才创建的货币,例如下图中的ShaopingCoin。
4 w9 O, [  K3 w( q5 C9 ], L3 ?, N  T- G" m( ]
点击创建的货币,转到以下界面,复制红色方框中的合约地址,下面的步骤中要用到。
5 r* E# d4 ^+ P. N7 x% O' n1 i
4 F) }; C0 g! ]再次回到CONTRACTS(合约)页面,点击WATCH TOKEN(查看代币)。
( t9 J: _* n, ~- {  G$ ~8 d  j" w
弹出如下界面,将刚才复制的地址粘贴到红色方框中,会看到货币的名字、符号等信息。点击OK。
- f! G1 a) ^( Z% y& K
5 A! r# o$ D& d+ n* U完成以后,在合约页面就可以看到新创建的货币了。
; O: v# ^2 u& z3 i
- b6 |8 `& M$ l  f* b3 R+ n3 K发送新创建的新货币进入SEND(发送)页面,在右上角的红色方框中输入收款者的账户地址。在AMOUT中填写发送的数量,在右边的红色方框中选择要发送的货币。左右拖动横轴选择费用,越靠近右边费用越高,处理速度越快。下图表示向0xba960dbedc4c2e0774729b2def16764592ced454地址发送10个ShaopingCoin,交易费用是0.00253625个以太币。点击SEND(发送)。
! H. D* D8 G; V2 ^3 Z: d9 t8 E, J+ T6 N6 @: o( d6 q6 E( B
跳转到如下确认界面,输入密码(即创建账户时设置的密码)。点击SEND TRANSACTION(发送交易)。
' O4 O9 F& x: S
5 B3 w( B0 ?+ G1 e回到WALLETS(钱包)界面,会看到刚刚发出的记录信息。& [8 X* m$ t  _. N  x* u3 h
5 y3 A4 C. ]7 \. v* L; d
收款者需要将新创建的币的添加到WATCH Token中才可以看到收到的币。收款者进入CONTRACT(合约)页面,点击WATCH TOKEN。发送者将创建的新币的合约地址通过聊天工具发给收款者。
* A& x' @1 r& h  c6 \
1 D( D9 ~& h& p' v3 v将发送者新创建币的合约地址复制到红色方框中,点击OK。
, K  g* o; E0 y' b- |; e$ J
3 Q" ?. O  k+ w" m. h8 Q7 k收款者在WALLETS(钱包)页面将看到收到的币。下图显示收到了10个ShaopingCoin。
0 {% k9 t( v$ u: T. Q, P
BitMere.com 比特池塘系信息发布平台,比特池塘仅提供信息存储空间服务。
声明:该文观点仅代表作者本人,本文不代表比特池塘立场,且不构成建议,请谨慎对待。
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

成为第一个吐槽的人

忆神姆原们 初中生
  • 粉丝

    0

  • 关注

    0

  • 主题

    16