0% found this document useful (0 votes)
10 views89 pages

Title: Chur Rate Predictio

The document discusses customer churn prediction, emphasizing its importance for companies to retain existing customers rather than acquiring new ones. It outlines the objectives, related work, methodology, and technical architecture for predicting customer churn in a banking context using various machine learning techniques. The ultimate goal is to reduce churn rates and enhance profitability through targeted marketing efforts and improved customer experiences.

Uploaded by

omey1230
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
10 views89 pages

Title: Chur Rate Predictio

The document discusses customer churn prediction, emphasizing its importance for companies to retain existing customers rather than acquiring new ones. It outlines the objectives, related work, methodology, and technical architecture for predicting customer churn in a banking context using various machine learning techniques. The ultimate goal is to reduce churn rates and enhance profitability through targeted marketing efforts and improved customer experiences.

Uploaded by

omey1230
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

Churn Rate Prediction

Title
CHURN RATE PREDICTION

Dept. of Computer Science, BKBCK


2|Page
Churn Rate Prediction

Objective:

Customer Churn prediction means knowing which customers are likely to leave
or unsubscribe from your service. For many companies, this is an important
prediction. This is because acquiring new customers often costs more than
retaining existing ones. The focus on customer churn is to determinate the
customers who are at risk of leaving and if possible on the analysis whether
those customers are worth retaining. A company will therefore have a sense of
how much is really being lost because of the customer churn and the scale of
the efforts that would be appropriate for retention campaign

The primary goals of an churn prediction project typically include:


1. The ultimate goal of churn analysis is to reduce churn and increase
profits. As more customers stay longer, revenue should increase, and
profits should follow.
2. If customers are leaving because of specific issues with your product or
service or shipping method, you have an opportunity to
improve. Implementing these insights reduces customer churn and
improves the overall product or service for future growth.
3. The opposite of customer churn is customer retention. A company can
retain customers and continue to generate revenue from them. High
customer loyalty enables companies to increase the profitability of
their existing customers and maximize their lifetime value (LTV).
4. Once you’ve identified customers at risk of churn, you need to know
exactly what marketing efforts you should make with each customer to
maximize their likelihood of staying.

The purpose of this study is to build the most appropriate model to predict
client churn in a Bank in the early stages

Dept. of Computer Science, BKBCK


3|Page
Churn Rate Prediction

Related Work:

1. Name:
“Data mining: an overview from a database perspective,” IEEE Transactions on
Knowledge and data Engineering,
i. Complete citation:
“Data mining: an overview from a database perspective,” IEEE Transactions on
Knowledge and data Engineering,
M.-S. Chen, J. Han, and P. S. Yu,

ii. Key words:


Customer churn in Bank, k-Nearest Neighbour, Support Vector Machine,
Decision Tree, Random Forest.

iii. Hypothesis or research question:


The need for a system that can efficiently predict customer churn in the early
stages is really important for any organization.

iv. Summary:
Customer churn takes place when clients or subscribers cease to engage
incorporation with a company or service. For any organization, winning business
from new clients means going via the sales pipeline, using their sales and
marketing assets in the cycle. Customer retention, on the other hand, is usually
more budget-effective, because they have already gained the confidence and
loyalty of current customers

Dept. of Computer Science, BKBCK


4|Page
Churn Rate Prediction

2. Name:
When customers are members: Customer retention in paid membership contexts.
Journal of the Academy of Marketing Science

i. Complete citation:
When customers are members: Customer retention in paid membership contexts.
Journal of the Academy of Marketing Science
Bhattacharya, C. B.

ii. Key words:


Savings Bank, Customer Churn, Customer Retention, Random Forests, Machine
Learning, Under-Sampling

iii. Hypothesis or research question:


When Customer can leave the bank or not?

iv. Summary:

Well, this paper is what I need to share why everyone searching Churn
Prediction on google. In this researches take help of google trends data and
according to it they find how prediction word going on top in search index and
what was the reason behind it.

It is based on various statistical & machine learning models and uses under-
sampling, to improve the predictive power of these models, considering the
imbalance characteristics of customer churn rate in the data

Dept. of Computer Science, BKBCK 5|Page


Churn Rate Prediction

3. Name:
Customer Churn Analysis in Banking Sector

i. Complete citation:
Customer Churn Analysis in Banking Sector
Saw Thazin Khine 1 , Win Win Myo 1,

ii. Keywords:
churn prediction, data mining, k-means, Support Vector Machine

iii. Hypothesis or research question:


All about banking predictions

iv. Summary:

The role of ICT in the banking sector is a crucial part of the development of
nations. The development of the banking sector mostly depends on its valuable
customers. So, customer churn analysis is needed to determine customers
whether they are at risk of leaving or worth retaining

Dept. of Computer Science, BKBCK 6|Page


Churn Rate Prediction

4 . Name:
Churn Prediction and Retention in Banking

i. Complete citation:
Churn Prediction and Retention in Banking using Machine Learning
Himani Jain , Garima Yadav , and R. Manoov

ii. Keywords:
XGboost, Random Forest, SVM , Logistic Regression.

iii. Hypothesis or research question:


To compare the performances of various algorithms and build the best model for
churn prediction in telecom, banking and IT sectors, respectively

iv. Summary:
Based on the results and exploratory data analysis, we will derive which
attributes contribute more towards the customer churn and accordingly develop
various retention strategies for the respective domains.
In order to understand early signs of customer churn, we should have a detailed
information about our customers and their interactions across various channels
like calls to customer services, social media interactions, mobile and Web-based
transactions. If we can successfully detect these early signs, we can take
preventive actions like giving the customers a hefty discount, special offers,
perks, etc., to prevent churn.

Dept. of Computer Science, BKBCK 7|Page


Churn Rate Prediction

Methodology:

Customer Churn prediction means knowing which customers are likely to leave
or unsubscribe from your service. For many companies, this is an important
prediction. This is because acquiring new customers often costs more than
retaining existing ones. Once you’ve identified customers at risk of churn, you
need to know exactly what marketing efforts you should make with each
customer to maximize their likelihood of staying.

Customers have different behaviors and preferences, and reasons for cancelling
their subscriptions. Therefore, it is important to actively communicate with each
of them to keep them on your customer list. You need to know which marketing
activities are most effective for individual customers and when they are most
effective.

Market Research:
Businesses sell products and services to make money. Therefore, the ultimate
goal of churn analysis is to reduce churn and increase profits. As more
customers stay longer, revenue should increase, and profits should follow.].
• Improve the customer experience
• Optimize your products and services

NFT Marketplaces in India:


In India, As per studies and reports the average monthly churn rate of wireless
subscribers in India is around 6% which is one of the highest in the world. As
per the information pubtished on in-actiu" SIM, in the consultation paper also
the monthly churn is around s-6%.

Dept. of Computer Science, BKBCK 8|Page


Churn Rate Prediction

CHURN RATE:
• Churn rate is defined as the rate at which individual/customers leave a
group/subscription over a specified period.
• In the most general sense, it is referred to as the proportion of subscribed
customers who terminate their contractual relationship (i.e.,
subscription) with a company over a given timeframe
• Churn rate can be applied to subscription-based businesses as well as to
the number of employees that leave a firm
• A high churn rate could adversely affect profits and impede growth.
Advantages of calculating a company’s churn rate is that it provides
clarity on how well the business is retaining its customers.
• The churn rate will indicate to a company that it needs to understand
why its clients are leaving and where to fix its business. The cost of
acquiring new customers is higher than it is to retain existing customers.

Technical Architecture:

Flow Diagram

Dept. of Computer Science, BKBCK 9|Page


Churn Rate Prediction

This work aims to predict customer churn in a commercial bank as early as


possible using efficient data mining methods. A diagrammatic representation of
the proposed model is given.

A. Dataset description
The dataset used in this analysis was obtained from Kaggle to model churns. The
dataset includes information of 10000 bank clients, and the target parameter is a
binary variable that represents whether the customer has left the bank or still a
customer. Of this, 7963 were positive class(maintained) samples and 2037 were
negative class(exited) samples. The target variable reflects the binary flag 1 when
the client has a bank account closed, and 0 when the client is retained. The dataset
contains 13 feature vectors(predictors) that were reported from customer data and
transactions processed by the customer.

B. Data Preprocessing
Preprocessing the data is a significant phase in the process of data mining. Since
they have a direct effect on task success rate. It must deal with irrelevance,
noisiness, and unreliability of data. And if necessary, the data conversion too.
Predictors descriptions after preprocessing are listed . These are the attributes
taken for deciding on churn prediction in this study.

Data Visualization Various business industries are consulting with analytics


experts to extract insights from the enormous data available to businesses
regarding their supply chain to help improve decision making. Descriptive
Statistical Analysis helps us to understand the data and is an essential part of
Machine Learning modeling; this is due to Machine Learning being all about
making predictions. On the other hand, statistical analysis is all about drawing
conclusions from data, which is a necessary initial step for developing predictive

Dept. of Computer Science, BKBCK 10 | P a g e


Churn Rate Prediction

models.

C. Data Visualization
Various business industries are consulting with analytics experts to extract
insights from the enormous data available to businesses regarding their supply
chain to help improve decision making. Descriptive Statistical Analysis helps us
to understand the data and is an essential part of Machine Learning modeling; this
is due to Machine Learning being all about making predictions. On the other
hand, statistical analysis is all about drawing conclusions from data, which is a
necessary initial step for developing predictive models.

D. Data Cleaning
We discover missing or corrupt data and think of various data cleaning operations
to perform, such as marking or removing bad data and imputing missing data. For
most of the features, a separate category for missing values has been created so
that the model does not lose vital information.

E. Model Selection
Artificial Intelligence (AI) and machine learning (ML) are making the customer
experience more personalized and contextual than ever before. Banks and credit
unions are using advanced technology to build websites, emails, digital
advertising, social media, and other content more efficiently and effectively; this
is increasing marketing return of investment (ROI) as well as customer
satisfaction and customer retention. Considering the necessity to keep up with the

Dept. of Computer Science, BKBCK 11 | P a g e


Churn Rate Prediction

competition, data science has become a tool to enhance the business in the
banking industry. Indian commercial banks must understand that big data
technologies can help them focus their resources efficiently, make sharp-witted
decisions, and improve the performance of their products and services. In the
current world of information technology and hyped overrated techniques,
machine learning has a great future in terms of industrial research and business
benefit. The potential of computer algorithms to learn on their own and improve
over time generates new opportunities for industries across the board, especially
for the banking industry.

The Churn Model has been built in two steps:


In the First Step, all predictors/features which are believed to be influencing
customer attrition have been passed to the Logistic Regression, C 5.0, CHAID,
ANN, XG-BOOST, and Decision Tree techniques. In order to improve the
efficiency of the model, we further have passed the important predictors,
identified in the previous step, through the Random Forest algorithm to build a
Machine Learning Model for prediction of customer attrition.

Dept. of Computer Science, BKBCK 12 | P a g e


Churn Rate Prediction

Techniques/tools:

Qualtrics CustomerXM for churn prediction and prevention

Predicting where and when churn is most likely to happen is one of the best ways to
reduce it. Qualtrics CustomerXM helps you lower churn by providing insight into how
users feel about and interact with your product.

Use Qualtrics to distribute surveys to customers via various channels, so you can collect
valuable feedback and engage users. Its Predict IQ™ technology identifies customers
and accounts likely to churn and tells you what drives that behavior, giving you key
insights you'd otherwise have to spend weeks gathering manually.

The tool’s role-based dashboard presents targeted information to different teams, so they
can take the right steps to prevent churn in high-risk users.

This means your customer success team doesn’t just see sales data, and product teams
don’t get caught up in marketing metrics. Each team gets a segmented view that makes
data more digestible and actionable—so everyone knows what they need to do to delight
users and prevent churn.

Hotjar to see customer behaviour in action and understand reasons for churn

Once you find out where and when your customers are churning, you need to
understand the ‘why’. This is where Hotjar a product experience (PX) insights tool, can
help. Hotjar collects qualitative and quantitative data about users’ behaviour and
opinions, so you can pinpoint what’s frustrating them.

Hotjar’s Observe tools—Heatmaps and Recordings—give you a first hand look at how
your users experience your product. For example, Hotjar's Recordings tool shows you
playbacks of user sessions, so you can identify actions, like rage clicks, and elements
that irritate your customers and make them stop using your website or service.

ChurnZero to fight churn at every step of the customer journey

ChurnZero describes itself as a 'holistic customer success management platform', and it


helps you detect and prevent churn at every stage in your customer’s journey through

Dept. of Computer Science, BKBCK 13 | P a g e


Churn Rate Prediction

tailored solutions for user onboarding, product adoption, and subscription renewals and
upgrades.

The platform lets you integrate data related to just about every user touchpoint, starting
from sales and going all the way to customer support. ChurnZero then uses this data to
generate a 'churn score', which gives you a clear look at your customers' health, or how
satisfied and engaged they are with your product experience.

It also notifies you when customer activation milestones occur, so you can keep track of
the events when churn occurs. At the same time, the Command Center gives you a
convenient overview of key information and pending tasks.

Implementation Details:

Dept. of Computer Science, BKBCK 14 | P a g e


Churn Rate Prediction

“CHURN RATE " is a project that was built to make a project based on smart
contract to be used by the banker or other service companies to check their
growth. The project was implemented using Pycharm, Jupyter, Flask,

The first step in the implementation of the project was to create or use a custom
site suitable for user needs. This was done using the Flask and Streamlit.

Applying machine learning (ML) to customer data helps companies develop


