
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.

网友评论