how to make transaction like THIS TRANSACTION
anyone can help me how to build it
Ethereum Stack Exchange is a question and answer site for users of Ethereum, the decentralized application platform and smart contract enabled blockchain. It only takes a minute to sign up.
Sign up to join this communityhow to make transaction like THIS TRANSACTION
anyone can help me how to build it
For clarity, you can't make a script that runs around exterminating other contracts. You can organize things so the contracts you create are willing to selfdestruct
when you tell them to.
Here, a Factory
contract deploys a series of 10 contracts that will selfdestruct
if the Factory
(and only the Factory
) tells them to. There are verbose logs from both kinds of contract.
pragma solidity 0.4.25;
contract Factory {
address[] public volatileContracts;
event LogCreatedVolatileContract(address sender, address volatileContract);
event LogKilledVolatileContract(address sender, address volatileContract);
/**
* If this were a real implementation, you would want access control over these functions.
*/
function createVolatileContracts() public returns(bool success) {
require(volatileContracts.length==0, "Ten at a time, please.");
for(uint i=0; i<10; i++) {
Volatile v = new Volatile();
volatileContracts.push(address(v));
emit LogCreatedVolatileContract(msg.sender, address(v));
}
return true;
}
function destroyVolatileContracts() public returns(bool success) {
for(uint i=0; i<10; i++) {
emit LogKilledVolatileContract(msg.sender, volatileContracts[i]);
Volatile v = Volatile(volatileContracts[i]);
v.kill();
}
volatileContracts.length=0;
return true;
}
}
contract Volatile {
address public owner;
modifier onlyOwner {
require(msg.sender == owner);
_;
}
event LogSelfDestruction(address sender, address this, address owner, uint balance);
constructor() public {
owner = msg.sender;
}
function kill() public onlyOwner {
emit LogSelfDestruction(msg.sender, address(this), owner, address(this).balance);
selfdestruct(owner);
}
}
It's just a scribble to give you some ideas. There are multiple non-trivial concerns you would to address before thinking about using it. No warranty.
Hope it helps.
You can try the following code:
pragma solidity ^0.4.22;
contract exampleContract {
event Debug(bool destroyed); // Create an event to let web3 know that contract is destroyed
constructor () public {
// I've set this function internal which means you can only call this function from another function.
// You can set it to public but I'd recommend you to create a modifier for owner and use it instead.
function _destroyContract() internal {
emit Debug(true); // call event
// this - is the current contract address
selfdestruct(this); // selfDestruct contract
}
}
Hope this helps someone!
selfdestruct()
function from solidity? – Shawn Tabrizi Nov 12 '18 at 15:27