focused customer-retention programs. For example, a marketing department
could use an ML churn model to identify high-risk customers and send
promotional content to entice them.
To enable these models to make predictions with new data, knowing how to
package a model as a user-facing, interactive application is essential. In this
blog, we’ll take an ML model from a Jupyter Notebook environment to a
containerized application. We’ll use Streamlit as our application framework to
build UI components and package our model. Next, we’ll use Docker to publish
our model as an endpoint.

Dept. of Computer Science, BKBCK 15 | P a g e


Churn Rate Prediction

Experimental setup and results:

Dept. of Computer Science, BKBCK 16 | P a g e


Churn Rate Prediction

 Technical Architecture:

Collecting the data:

Here the data will be collected from the given csv file or dataset. The data will be
displayed with its various categories.

Data Cleaning:

Data cleaning means fixing bad data in your data [Link] data could be:

• Empty cells
• Data in wrong format
• Wrong data
• Duplicates

Exploratary Data Analysis:

EDA is applied to investigate the data and summarize the key insights.

Dept. of Computer Science, BKBCK 17 | P a g e


Churn Rate Prediction

It will give you the basic understanding of your data, it’s distribution, null values
and much more.
You can either explore data using graphs or through some python functions.

Model Evaluation:

Evaluation is a process during development of the model to check whether the


model is best fit for the given problem and corresponding data.

Model Selection:
Model selection is the process of selecting one final machine learning model
from among a collection of candidate machine learning models for a training
dataset. Model selection is a process that can be applied both across different
types of models

Model Deployment:
Deployment is the method by which you integrate a machine learning model into
an existing production environment to make practical business decisions based
on data. It is one of the last stages in the machine learning life cycle and can be
one of the most cumbersome.

 Process flow:

Dept. of Computer Science, BKBCK 18 | P a g e


Churn Rate Prediction

K-Nearest Neighbors
K-nearest neighbors is a machine learning and data mining algorithm used to
address classification and regression problems. It uses Euclidean distance to find
the similarity between the classes.
Boosting
The idea of using Boosting algorithm for customer churn prediction is to train a
series of classifier simultaneously and keep updating the model accuracy for
improving the performance of the classifier.
XGBoost
XGBoost is extreme gradient boosting. It is the mostly used predominant and
advanced algorithm to solve machine learning problems. It dispenses support in
most 686 H. Dalmia et al. of the developing environments (C++, python, R). It is
mainly used for increased performance and high speed.
To assess the performance of the classifier model for churn prediction, bank data
is trained for a specific period, and then, the customers of the bank are classified
into loyal or churn based on their activities. This prediction gives useful insights

Dept. of Computer Science, BKBCK 19 | P a g e


Churn Rate Prediction

to the bank officials regarding its customers and functioning of bank. The
performance of the prediction model is the capability to identify customers exit
status accurately. We use confusion matrix for evaluation.

 Architecture / Framework:
KNN:
K-means clustering It is widely used and is a very simple technique to analyze
huge amounts of data in clusters. And very quick, robust and easily
comprehensible too.
When a new customer is presented, the algorithm looks through the database
for customers who are most similar to the target customer. It then predicts if the
customer would churn based on whether those similar customers churned or not.
KNN works by identifying the k nearest samples from an existing dataset and
when a new unknown sample appears, classify the new sample in the most
similar class. That is, the classification algorithm determines the test sample
group by the k training samples that are the nearest neighbours to the test sample
and assign it to the class with the highest likelihood

Support vector machine (SVM) :


SVM is used to develop a predictive model for classifying which customers on
the output of clustering results are likely to be churner or nonchurner. Binary
classification technique is widely used in model prediction. It can solve both
linear and non-linear issues and work well for many practical issues.
SVM’s main objective is to find an efficient distinguishing hyperplane that
precisely categorizes data points and as far as possible, and distinguishes the
points of two classes by reducing the possibility of misclassifying the training
samples and unknown test samples. This implies that there is the maximum
distance between two classes and the separating hyperplane.

Decision Tree(DT):
A decision tree is a procedure that slices a collection of data into various branch-
like segments. A tree of decisions is easy to read. This advantage makes
explanations for the model simple. While another algorithm (like a neural
network) can generate a much more accurate model in a given scenario, a
decision tree could be trained to predict the neural network’s predictions, thus
opening up the neural network’s ”black box”. Another benefit is that, in the
correlation between the target variables and the predictor variables it can model
a high degree of nonlinearity. A decision tree is composed of two major
strategies ; Tree creation and Classification.

Dept. of Computer Science, BKBCK 20 | P a g e


Churn Rate Prediction

Random Forest(RF):
The method employs several decision trees so that each tree relies on the values
of an individually selected random vector with the same distribution for all trees.
Right choice for the tendency of decision trees to overfit their training
collection. In short, Random forests are actually a way to combine many deep
decision trees which are learned on various sections of the same dataset with the
target of decreasing the variance. The real advantage of using RF is it comes
with quite high dimensional data, with no need to perform dimensionality
reduction and feature selection. The training rate is also higher and ease to use in
parallel models.

 Softwares:
Pycharm:
PyCharm is an integrated development environment (IDE) used for
programming in Python. It provides code analysis, a graphical debugger, an
integrated unit tester, integration with version control systems, and supports web
development with Django. PyCharm is developed by the Czech
company JetBrains.
It is cross-platform, working on Microsoft Windows, macOS and Linux.
PyCharm has a Professional Edition, released under a proprietary license and a
Community Edition released under the Apache License. PyCharm Community
Edition is less extensive than the Professional Edition. Scientific tools integration:
integrates with IPython Notebook, has an interactive Python console, and
supports Anaconda as well as multiple scientific packages including Matplotlib
and NumPy.

Flask:
Flask is a micro web framework written in Python. It is classified as
a microframework because it does not require particular tools or libraries. It has
no database abstraction layer, form validation, or any other components where
pre-existing third-party libraries provide common functions. However, Flask
supports extensions that can add application features as if they were implemented
in Flask itself. Extensions exist for object-relational mappers, form validation,
upload handling, various open authentication technologies and several common
framework related tools.

Dept. of Computer Science, BKBCK 21 | P a g e


Churn Rate Prediction

Streamlit:
Streamlit is a free and open-source framework to rapidly build and share beautiful
machine learning and data science web apps. It is a Python-based library
specifically designed for machine learning engineers. Data scientists or machine
learning engineers are not web developers and they're not interested in spending
weeks learning to use these frameworks to build web apps. Instead, they want a
tool that is easier to learn and to use, as long as it can display data and collect
needed parameters for modeling. Streamlit allows you to create a stunning-
looking application with only a few lines of code.
Streamlit is a promising open-source Python library, which enables developers to
build attractive user interfaces in no time.
Streamlit is the easiest way especially for people with no front-end knowledge to
put their code into a web application:
• No front-end (html, js, css) experience or knowledge is required.
• You don't need to spend days or months to create a web app, you can create
a really beautiful machine learning or data science app in only a few hours
or even minutes.
• It is compatible with the majority of Python libraries (e.g. pandas,
matplotlib, seaborn, plotly, Keras, PyTorch, SymPy(latex)).

