Fallback function execute when another contract call it with unknown function. Below is basic syntax for fallback function. There are two fallback functions, first one is simple and second is payable who can receive ethers. Three ways to call a method from another contract: Example of fallback function: when we transfer ether using fallback then… Continue reading Fallback function in Solidity
Here is the code example how can we destruct a contract. For destruction we have to set the payable address in selfdestruct method where all ethers of contract can be transferred. After destruct a contract all state variables become null, 0 or false, also we can’t update any state variable. e.g.
In this pattern we can define the owner of a contract, which restrict or control the protected methods, also can transfer his ownership to another.
Delay in withdraw can save smart contract from malicious activity. Here is the example how you can apply a delay in smart contract.
In the live contract there are many chances we find an type of error and we have to stop smart contract to handle malicious activity. here is the sample of Circuit Break Pattern.
During developing a smart contract sometime we need to manage the different stages and execute and restrict method according to that state/stage of the smart contract.
Authentication is very important in any project to control and give limited access to users for this purpose, in solidity we get this functionality with this pattern.
Here we apply cost based restriction, in which sender can’t able to send ethers less than cost defined my contract Owner.
Sometime we need to apply time base restrictions for special offer or ICO. Below, is the example for timebase restriction.
You can see here the difference b/w transfer, send method. Now, Here is the difference b/w transfer, send and call method. Here is the reentrancy attack Now protect from reentrancy attack: Another example to protect contract from reentrancy attack with the help of modifier: