// 声明contractNumberInterface{functiongetNum(address_myAddress)publicviewreturns(uint);}contractMyContract{addressNumberInterfaceAddress=0x06012c8cf97BEaD5deAe237070F9587f8E....;// ^ The address of the FavoriteNumber contract on EthereumNumberInterfacenumberContract=NumberInterface(NumberInterfaceAddress);// Now numberContract is pointing to the other contractfunctionsomeFunction()public{// Now we can call getNum from that contract:uintnum=numberContract.getNum(msg.sender);// ...and do something with num here}}
/** * @title Ownable * @dev The Ownable contract has an owner address, and provides basic authorization control * functions, this simplifies the implementation of "user permissions". */contractOwnable{addresspublicowner;eventOwnershipTransferred(addressindexedpreviousOwner,addressindexednewOwner);/** * @dev The Ownable constructor sets the original `owner` of the contract to the sender * account. */functionOwnable()public{owner=msg.sender;}/** * @dev Throws if called by any account other than the owner. */modifieronlyOwner(){require(msg.sender==owner);_;}/** * @dev Allows the current owner to transfer control of the contract to a newOwner. * @param newOwner The address to transfer ownership to. */functiontransferOwnership(addressnewOwner)publiconlyOwner{require(newOwner!=address(0));OwnershipTransferred(owner,newOwner);owner=newOwner;}}
性能优化
通常情况下我们不会考虑使用 unit 变种,因为无论如何定义 uint的大小,Solidity 为它保留256位的存储空间。例如,使用 uint8 而不是uint(uint256)不会为你节省任何gas。