Display of the page:

Dept. of Computer Science, BKBCK 22 | P a g e


Churn Rate Prediction

The given page shown is the main page. It has all the categories, from where we
can predict about customers.

Dept. of Computer Science, BKBCK 23 | P a g e


Churn Rate Prediction

Here,
Credit Score: It indicate what is the credit score of the person with bank account.
Age: We have to enter the age of the customer
Tenure: a virtual guarantee of lifetime employment granted to employees after
showing committed work for five to 10 years.

Here,
In 1st box, we have to see or check whether the customer is active or not. We have
to see whether the person is using our bak services or not.
1 indicates Yes
0 indicates No
The 2nd box, we have to define estimate salary of the customer.

We have to enter the account balance of the person, also we have to enter
number of products.

Dept. of Computer Science, BKBCK 24 | P a g e


Churn Rate Prediction

Here,
We have to enter the location by choosing options. There are four location.
Also, we should select the gender of the customer.

Here we have to mention whether the customer have the credit card or not.
If Yes then 1, if No then 0.
The last button shown in the picture is to check whether the customer will leave
the bank or not.

▪ Findings of Project work:


• The Goals of this project is to find out the characteristic
of customers who cancelled and finding a pattern in cancelled booking by
exploratory data analysis.
• Building model to predict cancellation.

Dept. of Computer Science, BKBCK 25 | P a g e


Churn Rate Prediction

• Create a dashboard and deploy the model


using flask/streamlit etc from our machine learning or
deep learning algorithm, that can predict of
cancellation based on user input.

Challenges Faced -
• Target variable “is_canceled” has an imbalanced set of values for the two
classes. In order to make the model correctly predict, the imbalance needed
to be handled.
• We had a variety of models to choose from but running them all was a time
consuming and hardware heavy task.
• Understanding the different models and the parameters to input in order to
make the model better at predicting.
• Deploying the model

How Did We Overcome? -


• Learning about dataset imbalance through study material and python
documentation to figure out oversampling technique was the right one.
• Tasks were divided among the teammates so everyone had equal amount of
work.
• Daily meetings to keep a check on the progress of our project. Weekly
meetings with the mentor to get feedback on our work.

Analysis of the results:

After implementing the project using SVM techniques, we conducted


experiments on evaluating the performance of our platform. In this section, we
present the analysis results of our project.
Customer churn is important because it costs more to acquire new customers
than to sell to existing customers. This is the metric that determines the success

Dept. of Computer Science, BKBCK 26 | P a g e


Churn Rate Prediction

or failure of a business. Successful customer retention increases the customer’s


average lifetime value, making all future sales more valuable and improving unit
margins.
The way to maximize a company’s resources is often by increasing revenue
from recurring subscriptions and trusted repeat business rather than investing in
acquiring new customers. Retaining loyal customers for years makes it much
easier to grow and weather financial hardship than spending money to acquire
new customers to replace those who have left.

Conclusion:

Customer churn analysis has become a major concern in almost every industry
that offers products and services. The model developed will help banks identify
clients who are likely to be churners and develop appropriate marketing actions
to retain their valuable clients. And this model also supports information about
similar customer group to consider which marketing reactions are to be
provided.
When you have finished preparing the Churn Prediction Model, the next step is
to incorporate it into the day-to-day operations of the company. This requires
constant monitoring, evaluation, and updating of the system (which may simply
consist of re-training the system or may even involve the addition of new
features).
As a consequence of this, you can begin to automatically recognize events that
tend to increase the propensity to leave and that require a response as quickly as
possible.
In this article, you learned how to build a churn prediction model for retail data
and how to review the status and results along with how to delete and fix a failed
prediction.
However, as a Developer, extracting complex data from a diverse set of data
sources like Databases, CRMs, Project management Tools, Streaming Services,
and Marketing Platforms to your Database can seem to be quite challenging.

Future Enhancement:

Dept. of Computer Science, BKBCK 27 | P a g e


Churn Rate Prediction

Banking system is a way to maintain few records which bank holds in order to
keep a track of everything in the bank so a software application is required in
order to make the work easier, for example- maintenance of international value
of INR and other currency are also a part of the job of banking system. The bank
management is also required to act as the currency distributor and to serve the
work for the nation’s well-being. This application is built to make it easier for
the customers to track every transaction that is being made. And also to check
whether the customer will leave the bank or Not.

The main aim of application is to somewhere automate records on the system. It


gives all sorts of functions which are required by the bank in order to run a
stable system. In addition to that it also helps to manually check the records of
the pre-existing system like transactions that are made in the past. The
application also changes or manipulates the new data that is being added and is
then re-recorded. One can also check their present transactions that are in
process and keep a check on their accounts via this application. It’s not only
useful for the customers but also for the admin.

Dept. of Computer Science, BKBCK 28 | P a g e


Churn Rate Prediction

Dept. of Computer Science, BKBCK


Churn Rate Prediction

Program Code:

import {
BrowserRouter,
Routes,
Route
} from "react-router-dom"; import Navigation from './Navbar'; import Home
from './[Link]' import Create from './[Link]' import MyListedItems
from './[Link]' import MyPurchases from './[Link]'
import MarketplaceAbi from '../contractsData/[Link]' import
MarketplaceAddress from '../contractsData/[Link]'
import NFTAbi from '../contractsData/[Link]' import NFTAddress from
'../contractsData/[Link]' import { useState } from 'react'
import { ethers } from "ethers"
import { Spinner } from 'react-bootstrap'
import './[Link]';
function App() { const [loading, setLoading] =
useState(true) const [account, setAccount] =
useState(null) const [nft, setNFT] = useState({})
const [marketplace, setMarketplace] = useState({})
// MetaMask Login/Connect const web3Handler = async () =>
{ const accounts = await [Link]({
method:
'eth_requestAccounts' });
setAccount(accounts[0]) //
Get provider from Metamask
const provider = new [Link].Web3Provider([Link])
// Set signer
const signer = [Link]()
[Link]('chainChanged', (chainId) => {
[Link]();
})
[Link]('accountsChanged', async function (accounts) {
setAccount(accounts[0]) await web3Handler()
})
loadContracts(signer) }

28 | P a g e

Dept. of Computer Science, BKBCK


Churn Rate Prediction

Dept. of Computer Science, BKBCK


Churn Rate Prediction
const loadContracts = async (signer) => {
// Get deployed copies of contracts
const marketplace = new [Link]([Link],
[Link], signer) setMarketplace(marketplace) const nft = new
[Link]([Link], [Link], signer) setNFT(nft)
setLoading(false)
}
return (
<BrowserRouter>
<div className="App">
<>
<Navigation web3Handler={web3Handler} account={account} />
</>
<div>
{loading ? (
<div style={{ display: 'flex', justifyContent: 'center',
alignItems: 'center', minHeight: '80vh' }}>
<Spinner animation="border" style={{ display: 'flex' }} />
<p className='mx-3 my-0'>Awaiting Metamask Connection...</p>
</div>
) : (
<Routes>
<Route path="/" element={
<Home marketplace={marketplace} nft={nft} />
} />
<Route path="/create" element={
} />
<Route path="/my-listed-items" element={
<MyListedItems marketplace={marketplace} nft={nft}
account={account} />
} />
<Route path="/my-purchases" element={
<MyPurchases marketplace={marketplace} nft={nft}
account={account} />
} />
</Routes>
)}
</div>
</div>
</BrowserRouter>

); }
export default App;

