SOCI4L

Write the guard once

Step 1 of 3
0 of 4 goals

Take it from the base

Ownable above already has the owner and the modifier, and Vault repeats both. Two copies of a security check is one more than you can keep in step.

Inherit instead:

contract Vault is Ownable {

Then delete the duplicated owner, the constructor and the modifier from Vault.

// SPDX-License-Identifier: MIT
pragma solidity ^0.8.24;

contract Ownable {
    address public owner;

    constructor() {
        owner = msg.sender;
    }

    modifier onlyOwner() {
        require(msg.sender == owner, "not the owner");
        _;
    }
}

contract Vault {
    uint256 public rate;
    address public owner;

    constructor() {
        owner = msg.sender;
    }

    modifier onlyOwner() {
        require(msg.sender == owner, "not the owner");
        _;
    }

    function setRate(uint256 newRate) external onlyOwner {
        rate = newRate;
    }
}

Goals

The contract compiles
nothing to compile yet
Declare `owner`
no state variables declared yet
`rate` ends at 7
`rate` is not declared yet
The guard exists in one place
`Vault` does not inherit from `Ownable` yet

Contract storage

Write a contract and it will deploy itself here.