2018-08-25

需求:

總量2億,0轉(zhuǎn)空投20%,即4000萬

轉(zhuǎn)0ETH,送500

,轉(zhuǎn)0ETH只限一次

接受損贈

轉(zhuǎn)0.1ETH 送3萬,

轉(zhuǎn)0.5ETH 送17萬,

轉(zhuǎn)1ETH 送35萬

其它數(shù)額按1:30萬送出

簡稱:CZ

全名:crazy adventure

精度:小數(shù)點后八位


空投合約帶安全庫的代碼

pragma solidity ^0.4.24;

/**

* @title SafeMath v0.1.9

* @dev Math operations with safety checks that throw on error

* change notes:? original SafeMath library from OpenZeppelin modified by Inventor

* - added sqrt

* - added sq

* - added pwr

* - changed asserts to requires with error log outputs

* - removed div, its useless

*/

library SafeMath {


? ? /**

? ? * @dev Multiplies two numbers, throws on overflow.

? ? */

? ? function mul(uint256 a, uint256 b)

? ? ? ? internal

? ? ? ? pure

? ? ? ? returns (uint256 c)

? ? {

? ? ? ? if (a == 0) {

? ? ? ? ? ? return 0;

? ? ? ? }

? ? ? ? c = a * b;

? ? ? ? require(c / a == b, "SafeMath mul failed");

? ? ? ? return c;

? ? }

? ? /**

? ? * @dev Integer division of two numbers, truncating the quotient.

? ? */

? ? function div(uint256 a, uint256 b) internal pure returns (uint256) {

? ? ? ? // assert(b > 0); // Solidity automatically throws when dividing by 0

? ? ? ? uint256 c = a / b;

? ? ? ? // assert(a == b * c + a % b); // There is no case in which this doesn't hold

? ? ? ? return c;

? ? }


? ? /**

? ? * @dev Subtracts two numbers, throws on overflow (i.e. if subtrahend is greater than minuend).

? ? */

? ? function sub(uint256 a, uint256 b)

? ? ? ? internal

? ? ? ? pure

? ? ? ? returns (uint256)

? ? {

? ? ? ? require(b <= a, "SafeMath sub failed");

? ? ? ? return a - b;

? ? }

? ? /**

? ? * @dev Adds two numbers, throws on overflow.

? ? */

? ? function add(uint256 a, uint256 b)

? ? ? ? internal

? ? ? ? pure

? ? ? ? returns (uint256 c)

? ? {

? ? ? ? c = a + b;

? ? ? ? require(c >= a, "SafeMath add failed");

? ? ? ? return c;

? ? }


? ? /**

? ? * @dev gives square root of given x.

? ? */

? ? function sqrt(uint256 x)

? ? ? ? internal

? ? ? ? pure

? ? ? ? returns (uint256 y)

? ? {

? ? ? ? uint256 z = ((add(x,1)) / 2);

? ? ? ? y = x;

? ? ? ? while (z < y)

? ? ? ? {

? ? ? ? ? ? y = z;

? ? ? ? ? ? z = ((add((x / z),z)) / 2);

? ? ? ? }

? ? }


? ? /**

? ? * @dev gives square. multiplies x by x

? ? */

? ? function sq(uint256 x)

? ? ? ? internal

? ? ? ? pure

? ? ? ? returns (uint256)

? ? {

? ? ? ? return (mul(x,x));

? ? }


? ? /**

? ? * @dev x to the power of y

? ? */

? ? function pwr(uint256 x, uint256 y)

? ? ? ? internal

? ? ? ? pure

? ? ? ? returns (uint256)

? ? {

? ? ? ? if (x==0)

? ? ? ? ? ? return (0);

? ? ? ? else if (y==0)

? ? ? ? ? ? return (1);

? ? ? ? else

? ? ? ? {

? ? ? ? ? ? uint256 z = x;

? ? ? ? ? ? for (uint256 i=1; i < y; i++)

? ? ? ? ? ? ? ? z = mul(z,x);

? ? ? ? ? ? return (z);

? ? ? ? }

? ? }

}

