https://github.com/blleshi/joint_savings_account_smart_contract
Joint Savings Account Smart Contract (Solidity)
https://github.com/blleshi/joint_savings_account_smart_contract
remix-ide smart-contracts solidity solidity-contracts
Last synced: 8 months ago
JSON representation
Joint Savings Account Smart Contract (Solidity)
- Host: GitHub
- URL: https://github.com/blleshi/joint_savings_account_smart_contract
- Owner: blleshi
- Created: 2024-08-06T05:40:01.000Z (about 1 year ago)
- Default Branch: main
- Last Pushed: 2024-09-03T16:15:13.000Z (about 1 year ago)
- Last Synced: 2025-01-10T05:21:54.546Z (9 months ago)
- Topics: remix-ide, smart-contracts, solidity, solidity-contracts
- Language: Solidity
- Homepage:
- Size: 507 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Joint Savings Account Smart Contract
The team is building smart contracts to automate many of the institutions’ financial processes and features, such as hosting joint savings accounts.
To automate the creation of joint savings accounts, you’ll create a Solidity smart contract that accepts two user addresses. These addresses will be able to control a joint savings account. Your smart contract will use ether management functions to implement a financial institution’s requirements for providing the features of the joint savings account. These features will consist of the ability to deposit and withdraw funds from the account.## What You're Creating
- The completed `JointSavings` Solidity smart contract.
- A folder named `Execution_Results` that contains at least eight images. These images should confirm that the deposit and withdrawal transactions, which are designed to test the `JointSavings` functionality in the JavaScript VM, worked as expected.## Instructions
The steps for this Challenge are divided into the following sections:
1. [Create a Joint Savings Account Contract in Solidity](#step-1-create-a-joint-savings-account-contract-in-solidity)
2. [Compile and Deploy Your Contract in the JavaScript VM](#step-2-compile-and-deploy-your-contract-in-the-javascript-vm)
3. [Interact with Your Deployed Smart Contract](#step-3-interact-with-your-deployed-smart-contract)### Step 1: Create a Joint Savings Account Contract in Solidity
1. From the provided starter code, open the Solidity file named `joint_savings.sol` in the Remix IDE.
2. Define a new contract named `JointSavings`.
3. Define the following variables in the new contract:
- Two variables of type `address payable` named `accountOne` and `accountTwo`.
- A variable of type `address public` named `lastToWithdraw`.
- Two variables of type `uint public` named `lastWithdrawAmount` and `contractBalance`.4. Define a function named `withdraw` that accepts two arguments: `amount` of type `uint` and `recipient` of type `payable address`. In this function, create code as follows:
- Define a `require` statement that checks if `recipient` is equal to either `accountOne` or `accountTwo`. If it isn’t, the `require` statement will return the “You don't own this account!” text.
- Define a `require` statement that checks if the balance is sufficient for accomplishing the withdrawal operation. If insufficient funds exist, it will return the “Insufficient funds!” text.
- Add an `if` statement to check if `lastToWithdraw` is not equal to `recipient`. If it isn’t equal, set it to the current value of `recipient`.
- Call the `transfer` function of the `recipient`, and pass it the `amount` to transfer as an argument.
- Set `lastWithdrawAmount` equal to `amount`.
- Set the `contractBalance` variable equal to the balance of the contract by using `address(this).balance` to reflect the new balance of the contract.5. Define a public payable function named `deposit`. In this function, create code as follows:
- Set the `contractBalance` variable equal to the balance of the contract by using `address(this).balance`.6. Define a public function named `setAccounts` that takes two `address payable` arguments, named `account1` and `account2`. In the body of the function, set the values of `accountOne` and `accountTwo` to `account1` and `account2`, respectively.
7. Add a fallback function so that your contract can store ether that’s sent from outside the deposit function.
### Step 2: Compile and Deploy Your Contract in the JavaScript VM
1. Compile your smart contract. If an error occurs, review your code, and make the necessary changes for a successful compilation.
2. In the Remix IDE, navigate to the “Deploy & Run Transactions” pane, and then make sure that “JavaScript VM” is selected as the environment.
3. Click the Deploy button to deploy your smart contract, and then confirm that it successfully deployed.
### Step 3: Interact with Your Deployed Smart Contract
Now that your contract is deployed, it’s time to test its functionality. After each step, capture a screenshot of the execution, and then save it in a folder named `Execution_Results`. You’ll share this folder with your final submission.
To interact with your deployed smart contract, complete the following steps:
1. Use the `setAccounts` function to define the authorized Ethereum address that will be able to withdraw funds from your contract.
> **Note:** You can either create dummy addresses on the [Vanity-ETH](https://vanity-eth.tk/) website, which includes an Ethereum vanity address generator, or use the following Ethereum addresses:
> - Dummy account1 address: `0x0c0669Cd5e60a6F4b8ce437E4a4A007093D368Cb`
> - Dummy account2 address: `0x7A1f3dFAa0a4a19844B606CD6e91d693083B12c0`2. Test the deposit functionality of your smart contract by sending the following amounts of ether. After each transaction, use the `contractBalance` function to verify that the funds were added to your contract:
- Transaction 1: Send 1 ether as wei.
- Transaction 2: Send 10 ether as wei.
- Transaction 3: Send 5 ether.> **Note:** Remembering how to convert ether to wei and vice versa can be challenging. So, you can use a website like [Ethereum Unit Converter](https://eth-converter.com/) to ease doing the conversion.
3. Once you’ve successfully deposited funds into your contract, test the contract’s withdrawal functionality by withdrawing 5 ether into `accountOne` and 10 ether into `accountTwo`. After each transaction, use the `contractBalance` function to verify that the funds were withdrawn from your contract. Also, use the `lastToWithdraw` and `lastWithdrawAmount` functions to verify that the address and amount were correct.