Hi 游客

更多精彩,请登录!

比特池塘 区块链技术 正文

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

忆神姆原们
210 0 0
本教程主要参考以太坊官方博客,外加自己的实践。创建代币不需要自己写代码,只要会复制粘贴就可以搞定,这也是以太坊强大之处。下载钱包首先到这里(https://github.com/ethereum/mist/releases)根据自己的操作系统下载相应的钱包。然后,创建一个以太坊账户。
3 Y! q7 F% }3 {# ~4 W; G4 m
0 `0 L; l. T4 m' @! U另外,你还需要一点以太币,大多数合约只需要价值不要1毛钱的以太币。如果你没有以太币,又不想到国外交易所折腾,可以选择用微信扫描下面的二维码直接在微信中购买:9 r2 f( X, C, F' e3 f# {6 ?

9 N2 {$ T6 |7 p2 W! [创建账户并购买到1个以太币以后,钱包界面如下,创建新币合约我们要创建的第一个合约是一个代币合约。: `) m! M' {; a1 I, A
+ R# R% q. s& F/ _
以太坊生态系统中的代币可以代表任何可以交易的东西:币(coin)、积分、黄金证券、欠条(IOU)等。5 k  w$ e. }* B

1 [" W5 m$ m5 q' k( J" z因为所有的代币都以标准化的方式实现一些基本的特性,这样意味着你自己创建的代币将于以太坊钱包、使用相同标准的任何其它客户端或者合约相兼容。点击红框中的Contract(合约)。
+ B& t$ `0 Y! c/ L0 Z. t, b/ t. q
将红框中原有的代码删除,将下面的代码粘贴到里面。
3 R- R5 X) V7 Q3 t
  1. /*( S) @8 P8 ~: n$ J
  2. This creates a public tradeable fungible token in the Ethereum Blockchain.- g. {- ?2 z9 G3 N" x' G/ q& K  q9 }
  3. https://github.com/ethereum/wiki/wiki/Standardized_Contract_APIs
    + z) g$ R# p1 J) w, y, I! G0 v
  4. Unmodified this will create a cryptoasset with a fixed market cap
    3 C1 G- r* J7 |# O0 |5 k$ A) [
  5. wholly owned by the contract creator. You can create any function
    ( J# z' |9 Y& v/ E8 x
  6. to change this contract, like allowing specific rules for the issuance,
    ! w" `9 ?& K. y- t
  7. destruction and freezing of any assets. This contract is intended for
    : C# M5 `3 G# f! q8 L/ \4 N
  8. educational purposes, you are fully responsible for compliance with
    5 r* [. [2 K* d) t# N
  9. present or future regulations of finance, communications and the
    6 W5 {( E4 Q& T% C; f* q
  10. universal rights of digital beings.
    # F( r. r# i) ~6 e
  11. Anyone is free to copy, modify, publish, use, compile, sell, or
    5 i2 x3 H' E: e& U
  12. distribute this software, either in source code form or as a compiled
    ) v7 M2 ~) A( ]+ J
  13. binary, for any purpose, commercial or non-commercial, and by any- z5 n2 |7 {) ]4 j4 ^
  14. means., v( F+ n" _1 h6 u
  15. In jurisdictions that recognize copyright laws, the author or authors
    ( ^% i7 N4 E) `) v) o
  16. of this software dedicate any and all copyright interest in the& N' n% r( x- O6 Z9 o* a: z
  17. software to the public domain. We make this dedication for the benefit2 Z8 A- o9 C; Z4 ?4 R+ c5 ~
  18. of the public at large and to the detriment of our heirs and: a* |; v2 [! U+ ?0 \7 Q% V2 M7 g
  19. successors. We intend this dedication to be an overt act of
    1 h" u* H2 r! u  P+ q/ P/ m$ l: ]0 z
  20. relinquishment in perpetuity of all present and future rights to this
    7 l% y5 ]$ ~5 h0 ]" U- @
  21. software under copyright law.5 ]5 J* {6 Y* d& L" _4 t$ i! ~+ R7 p
  22. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,4 l& E# `( q% p9 N  b
  23. EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF' Y. C: ], t6 W2 s8 e5 X" i' g
  24. MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.2 j/ H% D4 ~# F+ ^$ {! \7 b" |
  25. IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR
    4 }. G# k  H6 F
  26. OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
    4 R, i9 y+ m& R  V
  27. ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
    6 R/ x  y: `2 j
  28. OTHER DEALINGS IN THE SOFTWARE.9 A$ y0 _' F" I
  29. For more information, please refer to
    + e! K' L( ~5 e
  30. */
    & E0 `' s% v0 t
  31. contract MyToken {; v' s& Q( v& T! w, G
  32.     /* Public variables of the token */
    * E# g6 Y: O4 i8 U' q: J
  33.     string public name;: ?9 p: p  G6 p2 Y* C' i  n
  34.     string public symbol;
    * @  w" f! p4 h: M+ J$ z
  35.     uint8 public decimals;
    ; L& u. V) j* v: Q
  36.     /* This creates an array with all balances */3 {+ y- z; W0 {7 i+ f. S0 {, F/ T
  37.     mapping (address => uint256) public balanceOf;
    ( I0 G. R, b3 e2 j6 ^& f0 L2 X% S
  38.     /* This generates a public event on the blockchain that will notify clients */
    ' p$ X7 a/ R; P3 @4 w* Y
  39.     event Transfer(address indexed from, address indexed to, uint256 value);
    ) F, |# e; ]3 Y$ B
  40.     /* Initializes contract with initial supply tokens to the creator of the contract */
    ( r) l% ?9 H# A; }% O6 m
  41.     function MyToken(uint256 _supply, string _name, string _symbol, uint8 _decimals) {# y; u( \; `4 g# ~/ \
  42.         /* if supply not given then generate 1 million of the smallest unit of the token */
    $ |' \- d- K9 t3 l
  43.         if (_supply == 0) _supply = 1000000;% `+ C8 |& @5 C% L9 {. t& e
  44.         /* Unless you add other functions these variables will never change */
    5 b" `8 L# O$ K* X$ h/ J4 X
  45.         balanceOf[msg.sender] = _supply;
    4 G  R! m% T+ l; h
  46.         name = _name;% S8 {: s$ S  q+ d0 V! x7 w
  47.         symbol = _symbol;3 H0 b, Q' P' O
  48.         /* If you want a divisible token then add the amount of decimals the base unit has  */2 `, M6 H& ]9 e( H+ i  ^
  49.         decimals = _decimals;
    . M2 S. l. t2 B! n& ?
  50.     }& w$ T/ v0 ~' a! C
  51.     /* Send coins */
    : O9 r7 u7 Y. \6 D' |9 ?
  52.     function transfer(address _to, uint256 _value) {
    ! P( l+ O+ O: W$ d# }
  53.         /* if the sender doenst have enough balance then stop */
    & `/ @, I5 ]2 _! ^& O: t, R
  54.         if (balanceOf[msg.sender] 9 o6 m4 K; J( \& e, s
  55.         if (balanceOf[_to] + _value
    0 n# d# R* X, ~/ H9 ?
  56.         /* Add and subtract new balances */6 J& O5 H/ j# p! s9 N
  57.         balanceOf[msg.sender] -= _value;
    . c0 ^2 D, p, m7 @8 e* f
  58.         balanceOf[_to] += _value;, Y2 ?2 W9 S6 E/ k+ u* b
  59.         /* Notifiy anyone listening that this transfer took place */% j; B! u% V  f4 s1 c4 A6 i1 _, P
  60.         Transfer(msg.sender, _to, _value);
    % h. H/ S8 x& }4 U
  61.     }2 |; H. G9 e8 E4 O; ]- T  W
  62. }
复制代码
1 Y, P$ A( \+ `& U( x/ \9 k5 }
如果代码编译成功,在左边将看到Pick contract,如下图:
0 r% t6 _5 J9 |$ O6 v
: d8 _& `. m% h) b- u* g然后,选择MyToken选项,如下图:
( c5 m5 X+ g" M& m3 c' ~, c
1 A7 r! A1 j% c% Z然后,在右边更改系数,定制自己的货币。supply: 货币总量,name: 货币名字,symbol:货币符号,decimals:货币单位精确到小数点后几位。
7 S% w/ m1 B$ y# C6 n5 w- \" o5 J7 u' Y3 o) f
下图定制的Shaopingcoin(少平币),总量10000个,货币符号:WL,货币单位精确到小数点后八位。根据自己的喜好,填写即可。 SELECT FEE(选择费用),左右拖动横轴选择支付多少手续费(这里就需要用到前面购买到的以太币了),越靠近右边,费用越高,完成合约的速度越快。例如,我选择了0.016131个以太币,大约需要30秒完成合约。完成后,点击DEPLOY(部署)。
! g* A6 b' d& X5 o% o! `8 R
, M7 c- d: ~; e* A: n5 L点击DEPLOY后,自动转到如下界面,输入密码(即创建账户时设置的 密码),点击SEND TRANSACTION(发送交易)。) S4 Z" T3 v: l9 y4 D

$ z; D: P+ C6 q" e/ e4 p! {然后,会跳转到钱包主界面,你会看到下面红色方框中的信息,大约需要3-4分钟的确认时间,完成12个确认就可以了。7 p& m. {, Y: g" A2 u7 S3 j) d8 R# ?
, g* @9 K9 q2 }0 q+ \" ~
显示新创建的货币。确认完毕,然后再进入CONTRACTS(合约)页面,你将看到刚才创建的货币,例如下图中的ShaopingCoin。  l) S6 {% u$ n. M. `, V

5 E, Q! ~% k4 L+ t8 a; J点击创建的货币,转到以下界面,复制红色方框中的合约地址,下面的步骤中要用到。8 U" L" p6 ~7 q& J4 Q: }
# t9 }. }% m9 R; \, W7 p9 ?& y
再次回到CONTRACTS(合约)页面,点击WATCH TOKEN(查看代币)。9 n- B: Z/ ^9 D

+ _2 u! G3 X" ]/ L" P1 e弹出如下界面,将刚才复制的地址粘贴到红色方框中,会看到货币的名字、符号等信息。点击OK。  Q. H! n+ o  l$ U2 U) g6 x) n. t

* t/ B: U; F% O4 ?完成以后,在合约页面就可以看到新创建的货币了。  m8 Q  {' o8 j, L
) {% ^3 [6 l5 V, d, D
发送新创建的新货币进入SEND(发送)页面,在右上角的红色方框中输入收款者的账户地址。在AMOUT中填写发送的数量,在右边的红色方框中选择要发送的货币。左右拖动横轴选择费用,越靠近右边费用越高,处理速度越快。下图表示向0xba960dbedc4c2e0774729b2def16764592ced454地址发送10个ShaopingCoin,交易费用是0.00253625个以太币。点击SEND(发送)。
" D2 Z. H" V3 y; o! N/ g* ^
% G" Y$ \9 h2 L" \" V跳转到如下确认界面,输入密码(即创建账户时设置的密码)。点击SEND TRANSACTION(发送交易)。) l" Z3 ~7 v# D5 X+ U; y
# _2 W, ~* r% X; _' E8 X
回到WALLETS(钱包)界面,会看到刚刚发出的记录信息。
: S! M5 ?8 V6 `/ k3 ]$ Q) G
- |+ {0 f5 R' \6 x3 A3 k收款者需要将新创建的币的添加到WATCH Token中才可以看到收到的币。收款者进入CONTRACT(合约)页面,点击WATCH TOKEN。发送者将创建的新币的合约地址通过聊天工具发给收款者。
0 a9 ?% S* H% p- j0 |
' R* b# J$ z$ }: K! I5 ~将发送者新创建币的合约地址复制到红色方框中,点击OK。
3 I( A6 h4 U$ C3 c& L. @
4 E) E6 `8 p2 V6 n& Y8 I收款者在WALLETS(钱包)页面将看到收到的币。下图显示收到了10个ShaopingCoin。3 S- A% x; B3 Q$ m3 b
BitMere.com 比特池塘系信息发布平台,比特池塘仅提供信息存储空间服务。
声明:该文观点仅代表作者本人,本文不代表比特池塘立场,且不构成建议,请谨慎对待。
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

成为第一个吐槽的人

忆神姆原们 初中生
  • 粉丝

    0

  • 关注

    0

  • 主题

    16