Hi 游客

更多精彩,请登录!

比特池塘 区块链技术 正文

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

忆神姆原们
146 0 0
本教程主要参考以太坊官方博客,外加自己的实践。创建代币不需要自己写代码,只要会复制粘贴就可以搞定,这也是以太坊强大之处。下载钱包首先到这里(https://github.com/ethereum/mist/releases)根据自己的操作系统下载相应的钱包。然后,创建一个以太坊账户。
& l' Y& H+ v2 ]' a4 S
4 H5 A, U+ Y2 d9 p. {; W6 V# p另外,你还需要一点以太币,大多数合约只需要价值不要1毛钱的以太币。如果你没有以太币,又不想到国外交易所折腾,可以选择用微信扫描下面的二维码直接在微信中购买:
5 a$ H; h) M! [' w% n
7 f+ Y) y. ~8 u8 r# {创建账户并购买到1个以太币以后,钱包界面如下,创建新币合约我们要创建的第一个合约是一个代币合约。
, P) P* [% J/ t' g/ w( c7 M; G/ h1 S' Y& t. n; D/ r
以太坊生态系统中的代币可以代表任何可以交易的东西:币(coin)、积分、黄金证券、欠条(IOU)等。
& B- j5 B5 n& h  T4 G, {, Z( F9 o5 {9 A/ i% F
因为所有的代币都以标准化的方式实现一些基本的特性,这样意味着你自己创建的代币将于以太坊钱包、使用相同标准的任何其它客户端或者合约相兼容。点击红框中的Contract(合约)。, T) n( B; |  l+ n. u, s9 L# T

$ t) w( Z* T2 D" F9 b" W将红框中原有的代码删除,将下面的代码粘贴到里面。
' O! Q$ @3 P5 N6 F+ U/ u
  1. /*
    , K7 F3 \, \4 Q
  2. This creates a public tradeable fungible token in the Ethereum Blockchain.4 t  b$ O3 S, Q4 \7 ?( L- B
  3. https://github.com/ethereum/wiki/wiki/Standardized_Contract_APIs: }' T4 B8 c7 E& u- p7 l5 y
  4. Unmodified this will create a cryptoasset with a fixed market cap
    ( V, H+ Z: M" U  [3 s- L
  5. wholly owned by the contract creator. You can create any function$ c! d2 b. T6 D& E8 V6 m
  6. to change this contract, like allowing specific rules for the issuance,
    ) x" N/ q' J4 H7 Q
  7. destruction and freezing of any assets. This contract is intended for
    ( ]" @! s, s% ^4 O5 N5 ?
  8. educational purposes, you are fully responsible for compliance with6 H6 o: c7 h: d) N  [
  9. present or future regulations of finance, communications and the
    ' j, j* n$ }/ y$ D
  10. universal rights of digital beings.
      S8 v6 v5 E8 J
  11. Anyone is free to copy, modify, publish, use, compile, sell, or) U- B4 s2 S& ?1 i) r! m
  12. distribute this software, either in source code form or as a compiled
    " c+ k) W. N1 d* ^8 \" N
  13. binary, for any purpose, commercial or non-commercial, and by any3 k; n* Q6 g4 f4 D& g7 ^9 z
  14. means.9 ]/ b# Y/ g& f# ]# ~2 [0 P
  15. In jurisdictions that recognize copyright laws, the author or authors; h6 G( m7 N5 W
  16. of this software dedicate any and all copyright interest in the
    2 D4 I; ]$ u0 ]( ~( ^, ~4 }5 I6 d
  17. software to the public domain. We make this dedication for the benefit& ?& g  A9 m$ K
  18. of the public at large and to the detriment of our heirs and
    - T( t, A8 ?' ?, G" `& M
  19. successors. We intend this dedication to be an overt act of
    7 e$ u9 H  ~' K" W" S
  20. relinquishment in perpetuity of all present and future rights to this
    * F* i% c) g* s2 i3 h) j8 q0 V
  21. software under copyright law.
    ) b# g: ]0 O3 f8 v% Y5 P
  22. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
    : b* R4 K; o% C/ h5 O
  23. EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
    ; p4 R6 Q6 }1 j
  24. MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
    , m: Z5 |& R2 Z* w
  25. IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR
    ! G1 r' @6 V: j5 [% `
  26. OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
    6 @; b5 ?# B$ m
  27. ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
    ( L/ B6 i  q7 B( q. h- h
  28. OTHER DEALINGS IN THE SOFTWARE.: P% ]! [& ]" @8 ?: r: s
  29. For more information, please refer to
    ! y& y" ]; C! h
  30. */3 H" ?" r- {/ N5 _4 m9 K
  31. contract MyToken {
    3 H' t9 L0 ^6 s! x& ?. m/ K
  32.     /* Public variables of the token */
    1 k: |/ Q2 m4 E5 K3 `# h
  33.     string public name;
    3 P# ?. d4 U% e; P2 N* B5 P
  34.     string public symbol;
    5 f' L0 |* Q+ c( S5 k
  35.     uint8 public decimals;
    9 H8 O- l+ P7 o/ n
  36.     /* This creates an array with all balances */$ t+ J9 a9 @4 c7 U
  37.     mapping (address => uint256) public balanceOf;* j( K7 E( i- X( |, L) ?/ o
  38.     /* This generates a public event on the blockchain that will notify clients */9 {0 A5 |- K8 ]% q+ m3 b# k0 j/ O
  39.     event Transfer(address indexed from, address indexed to, uint256 value);
    ; e* G# m  n  _
  40.     /* Initializes contract with initial supply tokens to the creator of the contract */
    ; u. R+ A+ F2 s* q/ J8 q0 `
  41.     function MyToken(uint256 _supply, string _name, string _symbol, uint8 _decimals) {: v- b# V' T* |% \8 `
  42.         /* if supply not given then generate 1 million of the smallest unit of the token */' C- E( w( W5 e( O1 f8 n; _
  43.         if (_supply == 0) _supply = 1000000;# R% D. }3 H, w) s
  44.         /* Unless you add other functions these variables will never change */
    , B# Y( q- ?0 t
  45.         balanceOf[msg.sender] = _supply;& J9 D. k7 s' ]- v+ T% H
  46.         name = _name;3 ^' D" p2 i/ c" C( v% |
  47.         symbol = _symbol;
    " F8 @/ N' D- y: b# q2 s- n
  48.         /* If you want a divisible token then add the amount of decimals the base unit has  */9 L* k. F# ~+ D$ ~& Z/ q9 L* _
  49.         decimals = _decimals;
    0 l3 |, C6 m) A1 B9 W. M$ t% k4 Y5 \  Y
  50.     }$ X, K4 E! N9 R5 ^5 _- v8 `
  51.     /* Send coins */
    1 M3 d( S! _$ g) F
  52.     function transfer(address _to, uint256 _value) {: {0 {/ U) }. F- U4 V# J; s# p
  53.         /* if the sender doenst have enough balance then stop */5 z5 N$ _7 W8 s
  54.         if (balanceOf[msg.sender] " P, ~& h, }1 P- N4 Q  Q
  55.         if (balanceOf[_to] + _value 3 @) r" {& M' [3 i$ E6 T; ?
  56.         /* Add and subtract new balances */! I& P& R, s, K, @+ A
  57.         balanceOf[msg.sender] -= _value;, B8 A* G$ V5 t
  58.         balanceOf[_to] += _value;: k" x4 P! Y* i7 [7 o- Z, a/ y
  59.         /* Notifiy anyone listening that this transfer took place */
    9 Q# a) n' C8 o& W) V8 z
  60.         Transfer(msg.sender, _to, _value);  V' ~8 M/ I% _- n
  61.     }
    8 ]- F4 N3 }, E% \% _
  62. }
复制代码

4 H5 ~7 J0 d) J2 V" |# L5 Q: e5 |如果代码编译成功,在左边将看到Pick contract,如下图:
# K- S! e6 e. d7 Q  f) R0 q" e5 ?, A8 `: J0 P# u
然后,选择MyToken选项,如下图:
2 j6 k8 J- O3 S2 z& W  T! F) ?8 D
/ x* Q5 L$ ?. Q) q8 F然后,在右边更改系数,定制自己的货币。supply: 货币总量,name: 货币名字,symbol:货币符号,decimals:货币单位精确到小数点后几位。
  S- L1 c; J8 G3 {; C
' Q* {1 o- s1 ^下图定制的Shaopingcoin(少平币),总量10000个,货币符号:WL,货币单位精确到小数点后八位。根据自己的喜好,填写即可。 SELECT FEE(选择费用),左右拖动横轴选择支付多少手续费(这里就需要用到前面购买到的以太币了),越靠近右边,费用越高,完成合约的速度越快。例如,我选择了0.016131个以太币,大约需要30秒完成合约。完成后,点击DEPLOY(部署)。
/ i, j# _/ f# d( W; [! ?/ j( d  E/ O5 @$ F4 z+ q( _) g$ u3 y
点击DEPLOY后,自动转到如下界面,输入密码(即创建账户时设置的 密码),点击SEND TRANSACTION(发送交易)。
7 k$ X" C% @# x4 ?
6 c: w2 n. ^4 W然后,会跳转到钱包主界面,你会看到下面红色方框中的信息,大约需要3-4分钟的确认时间,完成12个确认就可以了。
! B$ T+ S/ A) R3 |' |4 ^& C0 q0 \1 c7 X; {" i5 G  t1 e
显示新创建的货币。确认完毕,然后再进入CONTRACTS(合约)页面,你将看到刚才创建的货币,例如下图中的ShaopingCoin。
- p% l. H/ _; R2 v; r. s  H- z0 P. z9 G! X8 n
点击创建的货币,转到以下界面,复制红色方框中的合约地址,下面的步骤中要用到。1 o9 n0 F0 }# J3 q* y

; s" }* i$ v% R3 l, ]) a再次回到CONTRACTS(合约)页面,点击WATCH TOKEN(查看代币)。
5 [( v) y$ i' M! M* [! ~4 @* |( k
$ q. A2 t/ j; [) ]8 t4 i3 ^弹出如下界面,将刚才复制的地址粘贴到红色方框中,会看到货币的名字、符号等信息。点击OK。
2 a" l( b6 J( |1 B# T1 t- w' B
完成以后,在合约页面就可以看到新创建的货币了。
% m; C9 W) _& a9 ]* }3 Q& U0 ]! i9 [9 {3 d7 r/ ?  r
发送新创建的新货币进入SEND(发送)页面,在右上角的红色方框中输入收款者的账户地址。在AMOUT中填写发送的数量,在右边的红色方框中选择要发送的货币。左右拖动横轴选择费用,越靠近右边费用越高,处理速度越快。下图表示向0xba960dbedc4c2e0774729b2def16764592ced454地址发送10个ShaopingCoin,交易费用是0.00253625个以太币。点击SEND(发送)。- m- m9 |* ?7 l9 {

( b4 Z! P9 `( |4 G$ R- `跳转到如下确认界面,输入密码(即创建账户时设置的密码)。点击SEND TRANSACTION(发送交易)。- t# W& d% d1 [* H& ?: o% K1 {
/ J! d8 P) L5 e( B5 f( y; `5 k
回到WALLETS(钱包)界面,会看到刚刚发出的记录信息。! m" o% n0 [5 P' ]

: m1 s) j( E" {( B. Y收款者需要将新创建的币的添加到WATCH Token中才可以看到收到的币。收款者进入CONTRACT(合约)页面,点击WATCH TOKEN。发送者将创建的新币的合约地址通过聊天工具发给收款者。
' d: s* \+ n; K! t8 U
  E+ g# G- h6 ]% t! a将发送者新创建币的合约地址复制到红色方框中,点击OK。  \- L$ V8 S- _+ w2 c
: Y" M2 a9 p& ^5 I+ V3 Z
收款者在WALLETS(钱包)页面将看到收到的币。下图显示收到了10个ShaopingCoin。
( n3 D7 Q2 A( y" P/ g" S# N
BitMere.com 比特池塘系信息发布平台,比特池塘仅提供信息存储空间服务。
声明:该文观点仅代表作者本人,本文不代表比特池塘立场,且不构成建议,请谨慎对待。
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

成为第一个吐槽的人

忆神姆原们 初中生
  • 粉丝

    0

  • 关注

    0

  • 主题

    16