【Answer】
Practice 1
Practice 2
Practice 3
Practice 4
Practice 5
pragma solidity ^0.8.11
contract StartStopContract {
address owner;
bool paused; // default false
constructor() public{
// constructor is triggered in only once in contract deploy
owner = msg.sender;
}
function sendMoney() public payable {
}
function withdrawMoneyTo(address payable _to) public {
// if(msg.sender == owner) {
// _to.transfer(address(this).balance);
// } else {
// new Exception(...)
// }
require(msg.sender == owner, "You are not the Owner");
require(!paused, "Contract is paused");
_to.transfer(address(this).balance);
}
function setPaused(bool _paused) public {
require(msg.sender == owner, "You are not the Owner");
paused = _paused;
}
function destroySmartContract(address payable _to) public {
require(msg.sender == owner, "You are not the Owner");
selfdestruct(_to);
}
}
Practice 6
try feed.getData(token) returns (uint v) {
require(1 == 2, "Will revert"); // This will cause the transaction to revert!!
} catch (bytes memory /*lowLevelData*/) {
return (0); // Will not get here
}
Last updated
Was this helpful?