Skip to content

A dApp where Users can buy headphones, speakers, or earphones in the Music Store dApp by interacting with the smart contract and sending Sepolia ETH from the MetaMask wallet i.e. in Sepolia ETH test net.

License

Notifications You must be signed in to change notification settings

Rishabh566/musical-store-dapp-blockchain

Repository files navigation

Blockchain Concepts and Technologies

Creation of a Decentralized, web3-enabled application. (Retail-ECommerce)- Report)

dApp URL: https://music-store-dapp.netlify.app/**

Presentation URL: BlockChain-Project-Presentation-20230408_184850-Meeting**** Recording.mp4**

I. Introduction

Blockchain is a type of data structure that keeps track of transactions in an open, secure, and decentralized way. It is

an unbroken chain of data stored in blocks that is not under the authority of any one person or organization. The

blocks store data regarding a particular transaction, such as the user ID, credit card details, delivery details, and

currency amount. The larger database where the blocks are stored is called the chain. The hash of every block is added

to the hash of every new block to establish a link between earlier and recent transactions. Each block is given a distinct

ID and encrypted using an algorithm. Users can buy headphones, speakers, or earphones in the Music Store dApp by

interacting with the smart contract and sending Sepolia ETH from the MetaMask wallet i.e. in Sepolia ETH test net.

The blockchain system confirms that the data is saved in a block, which is then encrypted and assigned a special ID.

Each block's hash is added to the hash of the next block, ensuring a secure link between earlier and more recent

transactions. Blockchain is a safe and fantastic technology because it would take an impossibly large amount of

processing power to modify even a single block.

II. Process of Operations

1. Tools Used:

Building a dApp involves a number of distinct components and tools and can be the subject of a stand-alone article. The

the project focuses on JavaScript/NodeJS DApp built on the Ethereum platform. The following are the tools used to

create dApp:

1. Front-end:

Tool: ReactJS [2]

In order to create the user interfaces for my web application, I used ReactJS as a front-end JavaScript library.

It effectively handles state and enables the simple construction of intricate UI components.

2. Back-end:

Tool: Solidity [6]

The object-oriented, high-level programming language Solidity is what I used to create Smart Contracts that

run on the Ethereum network. It is possible to deploy Solidity code as a bytecode on the blockchain.

Tool: Hardhat

In order to build, test, and deploy my Smart Contracts, I utilized Hardhat as my development environment.

For the purpose of testing, debugging, and deploying Smart Contracts, Hardhat offers a number of tools

including a local blockchain instance.

3. Web client libraries:

Tool: Ether.js [7]

On the Ethereum blockchain, I have interacted with my smart contracts using Ether.js and spoken with end

users. As a JavaScript library, Ether.js offers a high-level API for interacting with apps built on the Ethereum

platform.

4. Account management:

Tool: MetaMask

Manage accounts and link the presently logged-in user to the blockchain, I utilized MetaMask. An add-on for

the browser called MetaMask controls user accounts and enables transaction signing.

5. Node Provider:

Tool: Infura API [1]

I have provided endpoint access to Ethereum networks using the Infura API. Developers can access Ethereum

blockchain data through Infura's API endpoint without having to run a complete node.

6. Frameworks:

Tool: Hardhat [5]

Test, debug, and deploy Smart Contracts, I used the Hardhat framework. For testing and deploying Smart

Contracts, Hardhat offers a set of tools and a local blockchain instance.

7. Deployment:

Tool: Netlify [3]

My dApp was uploaded to the cloud via Netlify, and its URL has been made public. It is straightforward to

handle environment variables, continuous integration/continuous deployment (CI/CD) pipelines, and web

application deployment with Netlify.

Overall, I built and deployed my dApp using JavaScript/NodeJS utilizing these tools on the Ethereum network.

From creating user interfaces to testing and deploying Smart Contracts, each tool had a distinct function during

the development process. The dApp was published to the cloud using Netlify and made publicly available

through URL.

8. 3rd Party API: Coinbase.io: I am using coinbase.io API to display the current exchange rate in dollars.

https://www.coinbase.com/ [8]

2. Setup and Configuration

Setting Up the application:

In the .zip file provided for the code do the following steps:

a. Extract .zip file.

b. Open the extracted folder and run the below command in the root directory.

Screenshot 2023-07-18 at 20 49 27

c. Now go to “frontend” and run the same npm install command. It will install all the project dependencies that are recorded in the package .Json file.

Screenshot 2023-07-18 at 20 51 32

d. Sign Up into INFURA: https://www.infura.io/ and go to Dashboard.

Screenshot 2023-07-18 at 20 52 41

e. Click on “CREATE NEW API KEY” > select “WEB3 API” Network and give the name of the project and then take a not of your API KEY and ENDPOINT URL.

