Hi 游客

更多精彩,请登录!

比特池塘 区块链技术 正文

区块链代币ERC-20源码,如此简单

朱丹铎
116 0 0
什么都不需要准备$ K# Y7 |  q* u- W
*1.  X) R( S! y; @* C- S+ y
启动网页的remix-ide即可
$ z) H5 N, q+ k: fhttps://remix.ethereum.org/#appVersion=0.7.7&optimize=false&version=soljson-v0.5.1+commit.c8a2cb62.js
6 E+ A7 w: ^! c. x5 P. w7 j: w9 m
% d9 n" [6 D& y- @+ V3 gpragma solidity ^0.5.10;
3 H6 _8 M$ k5 }' w$ H; U; I/**
, h% U; R7 s  O) Y, E * @title Token ERC20 implementation
7 j3 ~" @; j7 { * @dev Simplified version - Contract allows only Transfer and Burn Tokens2 ~. I6 }% m  B; |$ V7 ]1 o; n; E
* @dev source: https://www.ethereum.org/token
: b: K5 V, v$ `- J+ V' [8 H6 i */
5 b; k  L- X! O! |/ ccontract TokenERC20 {
0 R! S  ]2 Y" t    // Public variables of the token
  o+ m- e& M$ ]4 y8 }    string public name;
% C) H4 A# T6 ^  k# l. G+ Y9 [    string public symbol;
/ @! h# U4 o% o* O0 V$ A% F! ]    uint8 public decimals = 18;
; t, I% X' h9 M  s9 n, l/ X' z, x    // 18 decimals is the strongly suggested default, avoid changing it0 }! @3 e& P2 `& v$ |
    uint256 public totalSupply;- p4 L* r/ @8 I5 @; Y; K
    // This creates an array with all balances
) u7 u5 t: R& W# l7 f( g    mapping (address => uint256) public balanceOf;
1 u1 G. Z& }9 C' T- d& C5 r    // This generates a public event on the blockchain that will notify clients
& i; b) ~# d  P- |2 L: G    event Transfer(address indexed from, address indexed to, uint256 value);/ b& ~# a3 b6 l& V
    // This notifies clients about the amount burnt. e% H4 g! W5 s. J, s# b3 r; ^/ n
    event Burn(address indexed from, uint256 value);
