GithubHelp home page GithubHelp logo

rakesh9494 / tokenswapping Goto Github PK

View Code? Open in Web Editor NEW
0.0 1.0 0.0 75.05 MB

This goal of this project is to allow users to deposit ETH and receive 50% of its value in nUSD. Additionally, there will be a redeem function to convert nUSD back into either ETH.

Home Page: https://tokenswappingethtonused.netlify.app/

Solidity 16.59% JavaScript 42.07% HTML 18.14% CSS 23.20%

tokenswapping's Introduction

Overview

Smart contract

Solidity Version and Imports:

The contract specifies that it requires Solidity version 0.8.0 and imports the AggregatorV3Interface from the Chainlink contracts library.

Contract Structure:

The contract is named "TokenSwap" and includes several state variables and mappings:

ethToNusdRate:

A uint variable representing the conversion rate from ETH to a fictional token called nUSD.

nusdToEthRate:

A uint variable representing the conversion rate from nUSD to ETH.

totalSupply:

A uint variable representing the total supply of nUSD tokens.

balances:

A mapping that stores the balances of nUSD tokens for each address.

AggregatorV3Interface:

The contract includes an internal instance of the AggregatorV3Interface from the Chainlink library. It is used to obtain the ETH/USD price feed.

Events:

The contract defines two events:

Deposit:

Triggered when a user makes a deposit, indicating the amount of ETH and nUSD tokens received.

Redeem:

Triggered when a user redeems nUSD tokens for ETH, indicating the amount of nUSD tokens redeemed and the corresponding ETH amount received.

Constructor:

The constructor sets the initial values for the contract, including the owner, conversion rates, total supply, and the address of the Chainlink ETH/USD price feed contract.

Deposit Function:

The deposit function allows users to deposit ETH and receive nUSD tokens based on the current ETH/USD exchange rate. The ETH amount is converted to nUSD based on the ethToNusdRate, and the user's balance and the total supply are updated accordingly. The function emits a Deposit event.

Redeem Function:

The redeem function allows users to redeem a specified amount of nUSD tokens for ETH. The nUSD amount is converted to ETH based on the nusdToEthRate, and the user's balance and the total supply are updated accordingly. The function emits a Redeem event.

getETHUSDPrice Function:

The getETHUSDPrice function retrieves the latest ETH/USD price from the Chainlink price feed contract.

getBalance Function:

The getBalance function returns the nUSD token balance of a given address.

getTotalSupply Function:

The getTotalSupply function returns the total supply of nUSD tokens

Frontend

I have used ReactJS for the frontend.There is two one text field and two buttons.

Deposite

This button is used to depositing the ETH.

Reedem

This button is used to Reedem the nUSD from the balance

Testnet

I have Sepolia testnet for this project.

How to Run the project

Note : Make sure that you have NodeJS envinornment and Sepolia testnet.

1. Get Test Sepolia eth

Here you can get test Sepolia eth : https://sepoliafaucet.com/

2.Run Project

Run the command "npm start" in project directory.

tokenswapping's People

Contributors

rakesh9494 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.