Hi 游客

更多精彩,请登录!

比特池塘 区块链技术 正文

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

忆神姆原们
150 0 0
本教程主要参考以太坊官方博客,外加自己的实践。创建代币不需要自己写代码,只要会复制粘贴就可以搞定,这也是以太坊强大之处。下载钱包首先到这里(https://github.com/ethereum/mist/releases)根据自己的操作系统下载相应的钱包。然后,创建一个以太坊账户。
1 n( Q! T+ @* n: c" f8 ?
% F# W! [" V0 m8 Y9 t( c另外,你还需要一点以太币,大多数合约只需要价值不要1毛钱的以太币。如果你没有以太币,又不想到国外交易所折腾,可以选择用微信扫描下面的二维码直接在微信中购买:
0 V4 l1 d' f% `
3 z) R# E3 r2 _% d9 w' q9 O创建账户并购买到1个以太币以后,钱包界面如下,创建新币合约我们要创建的第一个合约是一个代币合约。2 L, V- [7 b1 e+ J5 N4 F, Q) a
1 L6 @4 x% f) a  i3 c! f
以太坊生态系统中的代币可以代表任何可以交易的东西:币(coin)、积分、黄金证券、欠条(IOU)等。& E! L% T3 m5 Q5 m

5 k  D" Y7 b# r; I6 [2 ^, D! \1 S因为所有的代币都以标准化的方式实现一些基本的特性,这样意味着你自己创建的代币将于以太坊钱包、使用相同标准的任何其它客户端或者合约相兼容。点击红框中的Contract(合约)。
9 i) }5 X; U3 p* t& m- H+ u1 o  H1 z
" ^. t7 o  g# W7 K& o2 Z将红框中原有的代码删除,将下面的代码粘贴到里面。8 H3 R! r* c+ r" ^- s
  1. /*
    ; b  f+ i3 Z. {+ O6 L, `2 W' S
  2. This creates a public tradeable fungible token in the Ethereum Blockchain.' t. h+ D, \. @4 e1 q
  3. https://github.com/ethereum/wiki/wiki/Standardized_Contract_APIs7 M5 H3 s  \- M; s
  4. Unmodified this will create a cryptoasset with a fixed market cap- a, q6 k" V8 L6 s" y
  5. wholly owned by the contract creator. You can create any function) e# ^8 V% c$ X$ Y( ~% I9 e
  6. to change this contract, like allowing specific rules for the issuance,% T9 q' V  T7 i& i  d
  7. destruction and freezing of any assets. This contract is intended for' G* U  b- M. }% X9 z9 x# L1 Y
  8. educational purposes, you are fully responsible for compliance with
    - k: r4 i+ I/ u8 c
  9. present or future regulations of finance, communications and the# g9 a0 J/ ^: W# k$ l/ ]
  10. universal rights of digital beings.
    " v1 ?7 z, t5 V" f# Q# k
  11. Anyone is free to copy, modify, publish, use, compile, sell, or# ~8 a& z5 m7 H' h
  12. distribute this software, either in source code form or as a compiled
    / d8 n" f2 z0 _6 S9 u% I- u$ G
  13. binary, for any purpose, commercial or non-commercial, and by any) C# l4 R+ r8 D3 u# h2 ?7 J0 q6 z
  14. means.
    . h% z6 T8 {& z+ ^' k
  15. In jurisdictions that recognize copyright laws, the author or authors
    - _9 ?" [1 u8 {" r3 M/ l
  16. of this software dedicate any and all copyright interest in the# `- a! V$ \9 G: u* `6 T; ]
  17. software to the public domain. We make this dedication for the benefit, A% Z/ [- f; `$ U! s
  18. of the public at large and to the detriment of our heirs and3 s5 W6 @7 @$ `& W# L7 D. \
  19. successors. We intend this dedication to be an overt act of
    ; z, ]8 u, ]* H, T1 v
  20. relinquishment in perpetuity of all present and future rights to this# l8 P1 C7 V+ d  G
  21. software under copyright law.6 q8 Q* g% o5 J4 A9 w! O
  22. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,. F8 R( @- x% p- S( R) G+ r
  23. EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF0 ?9 C; U) i2 j: I2 o0 {9 u
  24. MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.% G' ]1 I# q4 C# c# S
  25. IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR/ S( d5 `- T* m+ L! w/ h/ F
  26. OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
    6 @7 ?% h# B9 E1 m
  27. ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
    ( ?! y6 `8 I4 |# p+ H
  28. OTHER DEALINGS IN THE SOFTWARE.
    8 \" j1 I) p- G1 u' P! m9 Q
  29. For more information, please refer to - m8 `. K1 |! \# M: W9 e/ g
  30. */
    , ]/ o) C/ W, I2 K, P
  31. contract MyToken {
    : Y9 s  O% U8 m  U; e! Q
  32.     /* Public variables of the token */" b2 A7 ~& j6 a* R- o
  33.     string public name;
    ) n* U" I/ t) W# P' C
  34.     string public symbol;2 n  h  O$ h& s# W6 x% y6 U
  35.     uint8 public decimals;
    . o) e. p, ]3 l" ?& |3 Q, ?) c
  36.     /* This creates an array with all balances */. P  n0 J" c) g1 W
  37.     mapping (address => uint256) public balanceOf;: G0 j+ Q) v) i' G/ l, k+ G
  38.     /* This generates a public event on the blockchain that will notify clients *// {" Q' H2 t9 V( H  `: A+ f
  39.     event Transfer(address indexed from, address indexed to, uint256 value);# y1 G: m( M: o" q$ R! n3 l3 F0 J! i
  40.     /* Initializes contract with initial supply tokens to the creator of the contract */- |4 N1 r) Z. L/ d
  41.     function MyToken(uint256 _supply, string _name, string _symbol, uint8 _decimals) {
    6 C' u0 F- s* N1 x6 x4 x! q* N' t
  42.         /* if supply not given then generate 1 million of the smallest unit of the token */
    : B+ h; Y% r" c* x
  43.         if (_supply == 0) _supply = 1000000;
    1 t5 S1 Z+ M- |6 h2 g
  44.         /* Unless you add other functions these variables will never change */
      T7 A3 F) l& {8 t# N, S0 i
  45.         balanceOf[msg.sender] = _supply;, Y' [9 p" q$ T4 A( l
  46.         name = _name;8 b+ y. q( }! {/ m; L
  47.         symbol = _symbol;
    . }* i; W  O( p- T4 L6 ]
  48.         /* If you want a divisible token then add the amount of decimals the base unit has  */* B! p. }+ O5 g5 F
  49.         decimals = _decimals;
    # Z0 |3 E' M9 }% Z" U4 @: i/ r
  50.     }
    0 c- c0 ^+ a& }- F# Q0 N
  51.     /* Send coins */0 ?; v% h: H. v% {5 W( a6 m8 O
  52.     function transfer(address _to, uint256 _value) {
    6 ?, c! c  F# n7 a3 g
  53.         /* if the sender doenst have enough balance then stop */' c8 H% n7 [. o0 ?+ P" m" G
  54.         if (balanceOf[msg.sender] , T$ R& M+ \8 Y; b! k' I
  55.         if (balanceOf[_to] + _value 7 F  Y* M( h+ ?
  56.         /* Add and subtract new balances */
    / X! g7 Q. n0 X5 w2 M2 `
  57.         balanceOf[msg.sender] -= _value;. C7 g, O7 O% x
  58.         balanceOf[_to] += _value;
    8 v! R/ y/ d* D8 T0 ]
  59.         /* Notifiy anyone listening that this transfer took place */
    5 ]0 |3 M) h) w( R2 s" V9 Q4 m3 a
  60.         Transfer(msg.sender, _to, _value);5 t" Y- M: @, q0 b& I/ \; k# r! G
  61.     }
    7 D% C9 C0 e3 |! s; ]4 C: v+ ^
  62. }
复制代码
4 Q( i, g, U3 v/ H& i* k3 S
如果代码编译成功,在左边将看到Pick contract,如下图:
3 }9 o" ]: s& s: J6 r9 y5 Y
9 J5 w/ u/ _- V然后,选择MyToken选项,如下图:$ @/ G$ l8 J0 L! f6 x! `
4 [3 B: A! K0 e1 E& v
然后,在右边更改系数,定制自己的货币。supply: 货币总量,name: 货币名字,symbol:货币符号,decimals:货币单位精确到小数点后几位。/ e$ z; v- r% S" F) J! x) t" Y# Z+ Y

. O! p. V" U0 C/ u1 ]2 Q! c下图定制的Shaopingcoin(少平币),总量10000个,货币符号:WL,货币单位精确到小数点后八位。根据自己的喜好,填写即可。 SELECT FEE(选择费用),左右拖动横轴选择支付多少手续费(这里就需要用到前面购买到的以太币了),越靠近右边,费用越高,完成合约的速度越快。例如,我选择了0.016131个以太币,大约需要30秒完成合约。完成后,点击DEPLOY(部署)。
+ f( L* R7 G3 X- y1 V; |3 r! O) g. ^6 \
点击DEPLOY后,自动转到如下界面,输入密码(即创建账户时设置的 密码),点击SEND TRANSACTION(发送交易)。9 l( y3 y) M7 P  E3 }1 h
9 y! p. ^, X! a% [
然后,会跳转到钱包主界面,你会看到下面红色方框中的信息,大约需要3-4分钟的确认时间,完成12个确认就可以了。7 K# D( e& W  t  X/ t: u1 I# `% \

' W" S; h$ D6 j+ |; q. C显示新创建的货币。确认完毕,然后再进入CONTRACTS(合约)页面,你将看到刚才创建的货币,例如下图中的ShaopingCoin。
7 M3 H2 F3 F8 i5 N3 h+ B& _2 J% [1 }( _  \7 o0 q
点击创建的货币,转到以下界面,复制红色方框中的合约地址,下面的步骤中要用到。
/ H$ y" c' X- b: N. ^; t! \" F& e: `5 P- G% Y
再次回到CONTRACTS(合约)页面,点击WATCH TOKEN(查看代币)。) N9 h8 O1 Q. ^; z: N* T+ V

) ~' N$ i3 E# I! r: y0 [& q4 ]弹出如下界面,将刚才复制的地址粘贴到红色方框中,会看到货币的名字、符号等信息。点击OK。2 P2 _$ F. G' R! \% C* }
; S0 l2 h; ^+ {9 M
完成以后,在合约页面就可以看到新创建的货币了。
* F2 L( V- r9 }5 B9 A
+ F5 m' C, a0 H, z: q' v发送新创建的新货币进入SEND(发送)页面,在右上角的红色方框中输入收款者的账户地址。在AMOUT中填写发送的数量,在右边的红色方框中选择要发送的货币。左右拖动横轴选择费用,越靠近右边费用越高,处理速度越快。下图表示向0xba960dbedc4c2e0774729b2def16764592ced454地址发送10个ShaopingCoin,交易费用是0.00253625个以太币。点击SEND(发送)。
+ k5 b& D4 b) f! i7 |+ U7 _/ t, z6 ^- ]
跳转到如下确认界面,输入密码(即创建账户时设置的密码)。点击SEND TRANSACTION(发送交易)。
/ e+ N5 [0 X/ O/ Y
; s4 ~) T" S0 I! P2 e7 }回到WALLETS(钱包)界面,会看到刚刚发出的记录信息。
6 Y" b( G8 u2 R+ Z( d& m& T: J# A8 \) U/ q( {
收款者需要将新创建的币的添加到WATCH Token中才可以看到收到的币。收款者进入CONTRACT(合约)页面,点击WATCH TOKEN。发送者将创建的新币的合约地址通过聊天工具发给收款者。, [( u& ~) w& _

/ p, [% J3 T1 j将发送者新创建币的合约地址复制到红色方框中,点击OK。3 O, A0 q3 h+ y1 V. K2 g

: A, h- Y& N: b* n9 a2 S" Z4 S收款者在WALLETS(钱包)页面将看到收到的币。下图显示收到了10个ShaopingCoin。
) B, U4 W1 S& g
BitMere.com 比特池塘系信息发布平台,比特池塘仅提供信息存储空间服务。
声明:该文观点仅代表作者本人,本文不代表比特池塘立场,且不构成建议,请谨慎对待。
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

成为第一个吐槽的人

忆神姆原们 初中生
  • 粉丝

    0

  • 关注

    0

  • 主题

    16