Search code examples
ethereumsolidity

How to implement self destruct pattern in Solidity?


Hi I am working on the auction app in block chain using solidity as smart contract in Ethereum. The requirements are

  1. The DAPP will ask for the auction in the public domain like for example selling an iPhone
  2. All the users will bid for the item
  3. The smart contract will find the winner based on the highest money and declare him as the winner.

I want to add another functionality by self destructing the auction after specified amount of time and no other auction will take place after that.

How can we do this in solidity?

Any help would be really appreciated.Thanks!


Solution

  • Certainly. I have similar task in my dApp. I solve it using block.timestamp field. Timestamp field returns timestamp of latest block. You can solve your problem by using the following construct at the start of all methods related to auction bidding:

    require(block.timestamp > auction.endTime, "Auction is closed.");
    

    Essentially what it does is block any code if it happens after your auctions end time. Let me know if you need more help.