Ch 2: Making the Shell
Defining the shell
uint256 shellStrength; // The strength of the Walnut's shell.
constructor(uint256 _shellStrength, uint256 _kernel) {
shellStrength = _shellStrength; // Set the initial shell strength.
kernel = suint256(_kernel); // Initialize the kernel (cast to shielded).
}Adding the hit function
// Event to log hits
event Hit(address indexed hitter, uint256 remainingShellStrength);
// Modifier to ensure the shell is not cracked.
modifier requireIntact() {
require(shellStrength > 0, "SHELL_ALREADY_CRACKED");
_;
}
// Function to hit the walnut shell
function hit() public requireIntact {
shellStrength--; // Decrease the shell strength.
emit Hit(msg.sender, shellStrength); // Log the hit event.
}What’s happening here?
Example call:
Revealing the Kernel
Updated contract with hit, shake and look
Last updated

