! Y0 u0 a8 R2 R3 n
另外,你还需要一点以太币,大多数合约只需要价值不要1毛钱的以太币。如果你没有以太币,又不想到国外交易所折腾,可以选择用微信扫描下面的二维码直接在微信中购买:# y# K- z( @% M: S" p8 Y
3 m# u, J( Y6 {0 k, i5 z' A
创建账户并购买到1个以太币以后,钱包界面如下,创建新币合约我们要创建的第一个合约是一个代币合约。3 P5 a( B/ q7 d
以太坊生态系统中的代币可以代表任何可以交易的东西:币(coin)、积分、黄金证券、欠条(IOU)等。 o4 d3 P: J% B& {( x
% |6 ?6 X2 R5 j* A7 a) Q6 x0 S
因为所有的代币都以标准化的方式实现一些基本的特性,这样意味着你自己创建的代币将于以太坊钱包、使用相同标准的任何其它客户端或者合约相兼容。点击红框中的Contract(合约)。
) C1 j% t& m3 v, x+ J3 J
将红框中原有的代码删除,将下面的代码粘贴到里面。
- /*
- This creates a public tradeable fungible token in the Ethereum Blockchain.
- https://github.com/ethereum/wiki/wiki/Standardized_Contract_APIs* Z7 z' W) `' n3 X1 m
- Unmodified this will create a cryptoasset with a fixed market cap: q- n v. ?1 j5 Q7 {7 G! f
- wholly owned by the contract creator. You can create any function8 A1 C* t# p# t" B5 f
- to change this contract, like allowing specific rules for the issuance,
- destruction and freezing of any assets. This contract is intended for) O; I* O% l) n
- educational purposes, you are fully responsible for compliance with
- present or future regulations of finance, communications and the
- universal rights of digital beings.8 V. j: z- [; B9 k u/ H
- Anyone is free to copy, modify, publish, use, compile, sell, or& A0 l' k `( G# v. V
- distribute this software, either in source code form or as a compiled
- binary, for any purpose, commercial or non-commercial, and by any! a3 q, `1 J7 z9 }
- means.3 R" _/ ~/ T% [5 Q
- In jurisdictions that recognize copyright laws, the author or authors9 j8 ~" m( n. \2 G: A" b
- of this software dedicate any and all copyright interest in the
- software to the public domain. We make this dedication for the benefit$ _! a! g0 g% O! Z! s4 F
- of the public at large and to the detriment of our heirs and$ t8 f2 i2 r7 n( s0 d
- successors. We intend this dedication to be an overt act of) t" C- C) Q4 h( X
- relinquishment in perpetuity of all present and future rights to this8 F3 T% d; C; w9 |9 c8 |9 Z. c
- software under copyright law.
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,- ]% ]1 i. e& ^: ^
- EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF7 S3 a) i6 |0 Q
- MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
- IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR V9 d; D5 H1 k
- OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,* @5 I: M4 T( M
- ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR, M% |1 k: A R- b9 G$ Y
- OTHER DEALINGS IN THE SOFTWARE.
- For more information, please refer to $ O/ g* @0 t. J' |
- */
- contract MyToken {$ g$ L# _2 a. f1 o1 i& w7 V+ g
- /* Public variables of the token */2 o; s. V" i- y. D! v, k( b2 S
- string public name;& t) k- O$ S! D; ^% p. M4 G
- string public symbol;3 U' j! ]" z$ L" v; L
- uint8 public decimals;
- /* This creates an array with all balances */( h! B# j9 A- f c5 V* w8 J1 a+ w
- mapping (address => uint256) public balanceOf;
- /* This generates a public event on the blockchain that will notify clients */: B- C: Z6 i, T; k! R# `
- event Transfer(address indexed from, address indexed to, uint256 value);
- /* Initializes contract with initial supply tokens to the creator of the contract */; O4 d8 u7 m& s. v4 j/ J$ B! |1 A
- function MyToken(uint256 _supply, string _name, string _symbol, uint8 _decimals) {2 j- M: S7 a6 F5 c
- /* if supply not given then generate 1 million of the smallest unit of the token */
- if (_supply == 0) _supply = 1000000;7 B3 D7 B7 U4 O: ^9 F
- /* Unless you add other functions these variables will never change */
- balanceOf[msg.sender] = _supply;1 I/ o6 n1 ^0 R. X; F+ r2 x
- name = _name;" y0 ]% e- _1 O- ^& z
- symbol = _symbol;
- /* If you want a divisible token then add the amount of decimals the base unit has */, p$ z2 _/ p' g9 [( ?! S
- decimals = _decimals;& [3 T) X, [# U5 N: @/ ^
- }
- /* Send coins */5 ]1 i: g/ G. Z- |( [) Y
- function transfer(address _to, uint256 _value) {# I' O w3 W! i! z0 i0 y
- /* if the sender doenst have enough balance then stop */' G, x) s4 H3 _
- if (balanceOf[msg.sender]
- if (balanceOf[_to] + _value # y, s* v/ x) a8 ~ n$ o
- /* Add and subtract new balances */" I" n7 B9 ?' Z; Q- d5 v
- balanceOf[msg.sender] -= _value;5 m' @$ c: S5 b! g
- balanceOf[_to] += _value;
- /* Notifiy anyone listening that this transfer took place */& @0 } \/ {) h8 i, Q
- Transfer(msg.sender, _to, _value);+ _6 x, h9 H8 E3 e
- }( W; {8 A! |0 ` I# f# ], P' U! S
- }
如果代码编译成功,在左边将看到Pick contract,如下图:
2 N! N- ?" Y. N& b: s5 k
然后,选择MyToken选项,如下图:( j1 Q% `5 Z+ b3 D8 \& b+ @* y
# z( O% K; H: V5 t: v
然后,在右边更改系数,定制自己的货币。supply: 货币总量,name: 货币名字,symbol:货币符号,decimals:货币单位精确到小数点后几位。/ I5 u G! _4 P! A
2 r# x8 D0 _) z0 I4 V
下图定制的Shaopingcoin(少平币),总量10000个,货币符号:WL,货币单位精确到小数点后八位。根据自己的喜好,填写即可。 SELECT FEE(选择费用),左右拖动横轴选择支付多少手续费(这里就需要用到前面购买到的以太币了),越靠近右边,费用越高,完成合约的速度越快。例如,我选择了0.016131个以太币,大约需要30秒完成合约。完成后,点击DEPLOY(部署)。2 f p4 Q/ x- S+ g( i5 k6 K- t- O( y
' e# L/ W4 H6 c; V- r0 L
点击DEPLOY后,自动转到如下界面,输入密码(即创建账户时设置的 密码),点击SEND TRANSACTION(发送交易)。
/ M& h; @9 \; @, p; {% U
然后,会跳转到钱包主界面,你会看到下面红色方框中的信息,大约需要3-4分钟的确认时间,完成12个确认就可以了。! ~- `) ?: u0 n+ q, N5 J
显示新创建的货币。确认完毕,然后再进入CONTRACTS(合约)页面,你将看到刚才创建的货币,例如下图中的ShaopingCoin。
点击创建的货币,转到以下界面,复制红色方框中的合约地址,下面的步骤中要用到。8 B+ q7 M: d$ c6 l4 i
再次回到CONTRACTS(合约)页面,点击WATCH TOKEN(查看代币)。
2 ?: r: d5 P, u# X K! Q' ^
弹出如下界面,将刚才复制的地址粘贴到红色方框中,会看到货币的名字、符号等信息。点击OK。
7 Q* Y$ G4 ^1 p, |4 R+ d6 R
完成以后,在合约页面就可以看到新创建的货币了。
% x# W6 N5 o t: q R# Q( }( T
发送新创建的新货币进入SEND(发送)页面,在右上角的红色方框中输入收款者的账户地址。在AMOUT中填写发送的数量,在右边的红色方框中选择要发送的货币。左右拖动横轴选择费用,越靠近右边费用越高,处理速度越快。下图表示向0xba960dbedc4c2e0774729b2def16764592ced454地址发送10个ShaopingCoin,交易费用是0.00253625个以太币。点击SEND(发送)。, V* u$ U+ ^1 i- G
' q! f! I2 ~0 c' S: |( n
跳转到如下确认界面,输入密码(即创建账户时设置的密码)。点击SEND TRANSACTION(发送交易)。! _: J% G; o3 Q) t3 c) A
回到WALLETS(钱包)界面,会看到刚刚发出的记录信息。, x. J, h3 U8 b3 W* E) N
2 c+ l; ^, V% a# \( e" w/ Y
收款者需要将新创建的币的添加到WATCH Token中才可以看到收到的币。收款者进入CONTRACT(合约)页面,点击WATCH TOKEN。发送者将创建的新币的合约地址通过聊天工具发给收款者。+ K4 b* M6 F% ?. H, n$ t; D Z
. H7 L* g! f! t, T
将发送者新创建币的合约地址复制到红色方框中,点击OK。" D; [: `. U8 d+ W
收款者在WALLETS(钱包)页面将看到收到的币。下图显示收到了10个ShaopingCoin。! [/ | ~# X* P! s& \: D, y