Skip to content
geeksforgeeks
  • Courses
    • DSA to Development
    • Get IBM Certification
    • Newly Launched!
      • Master Django Framework
      • Become AWS Certified
    • For Working Professionals
      • Interview 101: DSA & System Design
      • Data Science Training Program
      • JAVA Backend Development (Live)
      • DevOps Engineering (LIVE)
      • Data Structures & Algorithms in Python
    • For Students
      • Placement Preparation Course
      • Data Science (Live)
      • Data Structure & Algorithm-Self Paced (C++/JAVA)
      • Master Competitive Programming (Live)
      • Full Stack Development with React & Node JS (Live)
    • Full Stack Development
    • Data Science Program
    • All Courses
  • Tutorials
    • Data Structures & Algorithms
    • ML & Data Science
    • Interview Corner
    • Programming Languages
    • Web Development
    • CS Subjects
    • DevOps And Linux
    • School Learning
  • Practice
    • Build your AI Agent
    • GfG 160
    • Problem of the Day
    • Practice Coding Problems
    • GfG SDE Sheet
  • Contests
    • Accenture Hackathon (Ending Soon!)
    • GfG Weekly [Rated Contest]
    • Job-A-Thon Hiring Challenge
    • All Contests and Events
  • NextJS
  • Material UI
  • React Bootstrap
  • React Suite
  • Ant Design
  • Reactstrap
  • BlueprintJS
  • React Desktop
  • React Native
  • React Rebass
  • React Spring
  • React Evergreen
  • ReactJS
  • ReactJS
  • JS Formatter
  • Web Technology
Open In App
Next Article:
Create a Stock Market Prediction App using React-Native
Next article icon

Create a Crypto Prediction App using React Native

Last Updated : 24 Jul, 2024
Comments
Improve
Suggest changes
Like Article
Like
Report

Crypto Prediction App using React Native allows users to fetch real-time cryptocurrency prices and predict future price movements based on historical data. Users can enter the symbol of the cryptocurrency they're interested in, fetch its current price, and make predictions using simple logic.

Output Preview: Let us have a look at how the final output will look like.

Screenshot-2024-02-14-110648

Prerequisites

  • React Native
  • Axios (for making HTTP requests)
  • CoinMarketCap API (for fetching cryptocurrency data)

Approach to create Crypto Prediction App:

  • Set up development environment and obtain API keys.
  • Design user interface.
  • Allow users to input cryptocurrency symbols.
  • Fetch real-time market data from CoinMarketCap API.
  • Implement basic prediction logic.
  • Display data and predictions in UI.

Steps to Create React Native Application:

Step 1: Set up a new React Native project.

npx react-native init cryptopredict
cd cryptopredict

Step 2: Install Axios for making HTTP requests.

npm install Axios

Step 3: Register for a free account on CoinMarketCap API to get an API key.

Project Structure:

Screenshot-2024-02-14-111624

The updated dependencies in package.json file will look like:

"dependencies": {
"axios": "^1.6.7",
"react": "18.2.0",
"react-native": "0.73.4"
}

Example: Below is the code example of the Crypto Prediction App using React-Native

