Bank Smart Contract

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.
Functions Available

For Demonstration Purpose , I will be deploying this smart contract on Javascript VM.

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

Common Functions

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.

Deployment of the Smart Contract

Owner Details

Any EOA can check owner and bank details which provide with the name and the bank name.

Details of the Bank

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.

Account By name Unnati Created
  • Note - EOA can only create one account

Account Holder Only Functionality

Check Balance

Owner of an account in the bank can check balance of their account in the bank.

Balance - 5 Ether

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.

Before Depositing
After Depositing 10 Ethers

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.

Withdrawing 20 Ethers
Transaction Error

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.

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.

Repay Loan

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

Previous Repayment Amount
New Loan Repayment Amount

The Loan Repayment Amount gets updated accordingly.

Close Account

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.

Close Account

Owner Functions

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.

Declare 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.

Bank Status

Close Bank

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

  1. Owner Pays 70 ether to start Bank
  2. EOA creates account by giving 10 ether.
  3. 5 ether given by the EOA is taked for creating account in the bank.
  4. Other 5 ether is deposited to the account of EOA.
  5. Owner Terminates Bank

Before Closing Bank -

Before Termination

After Closing Bank -

After Termination

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.

Source Code

The Code for this smart contract can be found in my github.

Thank You For Reading my Blog !!




A tech enthusiast pursuing B.Tech from BMSIT, Bangalore. A keen learner of new technologies and exploring use cases to create an impact in the society.

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

{UPDATE} Trump Said What? Hack Free Resources Generator

CPLAY target is to establish a safe and privacy protected cryptocurrency platform that will be able…

{UPDATE} Ball Jumping Hack Free Resources Generator

How Much Can You Earn by Sharing 2key Smartlinks? — Let’s Look at Real- Users’ Numbers

Using Digital Verification to secure Africa’s Mobility sector: Our Work with Staarm

Understanding User Authentication from Scratch

Finding Something Special

GRS (Groestlcoin) September ’21 Developer Update

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Suryansh Shrivastava

Suryansh Shrivastava

A tech enthusiast pursuing B.Tech from BMSIT, Bangalore. A keen learner of new technologies and exploring use cases to create an impact in the society.

More from Medium

What is Binance Smart Chain

Anatomy of a Smart Contract Scam

Smart contracts: neither smart, nor contracts

Why is Smart Contract Oracle Important In Blockchain Ecosystem?

Why is smart contract is important in blockchain ecosystem?