Hi 游客

更多精彩,请登录!

比特池塘 区块链技术 正文

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

忆神姆原们
209 0 0
本教程主要参考以太坊官方博客,外加自己的实践。创建代币不需要自己写代码,只要会复制粘贴就可以搞定,这也是以太坊强大之处。下载钱包首先到这里(https://github.com/ethereum/mist/releases)根据自己的操作系统下载相应的钱包。然后,创建一个以太坊账户。
: j, Y# ^" V! {
. {0 V7 X9 o' i, W: C另外,你还需要一点以太币,大多数合约只需要价值不要1毛钱的以太币。如果你没有以太币,又不想到国外交易所折腾,可以选择用微信扫描下面的二维码直接在微信中购买:
3 D! o, [. h8 ?; w% g) N: F' e  J  G6 {2 s% ~6 I! T
创建账户并购买到1个以太币以后,钱包界面如下,创建新币合约我们要创建的第一个合约是一个代币合约。$ x0 B" n2 w1 W

1 e& l3 y0 c1 ~: G以太坊生态系统中的代币可以代表任何可以交易的东西:币(coin)、积分、黄金证券、欠条(IOU)等。# ?2 \% G5 d- U; q( `- W% h

* J0 ?2 T: p' Q" b4 F$ w因为所有的代币都以标准化的方式实现一些基本的特性,这样意味着你自己创建的代币将于以太坊钱包、使用相同标准的任何其它客户端或者合约相兼容。点击红框中的Contract(合约)。* n1 Z0 {$ z; d4 A: T, Z6 |& s
$ M6 h' }2 G  K" }6 y
将红框中原有的代码删除,将下面的代码粘贴到里面。
( i0 F8 G# F8 s
  1. /*- Q+ V- L- S  K2 {. p% A
  2. This creates a public tradeable fungible token in the Ethereum Blockchain." T0 t9 Z( U* C" }4 |" s0 v# \
  3. https://github.com/ethereum/wiki/wiki/Standardized_Contract_APIs- O7 f% P9 ]( Y$ t6 F
  4. Unmodified this will create a cryptoasset with a fixed market cap
      W6 |) o' i6 Z6 n2 X, I5 a' W
  5. wholly owned by the contract creator. You can create any function% X# F0 h; R& g8 m+ Y- f
  6. to change this contract, like allowing specific rules for the issuance,
    ' ]! e& s2 s; |6 F7 z, q+ C
  7. destruction and freezing of any assets. This contract is intended for
    0 K9 U( J; v0 v8 @+ v7 L
  8. educational purposes, you are fully responsible for compliance with
    * M5 Z" J4 g4 X0 q" B, P- F
  9. present or future regulations of finance, communications and the
    . n/ B( K- f' E/ I- y9 Q3 Y
  10. universal rights of digital beings.9 H+ B1 S* i- X& x1 P
  11. Anyone is free to copy, modify, publish, use, compile, sell, or  g+ C- B; B3 `) \
  12. distribute this software, either in source code form or as a compiled5 }- L, U% k; k/ Y' _% b% j
  13. binary, for any purpose, commercial or non-commercial, and by any
    ( l' v& v! f4 G( L5 C
  14. means.1 Z# C0 M* a: p2 m
  15. In jurisdictions that recognize copyright laws, the author or authors. t/ F: b( r5 D7 F7 f% q
  16. of this software dedicate any and all copyright interest in the( j% }& z& V: {6 F
  17. software to the public domain. We make this dedication for the benefit% j5 n* C" D) Q4 O& F
  18. of the public at large and to the detriment of our heirs and1 e/ J, i4 \8 R. k* R
  19. successors. We intend this dedication to be an overt act of! l( `+ U1 h6 T2 W% P- u) j9 ?
  20. relinquishment in perpetuity of all present and future rights to this# a) h6 X5 M% i5 ]
  21. software under copyright law.0 [1 E8 B* ~2 w" K( L0 r7 S
  22. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
    8 y  i" w) t+ V; Z% D
  23. EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF( m/ s( k* Y9 v
  24. MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.% ~5 f) S; A7 c- S
  25. IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR6 y: D6 G) z& ~; n  |
  26. OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
    % q8 n4 ?! m% a5 x
  27. ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR& V8 p& n' D" _' G& a$ e- E
  28. OTHER DEALINGS IN THE SOFTWARE.- r8 w, g; {! D1 E8 c/ l# y! l, u
  29. For more information, please refer to
    ( n: x. u- U. q2 b
  30. */
    9 k/ s" M- N2 O8 U1 g. M% D
  31. contract MyToken {
    ( @0 O8 _5 t% [9 r) ^+ `" l
  32.     /* Public variables of the token */( s, L8 P5 `$ L. M# U* \
  33.     string public name;% ]( k  A! v1 I! Y5 F( C" V
  34.     string public symbol;. w5 `! \: d, @; n2 B/ h4 K& ?
  35.     uint8 public decimals;4 D# Q; U3 z  T1 d+ @
  36.     /* This creates an array with all balances */
    - |" c: u2 [; m9 i8 P
  37.     mapping (address => uint256) public balanceOf;
    4 n; ~5 ]/ T- C9 F
  38.     /* This generates a public event on the blockchain that will notify clients */
    " q( N8 L) P7 K* V  \. K+ m
  39.     event Transfer(address indexed from, address indexed to, uint256 value);
    " |# K" ]' E: J8 I3 D
  40.     /* Initializes contract with initial supply tokens to the creator of the contract */
    ) t- x3 t4 [2 g. `
  41.     function MyToken(uint256 _supply, string _name, string _symbol, uint8 _decimals) {* @9 i0 n, T# Z: K
  42.         /* if supply not given then generate 1 million of the smallest unit of the token */# }. T# w' E  k% B5 v8 J5 @
  43.         if (_supply == 0) _supply = 1000000;
    3 K* p. |: ~* p& r2 K* P
  44.         /* Unless you add other functions these variables will never change */
    " S5 q% S  l; S$ G$ A% d. W
  45.         balanceOf[msg.sender] = _supply;
    # l1 V: u* X1 Z2 b& s) c
  46.         name = _name;7 I: D1 a, S5 T# E( E
  47.         symbol = _symbol;7 |) L* K, F. v: n
  48.         /* If you want a divisible token then add the amount of decimals the base unit has  */
    1 |( }$ n) e- a6 b, o
  49.         decimals = _decimals;/ l: E' v& M' d2 n7 Y$ S( x
  50.     }8 v, [$ ^' I7 C1 }; x7 M1 A
  51.     /* Send coins */
    7 @* T" n) [. A6 u+ N
  52.     function transfer(address _to, uint256 _value) {' E/ O* a3 h+ Z8 ^. P
  53.         /* if the sender doenst have enough balance then stop */9 H. E7 T% n" L: a( D3 v
  54.         if (balanceOf[msg.sender]
    3 L9 Q+ ?5 d5 k* ^3 y% _
  55.         if (balanceOf[_to] + _value
    - s. D  G% h! l# V# D3 S
  56.         /* Add and subtract new balances */& o; M# O* D" o) z6 w  A
  57.         balanceOf[msg.sender] -= _value;% v3 X. @/ y6 G  ]
  58.         balanceOf[_to] += _value;; O+ h5 x2 z* w& K7 ?2 m
  59.         /* Notifiy anyone listening that this transfer took place */
    : y; r% [1 G" Q, v' d; s3 y
  60.         Transfer(msg.sender, _to, _value);
    - l7 X+ l0 C0 n
  61.     }
    ' u' k5 o( _  J8 k" {  R4 U
  62. }
复制代码

- `. J+ p4 P1 _, `' w如果代码编译成功,在左边将看到Pick contract,如下图:
$ P! P5 c0 _' C4 H, i: G2 y! g$ h  X+ l. ?; S3 H
然后,选择MyToken选项,如下图:
  A2 f& C/ {  g" \
# ^: c0 ~; q7 I6 S" j& X. M5 |然后,在右边更改系数,定制自己的货币。supply: 货币总量,name: 货币名字,symbol:货币符号,decimals:货币单位精确到小数点后几位。0 a. W: Q# @+ G, c8 s% ?4 T

  v" T! `0 [* r下图定制的Shaopingcoin(少平币),总量10000个,货币符号:WL,货币单位精确到小数点后八位。根据自己的喜好,填写即可。 SELECT FEE(选择费用),左右拖动横轴选择支付多少手续费(这里就需要用到前面购买到的以太币了),越靠近右边,费用越高,完成合约的速度越快。例如,我选择了0.016131个以太币,大约需要30秒完成合约。完成后,点击DEPLOY(部署)。4 n6 A4 P3 @! f1 n% X
: S# C; a- a6 p2 Z  A9 y. w, w
点击DEPLOY后,自动转到如下界面,输入密码(即创建账户时设置的 密码),点击SEND TRANSACTION(发送交易)。0 Z0 d- [' J, ?2 K+ h; m3 K7 C
5 g+ `' e" |3 a2 M5 ~7 q# u1 g  m# R
然后,会跳转到钱包主界面,你会看到下面红色方框中的信息,大约需要3-4分钟的确认时间,完成12个确认就可以了。4 W2 T- u" q% H$ V% q

+ i9 l: J/ C+ ?4 q5 w7 R& g% k, i# e显示新创建的货币。确认完毕,然后再进入CONTRACTS(合约)页面,你将看到刚才创建的货币,例如下图中的ShaopingCoin。2 J; C8 A1 y2 }9 @5 Q' ?: G9 z

$ s- k" e8 W4 {3 L点击创建的货币,转到以下界面,复制红色方框中的合约地址,下面的步骤中要用到。
  S% J4 U$ X  U+ v3 v6 A. w% L' g- T
* [, g0 f' C/ {- ^- Z4 Z2 {再次回到CONTRACTS(合约)页面,点击WATCH TOKEN(查看代币)。
5 u; r& _% ?3 [# P' B- c' v% l- p1 C; B7 P; F4 H- _/ x* X
弹出如下界面,将刚才复制的地址粘贴到红色方框中,会看到货币的名字、符号等信息。点击OK。
% J/ G* [2 E/ W, z7 ^, D+ I9 H) j2 u' l$ a- C) T4 j
完成以后,在合约页面就可以看到新创建的货币了。* C5 T# j1 z; z5 @5 b; J

* ~/ S7 q/ l, `: c0 p# \+ E发送新创建的新货币进入SEND(发送)页面,在右上角的红色方框中输入收款者的账户地址。在AMOUT中填写发送的数量,在右边的红色方框中选择要发送的货币。左右拖动横轴选择费用,越靠近右边费用越高,处理速度越快。下图表示向0xba960dbedc4c2e0774729b2def16764592ced454地址发送10个ShaopingCoin,交易费用是0.00253625个以太币。点击SEND(发送)。
0 \$ g5 o/ ?% n. d; B5 |: Y# q5 ^, D, Q1 ^2 q8 s! q6 P
跳转到如下确认界面,输入密码(即创建账户时设置的密码)。点击SEND TRANSACTION(发送交易)。
; b5 i8 c3 K- r* t4 H" q
/ c" M% f. l. Z% K回到WALLETS(钱包)界面,会看到刚刚发出的记录信息。
  m1 B- {; F* c" M6 f' l: Y6 l/ y- i
! X: {, o* [( \8 s4 c% I收款者需要将新创建的币的添加到WATCH Token中才可以看到收到的币。收款者进入CONTRACT(合约)页面,点击WATCH TOKEN。发送者将创建的新币的合约地址通过聊天工具发给收款者。: Y& z# p3 ~8 i% _9 v

) R2 b- y. D9 X将发送者新创建币的合约地址复制到红色方框中,点击OK。5 X' ^! ~: o  S

7 f  z. N6 R8 ]2 V2 ~* c5 Q收款者在WALLETS(钱包)页面将看到收到的币。下图显示收到了10个ShaopingCoin。* a  Z. [5 M5 K- q0 _, W
BitMere.com 比特池塘系信息发布平台,比特池塘仅提供信息存储空间服务。
声明:该文观点仅代表作者本人,本文不代表比特池塘立场,且不构成建议,请谨慎对待。
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

成为第一个吐槽的人

忆神姆原们 初中生
  • 粉丝

    0

  • 关注

    0

  • 主题

    16