Dept. of Computer Science, BKBCK


Churn Rate Prediction

29 | P a
ge

Dept. of Computer Science, BKBCK


Churn Rate Prediction

Dept. of Computer Science, BKBCK


Churn Rate Prediction

import { useState, useEffect } from 'react' import


{ ethers } from "ethers"
import { Row, Col, Card, Button } from 'react-bootstrap'
const Home = ({ marketplace, nft }) => { const
[loading, setLoading] = useState(true) const
[items, setItems] = useState([]) const
loadMarketplaceItems = async () => {
// Load all unsold items const itemCount =
await [Link]() let items = []
for (let i = 1; i <= itemCount; i++) { const
item = await [Link](i) if
(![Link]) {
// get uri url from nft contract const uri = await
[Link]([Link]) // use uri to fetch the nft
metadata stored on ipfs const response = await fetch(uri)
const metadata = await [Link]() // get total price of
item (item price + fee) const totalPrice = await
[Link]([Link])
// Add item to items array
[Link]({ totalPrice, itemId:
[Link], seller: [Link],
name: [Link], description:
[Link], image:
[Link]
})
} }
setLoading(false) setItems(items)
}
const buyMarketItem = async (item) => { await (await
[Link]([Link], { value:
[Link] })).wait() loadMarketplaceItems()
}
useEffect(() => {
loadMarketplaceItems()
}, [])

30 | P a g e

Dept. of Computer Science, BKBCK


Churn Rate Prediction

Dept. of Computer Science, BKBCK


Churn Rate Prediction
if (loading) return (
<main style={{ padding: "1rem 0" }}>
<h2>Loading...</h2>
</main>
) return
(
<div className="flex justify-center"> {[Link]
> 0 ?
<div className="px-5 container">
<Row xs={1} md={2} lg={4} className="g-4 py-5">
{[Link]((item, idx) => (
<Col key={idx} className="overflow-hidden">
<Card>
<[Link] variant="top" src={[Link]} />
<[Link] color="secondary">
<[Link]>{[Link]}</[Link]>
<[Link]>
{[Link]}
</[Link]>
</[Link]>
<[Link]>
<div className='d-grid'>
<Button onClick={() => buyMarketItem(item)}
variant="primary" size="lg">
Buy for {[Link]([Link])}
ETH
</Button>
</div>
</[Link]>
</Card>
</Col>
))}
</Row>
</div>
: (
<main style={{ padding: "1rem 0" }}>
<h2>No listed assets</h2>
</main>
)}
</div>
); }
export default Home

Dept. of Computer Science, BKBCK


Churn Rate Prediction

31 | P a g e

Dept. of Computer Science, BKBCK


Churn Rate Prediction

Dept. of Computer Science, BKBCK


Churn Rate Prediction

{
"_format": "hh-sol-cache-2",
"files": {
"C:\\Users\\apurv\\Downloads\\Compressed\\CHURN RATE -NFT_Marketplace-
master\\CHURN RATE -NFT_Marketplace-
master\\src\\backend\\contracts\\[Link]": {
"lastModificationDate": 1679327995250,
"contentHash": "b44c8473fb21b9b7e4a0280e192f5026",
"sourceName": "src/backend/contracts/[Link]",
"solcConfig": {
"version": "0.8.4",
"settings": {
"optimizer": {
"enabled": false,
"runs": 200
},
"outputSelection": {
"*": {
"*": [
"abi",
"[Link]",
"[Link]",
"[Link]",
"metadata"
],
"": [
"ast"
]
}
}
}
},
"imports": [
"@openzeppelin/contracts/token/ERC721/[Link]",
"@openzeppelin/contracts/security/[Link]",
"hardhat/[Link]"
],
"versionPragmas": [
"^0.8.4"
],
"artifacts": [
"Marketplace"
]

Dept. of Computer Science, BKBCK


Churn Rate Prediction
},

32 | P a
ge

Dept. of Computer Science, BKBCK


Churn Rate Prediction

Dept. of Computer Science, BKBCK


Churn Rate Prediction

"C:\\Users\\apurv\\Downloads\\Compressed\\CHURN RATE -NFT_Marketplace-


master\\CHURN RATE -NFT_Marketplace-
master\\node_modules\\@openzeppelin\\contracts\\token\\ERC721\\[Link]": {
"lastModificationDate": 1680189509501,
"contentHash": "27d219ec6f69478d065fdbfa7931da68",
"sourceName": "@openzeppelin/contracts/token/ERC721/[Link]",
"solcConfig": {
"version": "0.8.4",
"settings": {
"optimizer": {
"enabled": false,
"runs": 200
},
"outputSelection": {
"*": {
"*": [
"abi",
"[Link]",
"[Link]",
"[Link]",
"metadata"
],
"": [
"ast"
]
}
}
}
},
"imports": [
"../../utils/introspection/[Link]" ],
"versionPragmas": [ "^0.8.0"
],
"artifacts": [ "IERC721"
]
},
"C:\\Users\\apurv\\Downloads\\Compressed\\CHURN RATE -NFT_Marketplace-
master\\CHURN RATE -NFT_Marketplace-
master\\node_modules\\@openzeppelin\\contracts\\security\\[Link]"
: {
"lastModificationDate": 1680189512316,
"contentHash": "92f9448b23a90ea3bb932ee55cc3ccce",
"sourceName": "@openzeppelin/contracts/security/[Link]",
"solcConfig": {
"version": "0.8.4",

Dept. of Computer Science, BKBCK

43 | P a g e
Churn Rate Prediction

Dept. of Computer Science, BKBCK

44 | P a g e
Churn Rate Prediction

Dept. of Computer Science, BKBCK

45 | P a g e
Churn Rate Prediction

"settings": {
"optimizer": {
"enabled": false,
"runs": 200
},
"outputSelection": {
"*": {
"*": [
"abi",
"[Link]",
"[Link]",
"[Link]",
"metadata"
],
"": [
"ast"
]
}
}
}
},
"imports": [],
"versionPragmas": [
"^0.8.0"
],
"artifacts": [
"ReentrancyGuard"
]
},
"C:\\Users\\apurv\\Downloads\\Compressed\\CHURN RATE -NFT_Marketplace-
master\\CHURN RATE -NFT_Marketplace-
master\\node_modules\\hardhat\\[Link]":
{
"lastModificationDate": 1680189521253,
"contentHash": "cc4777addd464ea56fa35b1c45df0591",
"sourceName": "hardhat/[Link]",
"solcConfig": {
"version": "0.8.4",
"settings": {
"optimizer": {
"enabled": false,
"runs": 200
},
"outputSelection": {
"*": {
"*": [
"abi",

Dept. of Computer Science, BKBCK

46 | P a g e
Churn Rate Prediction

"[Link]",
"[Link]",

Dept. of Computer Science, BKBCK

47 | P a g e
Churn Rate Prediction

Dept. of Computer Science, BKBCK

48 | P a g e
Churn Rate Prediction

"[Link]",
"metadata"
],
"": [
"ast"
]
}
}
}
},
"imports": [],
"versionPragmas": [
">=0.4.22 <0.9.0"
],
"artifacts": [
"console"
]
},
"C:\\Users\\apurv\\Downloads\\Compressed\\CHURN RATE -NFT_Marketplace-
master\\CHURN RATE -NFT_Marketplace-
master\\node_modules\\@openzeppelin\\contracts\\utils\\introspection\\IERC165.
sol": {
"lastModificationDate": 1680189506923,
"contentHash": "03e6768535ac4da0e9756f1d8a4a018a",
"sourceName": "@openzeppelin/contracts/utils/introspection/[Link]",
"solcConfig": {
"version": "0.8.4",
"settings": {
"optimizer": {
"enabled": false,
"runs": 200
},
"outputSelection": {
"*": {
"*": [
"abi",
"[Link]",
"[Link]",
"[Link]",
"metadata"
],
"": [
"ast"
]
}
}
}

Dept. of Computer Science, BKBCK

49 | P a g e
Churn Rate Prediction

},