Screenshot 2023-07-18 at 20 54 46

f. Above information along with the Owner MetaMask Private Key is stored as the environment variable in “.env” file.

Screenshot 2023-07-18 at 20 56 31

g. Compile the “music. Sol” solidity file with hardhat it will deploy the “Smart Contract” and give “Smart Contract Address” and “ABI .Json” file, which will be used by the front end and ether.js to interact with the smart contract that is deployed on the Sepolia test network.

Screenshot 2023-07-18 at 21 16 05

The below screenshot is for the contract deployment using hardhat.

Screenshot 2023-07-18 at 21 18 43

h. Now, the configuration is done in the frontend here “App.js” so that the connecting users' MetaMask Wallet starts interacting with the underlying Smart Contract as shown below.

Screenshot 2023-07-18 at 21 19 23

i. Type “npm run build” to build the source code and deploy it on Netlify.

Signup into Netlify account by going to https://app.netlify.com/ and create a site called “music-store-dApp” and give the URL link for the same.

Screenshot 2023-07-18 at 21 20 33

Drop the build file.

Screenshot 2023-07-18 at 21 21 24

j. Setup your domain and upload your build folder.

Screenshot 2023-07-18 at 21 22 16

WEB3 dApp is live now!!!! https://music-store-dapp.netlify.app/

3. Architecture:

Screenshot 2023-07-18 at 21 28 36

After launching a fresh React project, the first thing I did was install the Ethers.js library, which allows connection with the blockchain. The blockchain is made up of many nodes, each of which holds a copy of the blockchain's data. My dApp required to be able to interface with one of these nodes in order to read or write any of this data these libraries give access to several modules (with methods and attributes) that can be used to communicate with Sepolia Ethereum TestNet. For example, "ethers.Wallet" is used to connect to an Ethereum wallet, while "ethers.Contract" is used to communicate with an Ethereum smart contract. The MetaMask wallet functions as a login and gateway to a DApp. Users are asked to sign in with an email address and a password in typical web apps. To enable particular functionality in the decentralized world, DApps must be granted access to a user's wallet. Metamask, which is available as a Chrome extension or a mobile app, was installed. Now that I had everything I needed, I was able to speak with the blockchain. The "middleman" — the smart contract — is then contacted. To connect to a smart contract, you must have the contract address, ABI, and a provider and/or a signer. The contract address is the contract's address on the blockchain. The ABI (Application Binary Interface) is a JSON file that gives a breakdown of each function in the contract, including any input parameters, intended output, and data types. Contract ABI is established by using HardHat to compile our "music.sol" solidity file. Both may be discovered on Etherscan, an Ethereum blockchain explorer that lets you inspect smart contracts. A DApp requires providers and signers. A smart contract can have both read and write capabilities. You will need a provider to read data from a smart contract. A signer is required to write data (i.e. to perform transactions that affect the status of the data on the blockchain). Both require a signer with a provider. I utilized Infura Node Provider to establish a provider utilizing Ethers.js's built-in Infura provider option.

“const provider = new ethers.providers.InfuraProvider('rinkeby', INFURA_PROJECT_ID);”

In contrast, signers are effectively an abstraction of the user's wallet address. Any writing operation to the blockchain will require you to sign the transaction. (i.e., prove that you are who you are). Finally, I constructed a contract that would be utilized throughout the application, sending in the contract address, ABI, and signer as parameters.

“const contract = new ethers.Contract(CONTRACT_ADDRESS, CONTRACT_ABI, provider or signer);”

With this done, I could call my smart contract function.

“const result = await contract.functionName();”

All the transactions are made, and the records are visible in sepolia etharscan under the contract address and at last the contract balance is transfered to the owners Metamask Wallet. And at last, the “build” file is updated to the cloud platform “Netlify”, and I had a URL to access my music-store-dApp. I have used Coinabase API to fetch the exchange value of few crypto currencies to USD.

III. Conclusion

Key takeaways from the project:

1. Front-end libraries, back-end programming languages, web client libraries, providers, and frameworks are used by Web3 apps to interface with the Ethereum blockchain.

2. MetaMask and Infura API are two essential providers that allow web3 applications to interface with blockchain smart contracts.

3. Netlify is a cloud platform that can be used to deploy apps that employ the web3 standard.

4. In web3 applications, end-users retain ownership of all of their data, removing the requirement for a centralized authority or an intermediary.

IV. Bibliography/References

[1] https://community.infura.io/t/react-js-ethers-js-demo-of-using-the-infuraprovider-vs-the-metamask-wallet-

web3provider/6108

[2]* Building** DApp** Frontends** with** React** &** Network.js** -** Infura*