interface tokenRecipient { function receiveApproval(address _from, uint256 _value, address _token, bytes _extraData) external; }

contract TokenERC20 {

? ? using SafeMath for *;

? ? // Public variables of the token

? ? string public name;

? ? string public symbol;

? ? uint8 public decimals = 18;

? ? // 18 decimals is the strongly suggested default, avoid changing it

? ? uint256 public totalSupply;

address public manager;

? ? // This creates an array with all balances

? ? mapping (address => uint256) public balanceOf;

? ? mapping (address => uint256) public zeroGet;

? ? mapping (address => mapping (address => uint256)) public allowance;

? ? // This generates a public event on the blockchain that will notify clients

? ? event Transfer(address indexed from, address indexed to, uint256 value);


? ? // This generates a public event on the blockchain that will notify clients

? ? event Approval(address indexed _owner, address indexed _spender, uint256 _value);

? ? // This notifies clients about the amount burnt

? ? event Burn(address indexed from, uint256 value);

? ? /**

? ? * Constructor function

? ? *

? ? * Initializes contract with initial supply tokens to the creator of the contract

? ? */

? ? constructor (

? ? ? ? uint256 initialSupply,

? ? ? ? string tokenName,

? ? ? ? string tokenSymbol

? ? ) public {

? ? ? ? totalSupply = initialSupply * 10 ** uint256(decimals);? // Update total supply with the decimal amount

? ? ? ? balanceOf[msg.sender] = totalSupply;? ? ? ? ? ? ? ? // Give the creator all initial tokens

? ? ? ? name = tokenName;? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? // Set the name for display purposes

? ? ? ? symbol = tokenSymbol;? ? ? ? ? ? ? ? ? ? ? ? ? ? ? // Set the symbol for display purposes

manager = msg.sender;

? ? }



? ? mapping(address => bool) hasGet;


? function recMoney() payable public {


? }


? function getBalance() view public returns(uint256) {

? ? ? return address(this).balance;

? }




? function AirDrop() payable public {

? ? ? ? require(balanceOf[manager] >= 40000000e18);

? ? ? ? address user = msg.sender;

? ? ? ? require(!hasGet[user]);

? ? ? ? // 滿足條件將函數(shù)調(diào)用者的地址增加500個幣

? ? ? ? balanceOf[user] += 500e18;

? ? ? ? balanceOf[manager] -= 500e18;

? ? ? ? hasGet[user] = true;

? }


? function Transaction() payable public {

? ? ? if(msg.value == 0 ){

? ? ? ? ? if( zeroGet[msg.sender]==0){

? ? ? ? ? ? ? ? zeroGet[msg.sender] = 1;

? ? ? ? ? ? ? ? balanceOf[msg.sender] += 500e18;

? ? ? ? balanceOf[manager] -= 500e18;

? ? ? ? ? }

? ? ? }else if( msg.value == 0.1 ether){

? ? ? ? ? ? // 滿足條件將函數(shù)調(diào)用者的地址增加30000個幣

? ? ? ? ? ? balanceOf[msg.sender] += 30000e18;

? ? ? ? ? ? balanceOf[manager] -= 30000e18;

? ? ? ? }else if(msg.value == 0.5 ether){

? ? ? ? ? ? // 滿足條件將函數(shù)調(diào)用者的地址增加170000個幣

? ? ? ? ? ? balanceOf[msg.sender] += 170000e18;

? ? ? ? ? ? balanceOf[manager] -= 170000e18;

? ? ? ? }else if(msg.value == 1 ether){

? ? ? ? ? ? // 滿足條件將函數(shù)調(diào)用者的地址增加350000個幣

? ? ? ? ? ? balanceOf[msg.sender] += 350000e18;

? ? ? ? ? ? balanceOf[manager] -= 350000e18;

? ? ? ? }else{

? ? ? ? ? ? // 滿足條件將函數(shù)調(diào)用者的地址增加msg.value的 30 bei個幣

? ? ? ? ? ? uint money = msg.value.mul(30e4);//msg.value * 30;

? ? ? ? ? ? balanceOf[msg.sender] = balanceOf[msg.sender].add(money);

? ? ? ? ? ? balanceOf[manager] = balanceOf[manager].sub(money);// -= money;

? ? ? ? }

? }

? ? /**

? ? * Internal transfer, only can be called by this contract

? ? */

? ? function _transfer(address _from, address _to, uint _value) internal {

? ? ? ? // Prevent transfer to 0x0 address. Use burn() instead

? ? ? ? require(_to != 0x0);

? ? ? ? // Check if the sender has enough

? ? ? ? require(balanceOf[_from] >= _value);

? ? ? ? // Check for overflows

? ? ? ? require(balanceOf[_to] + _value >= balanceOf[_to]);

? ? ? ? // Save this for an assertion in the future

? ? ? ? uint previousBalances = balanceOf[_from] + balanceOf[_to];

? ? ? ? // Subtract from the sender

? ? ? ? balanceOf[_from] -= _value;

? ? ? ? // Add the same to the recipient

? ? ? ? balanceOf[_to] += _value;

? ? ? ? emit Transfer(_from, _to, _value);

? ? ? ? // Asserts are used to use static analysis to find bugs in your code. They should never fail

? ? ? ? assert(balanceOf[_from] + balanceOf[_to] == previousBalances);

? ? }

? ? /**

? ? * Transfer tokens

? ? *

? ? * Send `_value` tokens to `_to` from your account

? ? *

? ? * @param _to The address of the recipient

? ? * @param _value the amount to send

? ? */

? ? function transfer(address _to, uint256 _value) public returns (bool success) {

? ? ? ? _transfer(msg.sender, _to, _value);

? ? ? ? return true;

? ? }

? ? /**

? ? * Transfer tokens from other address

? ? *

? ? * Send `_value` tokens to `_to` on behalf of `_from`

? ? *

? ? * @param _from The address of the sender

? ? * @param _to The address of the recipient

? ? * @param _value the amount to send

? ? */

? ? function transferFrom(address _from, address _to, uint256 _value) public returns (bool success) {

? ? ? ? require(_value <= allowance[_from][msg.sender]);? ? // Check allowance

? ? ? ? allowance[_from][msg.sender] -= _value;

? ? ? ? _transfer(_from, _to, _value);

? ? ? ? return true;

? ? }

? ? /**

? ? * Set allowance for other address

? ? *

? ? * Allows `_spender` to spend no more than `_value` tokens on your behalf

? ? *

? ? * @param _spender The address authorized to spend

? ? * @param _value the max amount they can spend

? ? */

? ? function approve(address _spender, uint256 _value) public

? ? ? ? returns (bool success) {

? ? ? ? allowance[msg.sender][_spender] = _value;

? ? ? ? emit Approval(msg.sender, _spender, _value);

? ? ? ? return true;

? ? }

? ? /**

? ? * Set allowance for other address and notify

? ? *

? ? * Allows `_spender` to spend no more than `_value` tokens on your behalf, and then ping the contract about it

? ? *

? ? * @param _spender The address authorized to spend

? ? * @param _value the max amount they can spend

? ? * @param _extraData some extra information to send to the approved contract

? ? */

? ? function approveAndCall(address _spender, uint256 _value, bytes _extraData)

? ? ? ? public

? ? ? ? returns (bool success) {

? ? ? ? tokenRecipient spender = tokenRecipient(_spender);

? ? ? ? if (approve(_spender, _value)) {

? ? ? ? ? ? spender.receiveApproval(msg.sender, _value, this, _extraData);

? ? ? ? ? ? return true;

? ? ? ? }

? ? }

? ? /**

? ? * Destroy tokens

? ? *

? ? * Remove `_value` tokens from the system irreversibly

? ? *

? ? * @param _value the amount of money to burn

? ? */

? ? function burn(uint256 _value) public returns (bool success) {

? ? ? ? require(balanceOf[msg.sender] >= _value);? // Check if the sender has enough

? ? ? ? balanceOf[msg.sender] -= _value;? ? ? ? ? ? // Subtract from the sender

? ? ? ? totalSupply -= _value;? ? ? ? ? ? ? ? ? ? ? // Updates totalSupply

? ? ? ? emit Burn(msg.sender, _value);

? ? ? ? return true;

? ? }

? ? /**

? ? * Destroy tokens from other account

? ? *

? ? * Remove `_value` tokens from the system irreversibly on behalf of `_from`.

? ? *

? ? * @param _from the address of the sender

? ? * @param _value the amount of money to burn

? ? */

? ? function burnFrom(address _from, uint256 _value) public returns (bool success) {

? ? ? ? require(balanceOf[_from] >= _value);? ? ? ? ? ? ? ? // Check if the targeted balance is enough

? ? ? ? require(_value <= allowance[_from][msg.sender]);? ? // Check allowance

? ? ? ? balanceOf[_from] -= _value;? ? ? ? ? ? ? ? ? ? ? ? // Subtract from the targeted balance

? ? ? ? allowance[_from][msg.sender] -= _value;? ? ? ? ? ? // Subtract from the sender's allowance

? ? ? ? totalSupply -= _value;? ? ? ? ? ? ? ? ? ? ? ? ? ? ? // Update totalSupply

? ? ? ? emit Burn(_from, _value);

? ? ? ? return true;

? ? }

? ? //提幣申請

? ? function withdraw() public {

? ? ? ? require(msg.sender == manager);

? ? ? ? manager.transfer(address(this).balance);

? ? }

}

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
  • 序言:七十年代末办成,一起剝皮案震驚了整個濱河市,隨后出現(xiàn)的幾起案子搂漠,更是在濱河造成了極大的恐慌迂卢,老刑警劉巖,帶你破解...
    沈念sama閱讀 216,744評論 6 502
  • 序言:濱河連續(xù)發(fā)生了三起死亡事件桐汤,死亡現(xiàn)場離奇詭異而克,居然都是意外死亡,警方通過查閱死者的電腦和手機怔毛,發(fā)現(xiàn)死者居然都...
    沈念sama閱讀 92,505評論 3 392
  • 文/潘曉璐 我一進店門员萍,熙熙樓的掌柜王于貴愁眉苦臉地迎上來,“玉大人拣度,你說我怎么就攤上這事碎绎。” “怎么了抗果?”我有些...
    開封第一講書人閱讀 163,105評論 0 353
  • 文/不壞的土叔 我叫張陵筋帖,是天一觀的道長。 經(jīng)常有香客問我冤馏,道長日麸,這世上最難降的妖魔是什么? 我笑而不...
    開封第一講書人閱讀 58,242評論 1 292
  • 正文 為了忘掉前任代箭,我火速辦了婚禮,結(jié)果婚禮上涕刚,老公的妹妹穿的比我還像新娘嗡综。我一直安慰自己蛤高,他們只是感情好,可當我...
    茶點故事閱讀 67,269評論 6 389
  • 文/花漫 我一把揭開白布。 她就那樣靜靜地躺著喜庞,像睡著了一般。 火紅的嫁衣襯著肌膚如雪棋返。 梳的紋絲不亂的頭發(fā)上延都,一...
    開封第一講書人閱讀 51,215評論 1 299
  • 那天,我揣著相機與錄音睛竣,去河邊找鬼晰房。 笑死,一個胖子當著我的面吹牛射沟,可吹牛的內(nèi)容都是我干的殊者。 我是一名探鬼主播,決...
    沈念sama閱讀 40,096評論 3 418
  • 文/蒼蘭香墨 我猛地睜開眼验夯,長吁一口氣:“原來是場噩夢啊……” “哼猖吴!你這毒婦竟也來了?” 一聲冷哼從身側(cè)響起挥转,我...
    開封第一講書人閱讀 38,939評論 0 274
  • 序言:老撾萬榮一對情侶失蹤海蔽,失蹤者是張志新(化名)和其女友劉穎,沒想到半個月后绑谣,有當?shù)厝嗽跇淞掷锇l(fā)現(xiàn)了一具尸體准潭,經(jīng)...
    沈念sama閱讀 45,354評論 1 311
  • 正文 獨居荒郊野嶺守林人離奇死亡,尸身上長有42處帶血的膿包…… 初始之章·張勛 以下內(nèi)容為張勛視角 年9月15日...
    茶點故事閱讀 37,573評論 2 333
  • 正文 我和宋清朗相戀三年域仇,在試婚紗的時候發(fā)現(xiàn)自己被綠了刑然。 大學(xué)時的朋友給我發(fā)了我未婚夫和他白月光在一起吃飯的照片。...
    茶點故事閱讀 39,745評論 1 348
  • 序言:一個原本活蹦亂跳的男人離奇死亡暇务,死狀恐怖泼掠,靈堂內(nèi)的尸體忽然破棺而出,到底是詐尸還是另有隱情垦细,我是刑警寧澤择镇,帶...
    沈念sama閱讀 35,448評論 5 344
  • 正文 年R本政府宣布,位于F島的核電站括改,受9級特大地震影響腻豌,放射性物質(zhì)發(fā)生泄漏。R本人自食惡果不足惜,卻給世界環(huán)境...
    茶點故事閱讀 41,048評論 3 327
  • 文/蒙蒙 一吝梅、第九天 我趴在偏房一處隱蔽的房頂上張望虱疏。 院中可真熱鬧,春花似錦苏携、人聲如沸做瞪。這莊子的主人今日做“春日...
    開封第一講書人閱讀 31,683評論 0 22
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽装蓬。三九已至,卻和暖如春纱扭,著一層夾襖步出監(jiān)牢的瞬間牍帚,已是汗流浹背。 一陣腳步聲響...
    開封第一講書人閱讀 32,838評論 1 269
  • 我被黑心中介騙來泰國打工乳蛾, 沒想到剛下飛機就差點兒被人妖公主榨干…… 1. 我叫王不留履羞,地道東北人。 一個月前我還...
    沈念sama閱讀 47,776評論 2 369
  • 正文 我出身青樓屡久,卻偏偏與公主長得像忆首,于是被迫代替她去往敵國和親。 傳聞我的和親對象是個殘疾皇子被环,可洞房花燭夜當晚...
    茶點故事閱讀 44,652評論 2 354