9 A; L* E# _- V  t3 R# H/ |( x    /**4 y. N# ^3 i( a; I0 w# L
     * Constructor function5 {1 W* v! N; F0 N( J5 k
     *
" w6 {; W( e6 x7 \/ d     * Initializes contract with initial supply tokens to the creator of the contract& ~; _8 }7 r! G  ?; J
     */! F& c  c; z% }6 l
    constructor(uint256 initialSupply, string memory tokenName, string memory tokenSymbol)
) m( m: T' w6 G8 W: Z        public: P% l) o2 k; S: h' {4 g
    {
( }- F; W( e; h' N1 A7 C5 a: r8 k8 ~        totalSupply = initialSupply * 10 ** uint256(decimals);  // Update total supply with the decimal amount$ z) c! q1 W+ C
        balanceOf[msg.sender] = totalSupply;                // Give the creator all initial tokens
2 `7 S# o4 P8 ]% J  t        name = tokenName;                                   // Set the name for display purposes8 [/ X# ?# g4 i5 J6 N
        symbol = tokenSymbol;                               // Set the symbol for display purposes
+ Z  S6 Q% e$ r) o    }
4 P2 _: I6 G9 G  i    /**
1 R' X2 o+ t1 `0 H8 K( |     * Internal transfer, only can be called by this contract
% ]* H  L, r5 v4 v' ]! Q2 _& I     */
! N# f" f$ [) g! k- Z. D  {& s    function _transfer(address _from, address _to, uint _value)
7 ?7 n5 x& y; W        internal
9 \5 {' u5 O" ~    {4 J$ o9 \( A3 L; k% e9 X
        // Prevent transfer to 0x0 address. Use burn() instead
% S& M! o8 g% w4 o        require(_to != address(0x0));
, H# d. W6 ^- t) f; N        // Check if the sender has enough7 v' e+ q. I: N; W1 f6 n
        require(balanceOf[_from] >= _value);) J# U- y, ~4 \) Z# y* d0 _' [
        // Check for overflows  J4 ?  N5 L* h2 j0 j; B
        require(balanceOf[_to] + _value >= balanceOf[_to]);- b7 {4 O1 D3 Z* n* }
        // Save this for an assertion in the future
' c  K2 i) x$ d# x% C$ T4 |        uint previousBalances = balanceOf[_from] + balanceOf[_to];
* s8 Z, n/ O7 j; ~4 B- e5 n        // Subtract from the sender! h; J4 ]/ P" i$ d& R- e
        balanceOf[_from] -= _value;
9 [! K9 e& v& D        // Add the same to the recipient9 Z* t* V9 d: T. ?! B/ v
        balanceOf[_to] += _value;
1 {. z6 j( m( ]6 y        emit Transfer(_from, _to, _value);% u3 B6 M1 j" M  j: ^$ Z' u" s
        // Asserts are used to use static analysis to find bugs in your code. They should never fail+ z" R  t0 B7 z
        assert(balanceOf[_from] + balanceOf[_to] == previousBalances);
2 n' A' }: Y8 C! J7 B  A* p    }4 f; g5 a  R$ ]: ]* h' }
    /**! B$ J' D7 |7 p3 F) {/ R% }0 y0 k( Z
     * Transfer tokens
) ^7 w3 U& O; h: Q2 W$ b. Q, U9 g     *
# }; A0 L2 N7 T     * Send `_value` tokens to `_to` from your account( Y" A% _5 Z: `
     *
& A! W$ I. m: ~     * @param _to The address of the recipient
9 v7 t3 a( i1 K! \* Q) O     * @param _value the amount to send
  \9 \+ p+ x3 J, t1 d5 I$ z& A     */) V3 R  a4 @2 l
    function transfer(address _to, uint256 _value)
0 ~) A. M" M5 U# c; `) }        public
5 V2 f- t9 g7 w- e! J        returns (bool success)
: c& ?/ [  K7 C( X2 I3 O# T6 a9 G$ j    {
5 s; U; [  _* d6 n        _transfer(msg.sender, _to, _value);
; T* d$ l- \% w' j        return true;% |4 }4 U2 W) Y) D
    }" ]5 q/ U4 K+ O- O, m
    /**. `8 N/ U9 Q! M9 O+ q, R2 E
     * Destroy tokens' \9 K- ]+ w$ W% }+ i7 }2 e% i
     *
4 u1 c- U2 D8 r/ W     * Remove `_value` tokens from the system irreversibly
' e+ g( M9 D( p4 O     *
$ P( }) q3 g* q% L: a  L     * @param _value the amount of money to burn% D9 Z3 v$ @8 w9 h8 X% A1 A
     */- ~$ p6 F  H" h
    function burn(uint256 _value)
  E. K5 Q0 }" D  }& e. p# V        public
- ^+ h, z7 \1 C1 j$ R; H, z; ]( h+ }        returns (bool success): n9 H' q5 d0 q% _& w! S2 j
    {2 v9 l! k: h' h* z
        require(balanceOf[msg.sender] >= _value);   // Check if the sender has enough5 [% \4 C6 U# k7 ~
        balanceOf[msg.sender] -= _value;            // Subtract from the sender
# u% G- F9 J* n1 Y8 `2 z        totalSupply -= _value;                      // Updates totalSupply1 e' c8 N+ ^" m7 p: g( |: ^; l
        emit Burn(msg.sender, _value);! H4 G) d$ ^9 l+ i
        return true;9 P2 I, W! q8 n9 l3 {: d
    }
2 s0 \6 K# p+ }. x5 B8 g* z}
; d7 L$ B. _# V部署的话2 I- J2 ]" j5 l- z4 v
; Y& `5 F4 P% b* A- @, m
三个参数,代币总金额,名字,代币符号(随你写了)
( _, [8 b" o! M# {# r0 Z# B- i$ H; S+ l3 P
拷贝合约地址
: @$ }+ e0 P" m5 a: F! c) }5 y( X* I1 @6 p. G8 |# [5 z. s+ k
添加代币,成功后就像我这样!
BitMere.com 比特池塘系信息发布平台,比特池塘仅提供信息存储空间服务。
声明:该文观点仅代表作者本人,本文不代表比特池塘立场,且不构成建议,请谨慎对待。
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

成为第一个吐槽的人

朱丹铎 小学生
  • 粉丝

    0

  • 关注

    0

  • 主题

    1