Dept. of Computer Science, BKBCK

50 | P a g e
Churn Rate Prediction

Dept. of Computer Science, BKBCK

51 | P a g e
Churn Rate Prediction

"imports": [],
"versionPragmas": [
"^0.8.0"
],
"artifacts": [
"IERC165"
]
},
"C:\\Users\\apurv\\Downloads\\Compressed\\CHURN RATE -NFT_Marketplace-
master\\CHURN RATE -NFT_Marketplace-
master\\node_modules\\@openzeppelin\\contracts\\token\\ERC721\\extensions\\IER
[Link]": {
"lastModificationDate": 1680189509889,
"contentHash": "efbc0d15b80a74e34dbe8da0f3e879bb",
"sourceName":
"@openzeppelin/contracts/token/ERC721/extensions/[Link]",
"solcConfig": {
"version": "0.8.4",
"settings": {
"optimizer": {
"enabled": false,
"runs": 200
},
"outputSelection": {
"*": {
"*": [
"abi",
"[Link]",
"[Link]",
"[Link]",
"metadata"
],
"": [
"ast"
]
}
}
}
},
"imports": [
"../[Link]"
],
"versionPragmas": [
"^0.8.0"
],
"artifacts": [

Dept. of Computer Science, BKBCK

52 | P a g e
Churn Rate Prediction

"IERC721Metadata"
]

Dept. of Computer Science, BKBCK

53 | P a g e
Churn Rate Prediction

},
"C:\\Users\\apurv\\Downloads\\Compressed\\CHURN RATE -NFT_Marketplace-
master\\CHURN RATE -NFT_Marketplace-
master\\node_modules\\@openzeppelin\\contracts\\token\\ERC721\\[Link]": {
"lastModificationDate": 1680189504831,
"contentHash": "49295810dc45f300e5f84b4b50d88a59",
"sourceName": "@openzeppelin/contracts/token/ERC721/[Link]",
"solcConfig": {
"version": "0.8.4",
"settings": {
"optimizer": {
"enabled": false,
"runs": 200
},
"outputSelection": {
"*": {
"*": [
"abi",
"[Link]",
"[Link]",
"[Link]",
"metadata"
],
"": [
"ast"
]
}
}
}
},
"imports": [
"./[Link]",
"./[Link]",
"./extensions/[Link]",
"../../utils/[Link]",
"../../utils/[Link]", "../../utils/[Link]",
"../../utils/introspection/[Link]"
],
"versionPragmas": [ "^0.8.0"
],
"artifacts": [ "ERC721"
]
},
"C:\\Users\\apurv\\Downloads\\Compressed\\CHURN RATE -NFT_Marketplace-
master\\CHURN RATE -NFT_Marketplace-

Dept. of Computer Science, BKBCK

54 | P a g e
Churn Rate Prediction

Dept. of Computer Science, BKBCK

55 | P a g e
Churn Rate Prediction

master\\node_modules\\@openzeppelin\\contracts\\token\\ERC721\\IERC721Receiver
.sol": {
"lastModificationDate": 1680189509924,
"contentHash": "592df588492d45fdcf46b3cb608c0fbf",
"sourceName":
"@openzeppelin/contracts/token/ERC721/[Link]",
"solcConfig": {
"version": "0.8.4",
"settings": {
"optimizer": {
"enabled": false,
"runs": 200
},
"outputSelection": {
"*": {
"*": [
"abi",
"[Link]",
"[Link]",
"[Link]",
"metadata"
],
"": [
"ast"
]
}
}
}
},
"imports": [],
"versionPragmas": [
"^0.8.0"
],
"artifacts": [
"IERC721Receiver"
]
},
"C:\\Users\\apurv\\Downloads\\Compressed\\CHURN RATE -NFT_Marketplace-
master\\CHURN RATE -NFT_Marketplace-
master\\node_modules\\@openzeppelin\\contracts\\utils\\[Link]": {
"lastModificationDate": 1680189498838,
"contentHash": "ad714a6368ee7d43cded6bbe8af0b155",
"sourceName": "@openzeppelin/contracts/utils/[Link]",
"solcConfig": {
"version": "0.8.4",
"settings": {
"optimizer": {

Dept. of Computer Science, BKBCK

56 | P a g e
Churn Rate Prediction

"enabled": false,

Dept. of Computer Science, BKBCK

57 | P a g e
Churn Rate Prediction

Dept. of Computer Science, BKBCK

58 | P a g e
Churn Rate Prediction

Dept. of Computer Science, BKBCK

59 | P a g e
Churn Rate Prediction

"runs": 200
},
"outputSelection": {
"*": {
"*": [
"abi",
"[Link]",
"[Link]",
"[Link]",
"metadata"
],
"": [
"ast"
]
}
}
}
},
"imports": [],
"versionPragmas": [
"^0.8.1"
],
"artifacts": [
"Address"
]
},
"C:\\Users\\apurv\\Downloads\\Compressed\\CHURN RATE -NFT_Marketplace-
master\\CHURN RATE -NFT_Marketplace-
master\\node_modules\\@openzeppelin\\contracts\\utils\\[Link]": {
"lastModificationDate": 1680189499156,
"contentHash": "5f2c5c4b6af2dd4551027144797bc8be",
"sourceName": "@openzeppelin/contracts/utils/[Link]",
"solcConfig": {
"version": "0.8.4",
"settings": {
"optimizer": {
"enabled": false,
"runs": 200
},
"outputSelection": {
"*": {
"*": [
"abi",
"[Link]",
"[Link]",
"[Link]",
"metadata"

Dept. of Computer Science, BKBCK

60 | P a g e
Churn Rate Prediction

],

Dept. of Computer Science, BKBCK

61 | P a g e
Churn Rate Prediction

Dept. of Computer Science, BKBCK

62 | P a g e
Churn Rate Prediction

"": [
"ast"
]
}
}
}
},
"imports": [],
"versionPragmas": [
"^0.8.0"
],
"artifacts": [
"Context"
]
},
"C:\\Users\\apurv\\Downloads\\Compressed\\CHURN RATE -NFT_Marketplace-
master\\CHURN RATE -NFT_Marketplace-
master\\node_modules\\@openzeppelin\\contracts\\utils\\[Link]": {
"lastModificationDate": 1680189512519,
"contentHash": "9c54c6c065d9e590fdcdd72c451425b9",
"sourceName": "@openzeppelin/contracts/utils/[Link]",
"solcConfig": {
"version": "0.8.4",
"settings": {
"optimizer": {
"enabled": false,
"runs": 200
},
"outputSelection": {
"*": {
"*": [
"abi",
"[Link]",
"[Link]",
"[Link]",
"metadata"
],
"": [
"ast"
]
}
}
}
},
"imports": [],
"versionPragmas":
[ "^0.8.0" ],