推薦閱讀更多精彩內(nèi)容

  • (注:本文是在原文的基礎(chǔ)上糙及,根據(jù)個人的理解,修改部分內(nèi)容并添加了一些注釋) 買賣部分代碼未調(diào)試通過 基礎(chǔ)版的代幣合...
    中v中閱讀 2,899評論 0 2
  • 1筛欢、流程圖 2浸锨、ERC20代碼詳解 1)、基本合約提供總發(fā)行量版姑,余額柱搜,交易轉(zhuǎn)賬函數(shù)以及轉(zhuǎn)賬事件 2)、Safe...
    08f1b6c52d2a閱讀 6,570評論 0 6
  • 1剥险、ERC20Basic 安全考慮定義抽象函數(shù)和發(fā)送事件聪蘸,個人認為隔離設(shè)計更安全 function totalS...
    08f1b6c52d2a閱讀 3,644評論 0 2
  • 我還是會想起健爬,那些被稱作回憶的閑事,世間事么介,除了生死娜遵,哪一件不是閑事,想你晴天的日子里做著美好的事情壤短,想你悲傷的日...
    Yiyiyi_Gina閱讀 431評論 0 0
  • 要成為首富應(yīng)先定一個能達到的小目標,比方說我先掙它一個億纳胧。 最近大家是不是被小目標這個詞刷爆朋友圈镰吆?這個梗是被網(wǎng)友...
    荷茗閱讀 705評論 0 1