美文网首页
Cryptozombie Part4

Cryptozombie Part4

作者: Olly_Zhang | 来源:发表于2018-11-08 15:04 被阅读0次
Cryptozombie Part4

1. Payable modifier

A part of function that can receive Ether. In ethereum, both money. thevdata, and the code itself all live on ethereum, it's possible to call.a funcyion and pay money to the contract at the same time.

example:

contract onlineStore {

function buySomething() external payable {

  require(msg.value == 0.001 ether);

  transferThing(msg.sender);

}

}

2. Withdraws

after send ether to a contract, it gets stored in the contract's ethereum account, and it will be trapped there_ unless we add a function to withdraw the ether from the contract.

contract GetPaid is Ownable {

  function withdraw() external onlyOwner {

    owner.transfer(this.balance);

}

}

3. Random number via keccak256

this is a hash function

uint randNonce = 0;

uint random = uint (keccak256(now, msg.sender, randNOunce)) %100;

randNonce++;

it use keccak to convert yhese inputsbto a rand hash, convert that hash to a uint, and use %100 to take only thevlast 2 digits.

Cryptozombie Part4

相关文章

网友评论

      本文标题:Cryptozombie Part4

      本文链接:https://www.haomeiwen.com/subject/umlwxqtx.html