Dept. of Computer Science, BKBCK

63 | P a g e
Churn Rate Prediction

Dept. of Computer Science, BKBCK

64 | P a g e
Churn Rate Prediction

"artifacts": [
"Strings"
]
},
"C:\\Users\\apurv\\Downloads\\Compressed\\CHURN RATE -NFT_Marketplace-
master\\CHURN RATE -NFT_Marketplace-
master\\node_modules\\@openzeppelin\\contracts\\utils\\introspection\\ERC165.s
ol": {
"lastModificationDate": 1680189499902,
"contentHash": "0e7db055ce108f9da7bb6686a00287c0",
"sourceName": "@openzeppelin/contracts/utils/introspection/[Link]",
"solcConfig": {
"version": "0.8.4",
"settings": {
"optimizer": {
"enabled": false,
"runs": 200
},
"outputSelection": {
"*": {
"*": [
"abi",
"[Link]",
"[Link]",
"[Link]",
"metadata"
],
"": [
"ast"
]
}
}
}
},
"imports": [
"./[Link]"
],
"versionPragmas": [
"^0.8.0"
],
"artifacts": [
"ERC165"
]
},
"C:\\Users\\apurv\\Downloads\\Compressed\\CHURN RATE -NFT_Marketplace-
master\\CHURN RATE -NFT_Marketplace-

Dept. of Computer Science, BKBCK

65 | P a g e
Churn Rate Prediction

master\\node_modules\\@openzeppelin\\contracts\\token\\ERC721\\extensions\\ERC
[Link]": {

Dept. of Computer Science, BKBCK

66 | P a g e
Churn Rate Prediction

Dept. of Computer Science, BKBCK

67 | P a g e
Churn Rate Prediction

"lastModificationDate": 1680189505062,
"contentHash": "580a443491d9d70eb064b0130fc3cd01",
"sourceName":
"@openzeppelin/contracts/token/ERC721/extensions/[Link]",
"solcConfig": {
"version": "0.8.4",
"settings": {
"optimizer": {
"enabled": false,
"runs": 200
},
"outputSelection": {
"*": {
"*": [
"abi",
"[Link]",
"[Link]",
"[Link]",
"metadata"
],
"": [
"ast"
]
}
}
}
},
"imports": [
"../[Link]"
],
"versionPragmas": [
"^0.8.0"
],
"artifacts": [
"ERC721URIStorage"
]
},
"C:\\Users\\apurv\\Downloads\\Compressed\\CHURN RATE -NFT_Marketplace-
master\\CHURN RATE -NFT_Marketplace-
master\\src\\backend\\contracts\\[Link]": {
"lastModificationDate": 1679327995250,
"solcConfig": {
"version": "0.8.4",
"settings": {
"optimizer": {
"enabled": false,
"runs": 200

Dept. of Computer Science, BKBCK

68 | P a g e
Churn Rate Prediction

},
"outputSelection": {

Dept. of Computer Science, BKBCK

69 | P a g e
Churn Rate Prediction

Dept. of Computer Science, BKBCK

70 | P a g e
Churn Rate Prediction

Dept. of Computer Science, BKBCK


Churn Rate Prediction
"*": {
"*": [
"abi",
"[Link]",
"[Link]",
"[Link]",
"metadata"
],
"": [
"ast"
]
}
}
}
},
"imports": [
"@openzeppelin/contracts/token/ERC721/extensions/[Link]"
],
"versionPragmas": [
"^0.8.4"
],
"artifacts": [ "NFT"
]
}
}
}

async function main() { const [deployer] =


await [Link]();

[Link]("Deploying contracts with the account:", [Link]);


[Link]("Account balance:", (await [Link]()).toString());

Dept. of Computer Science, BKBCK


Churn Rate Prediction

// Get the ContractFactories and Signers here.


const NFT = await [Link]("NFT"); const
Marketplace = await [Link]("Marketplace");
// deploy contracts
const marketplace = await [Link](1);

43 | P a g e

Dept. of Computer Science, BKBCK


Churn Rate Prediction

Dept. of Computer Science, BKBCK


Churn Rate Prediction
const nft = await [Link]();
// Save copies of each contracts abi and address to the frontend.
saveFrontendFiles(marketplace , "Marketplace");
saveFrontendFiles(nft , "NFT");
}

function saveFrontendFiles(contract, name) { const


fs = require("fs");
const contractsDir = dirname + "/../../frontend/contractsData";

if (![Link](contractsDir)) {
[Link](contractsDir);
}

[Link]( contractsDir +
`/${name}-[Link]`,
[Link]({ address: [Link] }, undefined, 2)
); const contractArtifact =

[Link](name);

[Link]( contractsDir +
`/${name}.json`,
[Link](contractArtifact, null, 2)
);
}

main()
.then(() => [Link](0))
.catch(error => {
[Link](error);
[Link](1);
});

const { expect } = require("chai");

const toWei = (num) => [Link]([Link]())


const fromWei = (num) => [Link](num)

