A decentralized marketplace built on StarkNet for buying, selling, and managing digital music assets using IPFS for storage.
This project implements a decentralized song marketplace where users can:
- Register songs and set their prices
- Preview songs before purchasing
- Buy songs from other users
- Manage their song collections
The smart contract is written in Cairo for the StarkNet L2 scaling solution, with IPFS integration for decentralized storage of audio files.
The codebase is organized into three main files:
Entry point that organizes and exports the contract modules:
mod interface;
mod song_marketplace;
use song_marketplace::SongMarketplace;Defines the contract interface with all available functions:
#[starknet::interface]
trait ISongMarketplace<TContractState> {
fn register_song(...) -> u64;
fn get_song_info(...) -> (...);
fn update_song_price(...);
fn get_preview(...) -> felt252;
fn buy_song(...) -> felt252;
fn get_user_songs(...) -> Array<u64>;
fn is_song_owner(...) -> bool;
}Contains the main contract implementation with storage structures and function logic.
Users can register songs by providing:
- Song name
- IPFS hash of the full song
- IPFS hash of a preview clip
- Initial price
Potential buyers can access a preview version of songs before purchasing, reducing the risk associated with digital asset purchases.
The contract maintains a complete record of song ownership and validates all transactions to ensure only legitimate owners can modify or sell songs.
Each user has a tracked collection of owned songs, making it easy to manage digital assets.
The contract uses IPFS (InterPlanetary File System) for decentralized storage:
- Full songs are stored as complete files on IPFS
- Preview clips (shorter/lower quality versions) are stored separately
- Only the IPFS content identifiers (CIDs) are stored on-chain
This approach provides:
- Cost efficiency (only storing hash references on-chain)
- Data permanence through IPFS
- Reduced blockchain bloat
- Compile the contract:
starknet-compile lib.cairo --output song_marketplace_compiled.json- Deploy to StarkNet:
starknet deploy --contract song_marketplace_compiled.json- Interact with the deployed contract using StarkNet CLI or integrate with a frontend application.
starknet invoke --address CONTRACT_ADDRESS --function register_song --inputs "Song Name" "IPFS_FULL_SONG_HASH" "IPFS_PREVIEW_HASH" PRICEstarknet invoke --address CONTRACT_ADDRESS --function buy_song --inputs SONG_IDstarknet call --address CONTRACT_ADDRESS --function get_preview --inputs SONG_IDTo create a complete dApp experience, integrate this contract with a frontend that handles:
- Uploading songs to IPFS and generating hash values
- Creating preview clips and uploading them to IPFS
- Interacting with the StarkNet contract
- Wallet connectivity for payments and transaction signing
- Playback interface for previewing and listening to purchased songs
- The contract implements ownership verification before allowing price changes or sales
- In a production environment, additional security measures should be added:
- Reentrancy guards
- Formal verification
- Rate limiting
- Additional access controls
This project is licensed under the MIT License - see the LICENSE file for details.
- Royalty distribution to original creators
- Subscription-based access models
- Auction mechanisms for rare songs
- Integration with artist verification systems
- Support for album collections and bundled sales