Cryptozombies Part2

2018-10-18  本文已影响0人  Olly_Zhang
Cryptozombies Part2

1. Mapping is another way of storing organized data in solidity.

mapping (address =>uint) public accountBalance;

mapping(uint => string) userIdToName;

2. Msg.sender

global variables available to all functions. msg.sender refers to the address of the person(or smart contract)who call tje functions.

mapping (address => uint) favoriteNumber;

function setMyNumber(uint _myNumber) public {

favoriteNumber[msg.sender] = _myNumber;

}

3. Require

require makes it so that the function will throw an error and stop executing if some condition is not true:

function sayhitovitalik(string _name) public returns (string) {

require (keccak256(_name) == keccak256("vitalik"));

return "hi!";

}

require is for verifying certain conditions that must be true before running  a function.

4. import

import "./chjkvggg.sol";

contract newcontact is chjkvggg {

}

5. storage vs memory

two places store variables

storage: var stored permanently on the blockchain

memory: var tempand erase btw external function calls to your contract

hard disk vs RAM

6. interface

for our contractvtalk to another contract on the blockchain that we do not own, first we need to define an interface.

contract NumberInterface {

function getNum(address _myaddrrss) public view returns (uint) ;

}

上一篇 下一篇

猜你喜欢

热点阅读