describe("NFTMarketplace", function () {

let NFT; let


nft; let
Marketplace;
let marketplace

Dept. of Computer Science, BKBCK


Churn Rate Prediction
let deployer;
let addr1; let
addr2;

44 | P a g e

Dept. of Computer Science, BKBCK


Churn Rate Prediction

Dept. of Computer Science, BKBCK


Churn Rate Prediction

let addrs; let


feePercent = 1; let
URI = "sample URI"
beforeEach(async function () {
// Get the ContractFactories and Signers here.
NFT = await [Link]("NFT");
Marketplace = await [Link]("Marketplace");
[deployer, addr1, addr2, ...addrs] = await [Link]();

// To deploy our contracts nft = await [Link]();


marketplace = await [Link](feePercent);
});
describe("Deployment", function () {
it("Should track name and symbol of the nft collection", async function ()
{
// This test expects the owner variable stored in the contract to be
equal
// to our Signer's owner. const nftName = "DApp
NFT" const nftSymbol = "DAPP" expect(await
[Link]()).[Link](nftName); expect(await
[Link]()).[Link](nftSymbol);
});
it("Should track feeAccount and feePercent of the marketplace", async
function () { expect(await
[Link]()).[Link]([Link]); expect(await
[Link]()).[Link](feePercent);
});
});
describe("Minting NFTs", function () {
it("Should track each minted NFT", async function () {
// addr1 mints an nft
await [Link](addr1).mint(URI) expect(await
[Link]()).[Link](1); expect(await
[Link]([Link])).[Link](1); expect(await
[Link](1)).[Link](URI);
// addr2 mints an nft await [Link](addr2).mint(URI)
expect(await [Link]()).[Link](2);
expect(await [Link]([Link])).[Link](1);
expect(await [Link](2)).[Link](URI);

45 | P a g e

Dept. of Computer Science, BKBCK


Churn Rate Prediction

Dept. of Computer Science, BKBCK


Churn Rate Prediction

});
})
describe("Making marketplace items", function () {
let price = 1 let result beforeEach(async
function () { // addr1 mints an nft await
[Link](addr1).mint(URI)
// addr1 approves marketplace to spend nft await
[Link](addr1).setApprovalForAll([Link], true)
})

it("Should track newly created item, transfer NFT from seller to


marketplace and emit Offered event", async function () { // addr1
offers their nft at a price of 1 ether await
expect([Link](addr1).makeItem([Link], 1 ,
toWei(price)))
.[Link](marketplace, "Offered")
.withArgs( 1,
[Link],
1,
toWei(price),
[Link]
)
// Owner of NFT should now be the marketplace expect(await
[Link](1)).[Link]([Link]);
// Item count should now equal 1 expect(await
[Link]()).[Link](1)
// Get item from items mapping then check fields to ensure they
are correct const item = await [Link](1)
expect([Link]).[Link](1) expect([Link]).[Link]([Link])
expect([Link]).[Link](1)
expect([Link]).[Link](toWei(price))
expect([Link]).[Link](false)
});
it("Should fail if price is set to zero", async function () { await
expect( [Link](addr1).makeItem([Link], 1,
0)
).[Link]("Price must be greater than zero");
});

});
describe("Purchasing marketplace items", function () {

46 | P a g e

Dept. of Computer Science, BKBCK


Churn Rate Prediction

Dept. of Computer Science, BKBCK


Churn Rate Prediction

let price = 2 let fee =


(feePercent/100)*price let
totalPriceInWei beforeEach(async
function () { // addr1 mints an nft
await [Link](addr1).mint(URI)
// addr1 approves marketplace to spend tokens await
[Link](addr1).setApprovalForAll([Link], true) //
addr1 makes their nft a marketplace item.
await [Link](addr1).makeItem([Link], 1 , toWei(price))
}) it("Should update item as sold, pay seller, transfer NFT to buyer,
charge
fees and emit a Bought event", async function () { const
sellerInitalEthBal = await [Link]()
const feeAccountInitialEthBal = await [Link]()
// fetch items total price (market fees + item price)
totalPriceInWei = await [Link](1); //
addr 2 purchases item.
await expect([Link](addr2).purchaseItem(1, {value:
totalPriceInWei}))
.[Link](marketplace, "Bought")
.withArgs(
1,
[Link],
1,
toWei(price),
[Link],
[Link]
) const sellerFinalEthBal = await [Link]()
const feeAccountFinalEthBal = await
[Link]()
// Item should be marked as sold
expect((await [Link](1)).sold).[Link](true) //
Seller should receive payment for the price of the NFT sold.
expect(+fromWei(sellerFinalEthBal)).[Link](+price +
+fromWei(sellerInitalEthBal))
// feeAccount should receive fee
expect(+fromWei(feeAccountFinalEthBal)).[Link](+fee +
+fromWei(feeAccountInitialEthBal)) // The buyer should now
own the nft expect(await
[Link](1)).[Link]([Link]);
})
it("Should fail for invalid item ids, sold items and when not enough ether
is paid", async function () { // fails for invalid item ids await expect(
[Link](addr2).purchaseItem(2, {value: totalPriceInWei})
).[Link]("item doesn't exist");

Dept. of Computer Science, BKBCK


Churn Rate Prediction

47 | P a g e

Dept. of Computer Science, BKBCK


Churn Rate Prediction

Dept. of Computer Science, BKBCK


Churn Rate Prediction
await expect( [Link](addr2).purchaseItem(0, {value:
totalPriceInWei})
).[Link]("item doesn't exist");
// Fails when not enough ether is paid with the transaction.
// In this instance, fails when buyer only sends enough ether to cover
the price of the nft
// not the additional market fee.
await expect( [Link](addr2).purchaseItem(1, {value:
toWei(price)})
).[Link]("not enough ether to cover item price and market
fee");
// addr2 purchases item 1 await
[Link](addr2).purchaseItem(1, {value:
totalPriceInWei})
// addr3 tries purchasing item 1 after its been sold const addr3 =
addrs[0] await expect( [Link](addr3).purchaseItem(1,
{value: totalPriceInWei}) ).[Link]("item already sold"); });
})
})

Dept. of Computer Science, BKBCK


Churn Rate Prediction

48 | P a g e

Dept. of Computer Science, BKBCK


Churn Rate Prediction

Dept. of Computer Science, BKBCK


Churn Rate Prediction

Bibliography:

1. [Link]/en/whitepaper/
2. [Link]/wallet/learn-web3
3. [Link]/top-10-nft-marketplaces-updatedversion-2022-2023-
357c2e1d3bde
4. [Link]/
5. [Link]/guide/
6. [Link]/22310188/nft-explainer-what-is-blockchain-cryptoart-faq
7. [Link]/en/nft/
8. [Link]
9. Openzeppline Documentation
10. Hardhat Docs IPFS
11. The Blockchain Developer by Elad Elrom
12. The NFT Handbook by Matt Fortnow and QuHarrison Terry
13. Mastering Blockchain by Imran Bashir
14. Non-Fungible Token (NFT) by Qin Wang, Rujia Li, Qi Wang, Shiping Chen
15. NFTs in Practice by Ferdinand Regner, André Schweizer, Nils Urbach

Dept. of Computer Science, BKBCK


Churn Rate Prediction

49 | P a
ge

Dept. of Computer Science, BKBCK


Churn Rate Prediction

Dept. of Computer Science, BKBCK

You might also like