JavaScript
import React from 'react'; import { 	StyleSheet, 	View } from 'react-native'; import CryptoPredictionComponent 	from './CryptoPredictionComponent';  export default function App() { 	return ( 		<View style={styles.container}> 			<CryptoPredictionComponent /> 		</View> 	); }  const styles = StyleSheet.create({ 	container: { 		flex: 1, 		// Main background color 		backgroundColor: '#d5def5', 		alignItems: 'center', 		justifyContent: 'center', 	}, }); 
JavaScript
import React, { 	useState, 	useEffect } from 'react'; import { 	View, Text, 	StyleSheet, 	TextInput, 	Button } from 'react-native'; import axios from 'axios';  const CryptoPredictionComponent = () => { 	const [selectedCrypto, setSelectedCrypto] = useState(''); 	const [cryptoPrice, setCryptoPrice] = useState(''); 	const [prediction, setPrediction] = useState('');  	const fetchCryptoPrice = async () => { 		try { 			// Replace 'YOUR_API_KEY' with your actual API key 			const apiKey = 'Your-API-KEY'; 			const response = 				await axios.get( `https://pro-api.coinmarketcap.com/v1/cryptocurrency/quotes/latest?symbol=${selectedCrypto.toUpperCase()}`,  				{ 					headers: { 						'X-CMC_PRO_API_KEY': apiKey, 						'Accept': 'application/json' 					} 				}); 			setCryptoPrice( 				response.data 					.data[ 					selectedCrypto.toUpperCase() 				].quote.USD.price 			); 		} catch (error) { 			console.error( 				`Error fetching  				${selectedCrypto} price:`, error 			); 		} 	};  	const handlePredict = async () => { 		try { 			// Replace 'YOUR_API_KEY' with your actual API key 			const apiKey = '3f146e06-8a7b-4ab3-92d6-299b04526dc2'; 			const response = 				await axios.get( `https://pro-api.coinmarketcap.com/v1/cryptocurrency/quotes/latest?symbol=${selectedCrypto.toUpperCase()}`, 					{ 						headers: { 							'X-CMC_PRO_API_KEY': apiKey, 							'Accept': 'application/json' 						} 					});  			const change = 				response.data 					.data[ 					selectedCrypto.toUpperCase() 				].quote.USD.volume_change_24h;  			if (change > 8) { 				setPrediction('Positive: Price is expected to increase'); 			} else if (change < -0.5) { 				setPrediction('Negative: Price is expected to decrease'); 			} else { 				setPrediction('Neutral: Price is expected to stay the same'); 			} 		} catch (error) { 			console.error(`Error predicting ${selectedCrypto} price:`, error); 		} 	};  	return ( 		<View style={styles.container}> 			<Text style={styles.title}> 				Crypto Prediction 			</Text> 			<View style={styles.content}> 				<TextInput 					style={styles.input} 					placeholder="Enter Cryptocurrency Symbol (e.g., BTC)" 					value={selectedCrypto} 					onChangeText={text => setSelectedCrypto(text)} /> 				<Text style={styles.price}> 					Current Price: 					{ 						cryptoPrice ? 							`$${cryptoPrice}` : 'Loading...' 					} 				</Text> 				<Button title="Fetch Price" 					onPress={fetchCryptoPrice} /> 				<View style={styles.buttonSpacing} /> 				<View style={styles.buttonSpacing} /> 				<Button title="Predict" 					onPress={handlePredict} /> 				{ 					prediction && <Text style={styles.prediction}> 						Prediction: 						<View style={styles.buttonSpacing} /> 						{prediction} 					</Text> 				} 			</View> 		</View> 	); };  const styles = StyleSheet.create({ 	container: { 		flex: 1, 		// Main background color 		backgroundColor: '#d5def5', 		alignItems: 'center', 		justifyContent: 'center', 	}, 	title: { 		fontSize: 24, 		fontWeight: 'bold', 		marginBottom: 20, 		// Title text color 		color: '#430f58', 	}, 	content: { 		alignItems: 'center', 	}, 	input: { 		height: 40, 		width: 200, 		// Input border color 		borderColor: '#8594e4', 		borderWidth: 1, 		marginBottom: 20, 		paddingHorizontal: 10, 	}, 	price: { 		marginBottom: 20, 		// Price text color 		color: '#6643b5', 	}, buttonSpacing: { 		// Adjust the height for the desired spacing 		height: 10, 	}, 	prediction: { 		marginTop: 20, 		fontSize: 18, 		fontWeight: 'bold', 		// Prediction text color 		color: '#8594e4', 	}, });  export default CryptoPredictionComponent; 

Steps to run the application:

react-native run-android or react-native run-ios.

Output:


Next Article
Create a Stock Market Prediction App using React-Native

D

dhruvitriutzm
Improve
Article Tags :
  • Project
  • Web Technologies
  • ReactJS
  • Dev Scripter
  • React-Native
  • Dev Scripter 2024

Similar Reads

  • Create a Stock Market Prediction App using React-Native
    We'll walk through the process of building a Stock Market Prediction App using React Native. The app will allow users to input a stock symbol, fetch real-time stock data, and even predict the price for the next trading day. Let's dive into the details! Preview of final output: Let us have a look at
    4 min read
  • Create a Portfolio App using React-Native
    In this article, we are going to Create a portfolio app using React Native. The portfolio app is a simple application that is a collection of a person's qualifications, achievements, work samples, and other relevant materials. It is used to demonstrate one's abilities and suitability for a particula
    5 min read
  • Create a Text Narrator App using React-Native
    In this project, we'll develop a Text Narrator application using React Native. The Text Narrator app is a valuable tool for improving accessibility. It allows users to input text, and the app will convert that text into audible speech. This can be incredibly helpful for individuals with visual impai
    2 min read
  • Create a Text Editor App using React-Native
    In this article, we are going to implement a text editor app using React Native. It will contain multiple text formatting functionalities like bold, italic, underline, etc. We will implement Editor with a library called "react-native-pell-rich-editor." Preview of final output: Let us have a look at
    3 min read
  • Create a Food Reciepe App using React-Native
    In this React-Native article, we will be developing an interactive Food Recipe Application. In this application, the users can be able to search for any food recipe in the search box. Then, according to the search query, the results will be fetched through an API and will be displayed in the applica
    5 min read
  • Create a News Reader app using React-Native
    Creating the News Reader application using React-Native language is an exciting project. Using this project, the users can read the news in the application itself, by filtering them according to the categories as per their interest. In this article, we will develop the complete News Reader applicati
    5 min read
  • Create a Location Sharing App using React-Native
    In this article, we are going to build a step-by-step Location Sharing App using React-Native. A Location Sharing App developed with React-Native allows users to share their real-time location with others. It leverages React-Native's cross-platform capabilities to create a mobile application that fa
    4 min read
  • Create a Camera App using React-Native
    A camera app using react native is a mobile application that is designed to capture photos or videos using the built-in camera functionality of a mobile device. In this article, you will learn how you can create a camera app with simple steps. Output Preview: Let us have a look at how the final appl
    3 min read
  • Create a Chatbot App using React-Native
    Creating a chatbot app using React Native will be an exciting project. In this article, we are going to implement a Chatbot App using React Native. Chatbot App is a mobile application that answers the user's questions on the basis of their previous learning or content provided by developers. It help
    4 min read
  • How to Create ToDo App using React Native ?
    In this article, we'll see how to create a ToDo app using React Native. An ideal illustration of a basic application that can be developed with React Native is a ToDo app. This app enables users to generate, modify, and remove tasks, assisting them in maintaining organization and concentration. Reac
    4 min read
geeksforgeeks-footer-logo
Corporate & Communications Address:
A-143, 7th Floor, Sovereign Corporate Tower, Sector- 136, Noida, Uttar Pradesh (201305)
Registered Address:
K 061, Tower K, Gulshan Vivante Apartment, Sector 137, Noida, Gautam Buddh Nagar, Uttar Pradesh, 201305
GFG App on Play Store GFG App on App Store
Advertise with us
  • Company
  • About Us
  • Legal
  • Privacy Policy
  • In Media
  • Contact Us
  • Advertise with us
  • GFG Corporate Solution
  • Placement Training Program
  • Languages
  • Python
  • Java
  • C++
  • PHP
  • GoLang
  • SQL
  • R Language
  • Android Tutorial
  • Tutorials Archive
  • DSA
  • Data Structures
  • Algorithms
  • DSA for Beginners
  • Basic DSA Problems
  • DSA Roadmap
  • Top 100 DSA Interview Problems
  • DSA Roadmap by Sandeep Jain
  • All Cheat Sheets
  • Data Science & ML
  • Data Science With Python
  • Data Science For Beginner
  • Machine Learning
  • ML Maths
  • Data Visualisation
  • Pandas
  • NumPy
  • NLP
  • Deep Learning
  • Web Technologies
  • HTML
  • CSS
  • JavaScript
  • TypeScript
  • ReactJS
  • NextJS
  • Bootstrap
  • Web Design
  • Python Tutorial
  • Python Programming Examples
  • Python Projects
  • Python Tkinter
  • Python Web Scraping
  • OpenCV Tutorial
  • Python Interview Question
  • Django
  • Computer Science
  • Operating Systems
  • Computer Network
  • Database Management System
  • Software Engineering
  • Digital Logic Design
  • Engineering Maths
  • Software Development
  • Software Testing
  • DevOps
  • Git
  • Linux
  • AWS
  • Docker
  • Kubernetes
  • Azure
  • GCP
  • DevOps Roadmap
  • System Design
  • High Level Design
  • Low Level Design
  • UML Diagrams
  • Interview Guide
  • Design Patterns
  • OOAD
  • System Design Bootcamp
  • Interview Questions
  • Inteview Preparation
  • Competitive Programming
  • Top DS or Algo for CP
  • Company-Wise Recruitment Process
  • Company-Wise Preparation
  • Aptitude Preparation
  • Puzzles
  • School Subjects
  • Mathematics
  • Physics
  • Chemistry
  • Biology
  • Social Science
  • English Grammar
  • Commerce
  • World GK
  • GeeksforGeeks Videos
  • DSA
  • Python
  • Java
  • C++
  • Web Development
  • Data Science
  • CS Subjects
@GeeksforGeeks, Sanchhaya Education Private Limited, All rights reserved
We use cookies to ensure you have the best browsing experience on our website. By using our site, you acknowledge that you have read and understood our Cookie Policy & Privacy Policy
Lightbox
Improvement
Suggest Changes
Help us improve. Share your suggestions to enhance the article. Contribute your expertise and make a difference in the GeeksforGeeks portal.
geeksforgeeks-suggest-icon
Create Improvement
Enhance the article with your expertise. Contribute to the GeeksforGeeks community and help create better learning resources for all.
geeksforgeeks-improvement-icon
Suggest Changes
min 4 words, max Words Limit:1000

Thank You!

Your suggestions are valuable to us.

What kind of Experience do you want to share?

Interview Experiences
Admission Experiences
Career Journeys
Work Experiences
Campus Experiences
Competitive Exam Experiences