This Ethereum Based Smart Contract is made in Solidity Language and can be deployed in any environment such as Web3 Provider , Injected Web3 , etc.
Features of this smart contract :-
- Anyone who has more than 50 ether can setup a bank.
- EOA can create accounts in the bank.
- EOA can deposit and withdraw their ether anytime.
- EOA can take up loan and can repay the loan with some interest to the bank.
- EOA can check their balance , check their loan repayment amount anytime.
- EOA can close their account in the bank.
- Owner can declare bank holiday at any time.
- Owner can see their bank status.
- Owner can close their bank.
For Simplicity I have divided the functionality of this smart contract into 3 Parts :-
- Common Functionality (Bank Owner and Account Holder)
- Account Holder Only Functionality
- Bank Owner Only Functionality
Setup of Bank
Anyone who wants to deploy this bank smart contract needs to deposit at least 50 ethers as a safety amount so that the bank can operate normally. He/She will have to provide their name and their bank name. After Deploying the smart contract he will be become the owner of the Bank.
Any EOA can check owner and bank details which provide with the name and the bank name.
Creation of Accounts By EOA
Any EOA can create their account in the bank by paying 5 ether as account creation amount. For eg , if an EOA pays 10 ethers to the bank for creating their account , 5 Ether will taken as account creation amount and the remaining ether that is 5 ether in this case gets deposited in their account in the bank.
- Note - EOA can only create one account
Account Holder Only Functionality
Owner of an account in the bank can check balance of their account in the bank.
Deposit Ether to account
Any Account Owner can deposit any amount of ethers to their bank account.
After Depositing eithers to their bank account , owner can see their balance to confirm deposit of their ether .
For eg. I am going to deposit 10 Eithers to my account.
Withdraw Ethers from account
Any Account Owner can withdraw any amount of ethers from their bank account to their wallet.
If the owner wants to withdraw 20 ethers and only has 15 ethers in their bank account , he will encounter an error and hence his transaction won’t go through.
Loan from the bank
Anyone who has an account in the bank can take loan up to 25% of the funds that are available in their bank account at an interest of 33%.
- Note - EOA can take only one loan at a time , after repayment of the current loan , additional loan can be taken by the account holder.
For eg . If some has 15 ethers in their account they can take maximum of 3 ethers , if they try to take more than 3 ethers in this case they wont be able to transact.
After taking loan , the EOA wallet will be updated.
Check Loan Repayment Amount
Anyone who has taken a loan can check their loan repayment amount.
In the case that we have mentioned above i.e taking loan of 3 ether will result in a 4 ether repayment amount due to bank’s 33% interest.
Loan Bearer can repay their loan amount with interest in parts or all at once , if more ether is given then that of the loan repayment amount , additional ether will be added to their account.
For eg. I will repay 2 ether to the bank
The Loan Repayment Amount gets updated accordingly.
An Account owner in the bank can close their account , all the ether in his account will be returned to him . If the owner had taken loan he would have to pay up all his loans before closing account or else he won’t be able to terminate/close his account . If in the future he wishes to use the same bank , he will have to create another account for using the functionality of the bank.
Declare Bank Holiday
If the owner of the bank declares a holiday , basic functionality of the bank will be stopped for time being until the owner declares the holiday over.
Account Holders won’t be able to withdraw/deposit/take loan/ repay loan/close account during bank holiday.
Show Bank Status
Owner can see the bank status which provides them information of no. of accounts created in the bank , Funds available in the bank , Bank holiday or not.
Owner can close the bank bearing any loses of the bank if there are some pending loans , every account of the bank will be terminated and the bank account holder’s will receive their account balance back to their wallets. The remaining fund will be given back to the owner of the Bank.
For eg. -
1 Owner and 1 Customer Situation
- Owner Pays 70 ether to start Bank
- EOA creates account by giving 10 ether.
- 5 ether given by the EOA is taked for creating account in the bank.
- Other 5 ether is deposited to the account of EOA.
- Owner Terminates Bank
Before Closing Bank -
After Closing Bank -
EOA Account receives its deposited money back and the remaining money goes to the owner of the bank.
This Termination works even with greater no of Accounts in the bank.
This smart contract handles basic functionality of a bank without creating a need of a Powerful 3rd party . This smart contract is traceable and secure. Every transaction that takes place in the contract is noted in a map i.e of loan and repayment , amount of loan taken by an account etc.
The Disadvantage of Such smart contract is that , lot of gas is required to deploy and transact in such smart contract.
The Code for this smart contract can be found in my github.
You can't perform that action at this time. You signed in with another tab or window. You signed out in another tab or…
Thank You For Reading my Blog !!