Decentralized Music Streaming Demo
π§ What Is a Decentralized Music Streaming DApp?
It’s a platform where:
Artists upload their music to decentralized storage (IPFS).
Listeners stream songs via the DApp.
Smart contracts manage ownership, payments, and permissions — no middlemen.
π§± Tech Stack Overview
Component Technology
Blockchain Ethereum / Polygon (testnet)
Smart Contracts Solidity
Decentralized Storage IPFS (via Web3.Storage or Pinata)
Web3 Framework Hardhat / Truffle
Frontend React.js
Wallet MetaMask
Web3 Interaction Ethers.js or Web3.js
π§ Core Features (Demo Version)
✅ For Artists:
Upload song + metadata
Mint music as an NFT (optional)
Set price (if using pay-per-stream or download)
✅ For Listeners:
View music catalog
Stream songs directly from IPFS
Pay to stream/download if monetization is enabled
π Smart Contract (Solidity Example)
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.20;
contract MusicStreaming {
struct Track {
address artist;
string title;
string ipfsHash;
uint256 price; // 0 = free
}
Track[] public tracks;
event TrackUploaded(address indexed artist, uint trackId, string title);
function uploadTrack(string calldata _title, string calldata _ipfsHash, uint256 _price) external {
tracks.push(Track(msg.sender, _title, _ipfsHash, _price));
emit TrackUploaded(msg.sender, tracks.length - 1, _title);
}
function getTrack(uint _trackId) external view returns (string memory, string memory, uint256, address) {
Track memory track = tracks[_trackId];
return (track.title, track.ipfsHash, track.price, track.artist);
}
function getTracksCount() public view returns (uint) {
return tracks.length;
}
}
π΅ How Music Files Are Stored
Songs are uploaded to IPFS (decentralized file system)
The IPFS hash is stored on-chain in the smart contract
Songs can be streamed directly from IPFS in the browser
π» Frontend Example Features (React.js + Ethers.js)
1. Connect Wallet
const provider = new ethers.providers.Web3Provider(window.ethereum);
await provider.send("eth_requestAccounts", []);
const signer = provider.getSigner();
2. Upload Song
Use Web3.Storage or Pinata to upload MP3 file
Store the returned IPFS hash in the contract with the title and price
await contract.uploadTrack("My Song", "QmHashHere", 0);
3. Display Tracks and Stream
const [title, ipfsHash, price, artist] = await contract.getTrack(0);
const audioUrl = `https://ipfs.io/ipfs/${ipfsHash}`;
<audio controls>
<source src={audioUrl} type="audio/mpeg" />
</audio>
π§ͺ Testing (Hardhat Example)
describe("MusicStreaming", function () {
it("Should allow artist to upload and retrieve track", async () => {
const [artist] = await ethers.getSigners();
const Music = await ethers.getContractFactory("MusicStreaming");
const music = await Music.deploy();
await music.uploadTrack("Song Title", "QmExampleHash", 0);
const track = await music.getTrack(0);
expect(track[0]).to.equal("Song Title");
});
});
π Optional Enhancements
Add payment logic (e.g., charge per stream or download)
Mint songs as NFTs (ERC-721 or ERC-1155)
Use Lens Protocol or Livepeer for Web3-native media
Create artist profiles and fan donations
Add likes, shares, playlists (stored off-chain)
π Project Folder Structure
decentralized-music-app/
│
├── contracts/
│ └── MusicStreaming.sol
│
├── frontend/
│ ├── src/
│ │ └── App.js
│ │ └── components/
│ │ └── UploadTrack.js
│
├── scripts/
│ └── deploy.js
│
├── test/
│ └── music-test.js
│
├── hardhat.config.js
└── README.md
✅ Demo Flow Summary
Artist connects wallet → uploads MP3 to IPFS
Artist submits IPFS hash + title to smart contract
Listeners view song list → click to stream
(Optional) Listeners pay a small fee per stream
π Deployment Tips
Deploy contract to Polygon Mumbai or Sepolia testnet
Use Web3.Storage or Pinata for hosting music files
Host frontend on Vercel or Netlify
Include contract address, ABI, and MetaMask integration
π Final Notes
Keep the UI clean and minimal
Add a loading state for IPFS fetches
Include proper error handling and gas estimation
Document how artists and users should interact with the DApp
Learn Blockchain Course in Hyderabad
Read More
Blockchain-Based Resume Verification App
Crypto Portfolio Tracker Using Web3
Decentralized Chat App on IPFS
Comments
Post a Comment