# Banking Contract Key Concepts

#### Summary:

* **Owner Management**: Teaches how to restrict access to certain functions for contract owners.
* **Banking Functions**: Demonstrates how users can deposit and withdraw Ether.
* **Balance and Loan Tracking**: Illustrates keeping track of user balances and loan amounts.
* **Events**: Shows how to log contract actions for transparency using events.
* **Modifiers**: Demonstrates using function modifiers for access control and logical checks.

These contracts can be used to teach the basic functionality associated with each concept in the original `SimpleBank`contract.

#### 1. **Owner Management**

A contract where only the owner can execute certain functions.

```solidity
solidityCopy code// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;

contract OwnerContract {
    address public owner;

    constructor() {
        owner = msg.sender;  // Set the owner as the account that deploys the contract
    }

    modifier onlyOwner() {
        require(msg.sender == owner, "Only the owner can call this function");
        _;
    }

    function changeOwner(address newOwner) public onlyOwner {
        owner = newOwner;
    }

    function ownerOnlyFunction() public onlyOwner {
        // Only owner can execute this function
    }
}
```

#### 2. **Banking Functions (Deposit and Withdrawal)**

A simple contract where users can deposit Ether, and only the owner can withdraw it.

```solidity
solidityCopy code// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;

contract DepositWithdraw {
    address public owner;
    mapping(address => uint256) public balances;

    constructor() {
        owner = msg.sender;
    }

    function deposit() public payable {
        balances[msg.sender] += msg.value;
    }

    function withdraw() public {
        require(balances[msg.sender] > 0, "No balance to withdraw");
        uint256 amount = balances[msg.sender];
        balances[msg.sender] = 0;
        payable(msg.sender).transfer(amount);
    }

    function ownerWithdraw() public {
        require(msg.sender == owner, "Only the owner can withdraw all funds");
        payable(owner).transfer(address(this).balance);
    }
}
```

#### 3. **Balance and Loan Tracking**

A contract that tracks balances and loans for users.

```solidity
solidityCopy code// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;

contract LoanTracker {
    mapping(address => uint256) public balances;
    mapping(address => uint256) public loans;

    function deposit() public payable {
        balances[msg.sender] += msg.value;
    }

    function takeLoan(uint256 amount) public {
        require(amount > 0, "Loan must be greater than 0");
        loans[msg.sender] += amount;
    }

    function repayLoan() public payable {
        require(loans[msg.sender] > 0, "No outstanding loan");
        require(msg.value == loans[msg.sender], "Must repay exact loan amount");
        loans[msg.sender] = 0;
    }

    function getLoanAmount() public view returns (uint256) {
        return loans[msg.sender];
    }
}
```

#### 4. **Events**

A contract that demonstrates emitting events to log actions such as deposits and withdrawals.

```solidity
solidityCopy code// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;

contract EventLogger {
    event DepositMade(address indexed user, uint256 amount);
    event WithdrawalMade(address indexed user, uint256 amount);

    mapping(address => uint256) public balances;

    function deposit() public payable {
        balances[msg.sender] += msg.value;
        emit DepositMade(msg.sender, msg.value);
    }

    function withdraw(uint256 amount) public {
        require(balances[msg.sender] >= amount, "Insufficient balance");
        balances[msg.sender] -= amount;
        payable(msg.sender).transfer(amount);
        emit WithdrawalMade(msg.sender, amount);
    }
}
```

#### 5. **Modifiers**

A contract that demonstrates the use of function modifiers for access control.

```solidity
solidityCopy code// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;

contract ModifierExample {
    address public owner;

    constructor() {
        owner = msg.sender;
    }

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

    function restrictedFunction() public onlyOwner {
        // Only the owner can call this function
    }

    function openFunction() public {
        // Anyone can call this function
    }
}
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.xrpl-commons.org/evm-sidechain/banking-contract-key-concepts.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