[3]* Deploying** React** apps** to** Netlify:** three** methods*

[5]* Compiling** your** contracts** |** Hardhat** |** Ethereum** development** environment*

[6]* How** to** develop** Solidity** smart** contracts** using** Hardhat*

[7]* The** Complete** Guide** to** Full** Stack** Web3** Development** -** DEV** Community*

[8]* Using** Coinbase** APIs** |** Coinbase** Helpc*

V. Use and Purpose of Smart Contracts

Smart contracts are self-executing and automated digital contracts with rules and logic expressed in code. Nick Szabo proposed them as a digital transaction mechanism in the 1990s. A blockchain, which is a distributed and transparent ledger that records transactions across a network of computers, is where smart contracts are maintained. Because a transaction cannot be changed once it is recorded on the blockchain, the blockchain technology used in smart contracts assures efficiency, security, and transparency. Smart contracts do not require intermediaries like banks, attorneys, or notaries, making them more efficient, secure, and cost-effective. Smart contracts allow contracts to be executed automatically once certain logics are met, eliminating the need for intermediaries. They digitally duplicate the conditions of real-world contracts, allowing transactions between untrustworthy parties to take place without the need for direct contact or dependence on third parties. Smart contracts have several advantages over traditional contracts, including lower transaction risk, lower administration and service costs, and improved business process efficiency. They are expected to provide improved alternatives to the current transaction mechanism in a variety of industries. For e.g. there is a smart contract working between you and soda Machine.

The creation of tokens, NFTs, and applications with smart contract functionality has completely changed a number of industries, including finance, the arts, gaming, and more. The issue of confirming ownership of digital assets, which was previously vulnerable to tampering and consequently, severe losses, has been solved specifically by NFTs. A digital certificate of ownership that can be bought and sold can be created using NFTs, and a record of who owns what can be recorded on a shared ledger known as the blockchain. Due to this, exclusive ownership and asset security have been improved. In the financial industry, the use of DLT-based tokens has grown in popularity as a means of capital raising, and smart contracts have the ability to do away with middlemen and lower transaction costs. NFTs have made it possible for digital artists to make money from their work and have led to high-profile sales in the art world. In the gaming business, NFTs and smart contracts can streamline payment procedures in the building sector.

However, using blockchain-based technologies raises several ethical and social questions. The environmental impact of these technology, which can use large quantities of energy when mining cryptocurrency, is one of the key issues.

Questions about enforceable property rights and open governance are also raised by ownership and governance of the digital assets represented by NFTs. Concerns regarding the commercialisation of art and its effects on conventional notions of art ownership and value have been raised by the introduction of NFTs in the art world. Finally, despite their increased security and openness, the use of blockchain-based technology in banking raises questions about the possibility of fraud and other illegal acts.

In order to maximize the benefits of blockchain-based technology while minimizing any potential negatives, these ethical and societal challenges must be addressed.

Many businesses are looking at integrating blockchain technology into their daily operations. For instance, in order to improve interactions with public transportation, BMW is thinking about incorporating blockchain into its next fleet of electric automobiles. The potential of blockchain for better monitoring of parts and maintenance procedures is being investigated by Lufthansa Airways. In contrast, Deutsche Telekom is using smart contracts to discuss roaming rates with other telecoms firms. For example, 1) The goal of PowerLedger (https://www.powerledger.io/ ), an award- winning Australian business, is to hasten the shift to a carbon-free economy. The issue is prevalent in apartment buildings where tenants frequently occupy the flats, according to the company. Apartment owners face a dilemma since they might not be motivated to put in solar panels or batteries because the tenants are the ones who benefit from them. The body corporate may now accept tenant payments for their electricity bills thanks to a new solution from PowerLedger. By doing this, the tenant avoids paying the power company and instead pays the owner directly for their electricity. Additionally, any extra energy that isn't utilized while the tenant is away might be sold to a neighbour to lower their energy costs and make money for the property owner. By tokenizing assets and making it simpler to invest in solar or wind farms, this offers a mechanism that justifies the investment in the first place and could expedite sustainable energy projects. 2) Another illustration is GAMB, a blockchain-based decentralized eCommerce platform. The platform is run by the Global Alliance of Merchants on the Blockchain (GAMB), where token holders who are members of the Merchant Alliance submit rules and regulations. These recommendations are then written into smart contracts, ensuring sustainability, reliability, and openness. GAMB is designed with merchants in mind, and the merchants themselves manage its features, functioning, and fee structures through a decentralized autonomous organization. (DAO).

About

A dApp where Users can buy headphones, speakers, or earphones in the Music Store dApp by interacting with the smart contract and sending Sepolia ETH from the MetaMask wallet i.e. in Sepolia ETH test net.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published