import “./Ownable.sol”;
contract Destroyable is Ownable {
function destroy() public onlyOwner {
selfdestruct(msg.sender);
}
}
import “./Ownable.sol”;
contract Destroyable is Ownable {
function destroy() public onlyOwner {
selfdestruct(msg.sender);
}
}
Ownable.sol
contract Ownable {
address public owner;
modifier onlyOwner {
require(msg.sender == owner);
_; //run the function
}
constructor() {
owner = msg.sender;
}
}
Destroyable.sol
import "./Ownable";
contract Destroyable is Ownable{
function destroy() public onlyOwner {
selfdestruct(owner);
}
}
Bank.sol
pragma solidity 0.7.5;
import "./Destroyable.sol";
contract Bank is Destroyable {
...
}
pragma solidity 0.7.5;
contract Ownable {
address payable public owner;
modifier onlyOwner {
require(msg.sender == owner);
_; //run the rest of the function after adding the line about to the modified function
}
constructor(){
owner = msg.sender;
}
}
contract Destroyable is Ownable {
function close() public onlyOwner { //onlyOwner is custom modifier
selfdestruct(owner); // `owner` is the owners address
}
}
Very interesting. I made a couple of mistakes such as (1) I had ‘import “./Ownable.sol”;’ underneath Pragma solidity 0.7.5
(2) I forgot to put ‘address payable receiver = msg.sender;’ inside of the self destruct function, so my code was:
pragma solidity 0.7.5;
import “./Ownable.sol”;
contract Destroyable is Ownable {
function destroy() public onlyOwner {
selfdestruct(owner);
}
}
However, I do understand the concept.
import "./Ownable.sol";
contract Destroyable is Ownable {
function close() public onlyOwner {
selfdestruct(msg.sender);
}
}
import "./Ownable.sol";
import "./Destroyable.sol";
contract Bank is Ownable, Destroyable
import "./Ownable.sol";
contract Destroyable is Ownable {
function close() public onlyOwner {
selfdestruct(msg.sender);
}
}
contract Ownable {
address payable public owner;
modifier onlyOwner {
require(msg.sender == owner, 'only owner can perform action');
_;
}
constructor(){
owner = msg.sender;
}
}
import "./Ownable.sol";
contract Destroyable is Ownable {
function close() public onlyOwner {
selfdestruct(owner);
}
}
/**
* Contracts for which the owners must be known.
*/
contract Ownable {
// internal as default
address owner;
modifier onlyOwner {
require (msg.sender == owner,"Only contract owner can execute this function.");
_; // run the function
}
// constructor
constructor() {
owner = msg.sender;
}
}
pragma solidity 0.7.5;
import "./Ownable.sol";
/**
* Contracts that can be destroyed.
*/
contract Destroyable is Ownable {
function close () public {
address payable _owner = payable(owner);
selfdestruct (_owner);
}
}
you could achieve the same by just assigning your owner
variable has payable, or selfdestruct(payable(owner));
If you have any more questions, please let us know so we can help you!
Carlos Z.
pragma solidity 0.7.5;
contract Destroyable {
address public owner;
constructor(){
owner = msg.sender;
}
modifier onlyOwner(){
require(msg.sender == owner);
_;
}
function close() public onlyOwner{
selfdestruct(owner);
}
}
My solution:
(Note: the code is written in version 0.8.3)
contract Destroyable is Ownable{
function close() public onlyOwner {
selfdestruct(payable(owner));
}
}
pragma solidity 0.7.5;
import “./ownable.sol”;
contract Destroyable is Ownable {
function destroy() public onlyOwner {
address payable receiver = msg.sender;
selfdestruct(receiver);
}
}
pragma solidity 0.7.5;
contract Destroyable {
address owner;
modifier onlyOwner {
require(msg.sender == owner);
_;
}
constructor() {
owner = msg.sender;
}
function destroy() public onlyOwner {
selfdestruct(msg.sender);
}
}
Create a new contract called Destroyable!
pragma solidity >=0.8.3;
import “./ownable.sol”;
contract SelfDestruct is Ownable {
function toSuicide() public onlyOwner{
selfdestruct (msg.sender);
}
}
Owner.sol
pragma solidity 0.7.5;
contract Owner{
address owner;
constructor(){
owner=msg.sender;
}
modifier Onlyowner{
require(msg.sender==owner);
_;
}
}
Destroyable.sol
pragma solidity 0.7.5;
import "./Owner.sol";
contract Destroyable is Owner{
function selfdestructor()public Onlyowner{
selfdestruct(msg.sender);
}
}
bank.sol
pragma solidity 0.7.5;
import "./Owner.sol";
import "./Destroyable.sol";
contract Bank is Owner,Destroyable{
mapping(address =>uint)balance; // etc, etc
Hey @Marcus_Hopkins
From Solidity 0.8 msg.sender
is not payable anymore by default.
You have to cast it to payable in order to use it as argument in selfdestruct()
.
Cheers,
Dani
import "./ownable.sol";
contract destroyable is ownable{
function destruct() public onlyowner {
selfdestruct(owner);
}
}
Ownable Contract.
pragma solidity 0.7.5;
contract Ownable {
address owner;
modifier onlyOwner {
require(msg.sender == owner);
_;
}
constructor(){
owner = msg.sender;
}
}
Self Destruct Contract.
pragma solidity 0.7.5;
import "./Ownable.sol";
contract MrSelfDestruct is Ownable {
function close() public onlyOwner {
selfdestruct(owner);
}
}
pragma solidity 0.7.5;
contract Ownable {
address public owner;
modifier onlyOwner () {
require(msg.sender==owner);
_;
}
constructor() public {
owner= msg.sender;
}
}
pragma solidity 0.7.5;
import "./ Ownable.sol";
contract Destroyable is Ownable {
function close () public onlyOwner {
selfdestruct ( owner); // it does not matter whether it is msg.sender or owner right ?
}
}