A decentralized music platform built on Ethereum that enables creators to share music tracks, receive tips in USDC, and build engagement through a like-to-tip mechanism.
BasedBeats is a blockchain-based music platform where:
- Creators can upload music tracks (metadata stored on IPFS)
- Listeners can like and tip tracks using USDC
- All interactions are transparent and recorded on-chain
- Creators earn directly from their supporters without intermediaries
- Track Creation: Upload music tracks with IPFS metadata
- Like-to-Tip: Liking a track automatically sends a tip to the creator
- Direct Tipping: Send additional tips to creators without liking
- Custom Tip Amounts: Users can set their preferred tip amount
- Pagination: Efficient querying of tracks with pagination support
- Batch Operations: Retrieve multiple tracks in a single call
- Reentrancy Protection: All state-changing functions are protected
- Gas Optimized: Uses EnumerableSet for efficient track management
- Comprehensive Events: All actions emit events for off-chain tracking
- Fully Documented: Complete NatSpec documentation for all functions
basedbeats-contracts/
βββ contracts/
β βββ BasedBeats.sol # Main contract implementation
β βββ IBasedBeats.sol # Interface definition
β βββ mocks/
β βββ USDC.sol # Mock USDC for testing
βββ test/
β βββ BasedBeats.test.ts # Comprehensive test suite
βββ hardhat.config.ts # Hardhat configuration
βββ package.json
The main contract implementing the music platform functionality:
- Inherits from OpenZeppelin's
OwnableandReentrancyGuard - Uses
SafeERC20for secure USDC transfers - Manages tracks, likes, and tips with efficient data structures
- Track: Stores creator address, IPFS CID, like count, and existence flag
- TipPreference: User-specific tip amount preferences
- EnumerableSet: Efficient storage and retrieval of track IDs
- Node.js >= 16
- npm or yarn
# Install dependencies
npm installCreate a .env file (if deploying to testnet/mainnet):
SEPOLIA_PRIVATE_KEY=your_private_key_here
ETHERSCAN_API_KEY=your_etherscan_api_key_hereRun the comprehensive test suite:
# Run all tests
npx hardhat test
# Run tests with coverage
npx hardhat coverage
# Run tests with gas reporting
REPORT_GAS=true npx hardhat testThe project includes 1157 lines of tests covering:
- Track creation and management
- Like and tip functionality
- Pagination and batch operations
- Edge cases and error conditions
- Gas optimization scenarios
# Start local Hardhat node
npx hardhat node
# Deploy to local network (in another terminal)
npx hardhat ignition deploy ignition/modules/BasedBeats.ts --network localhost# Set your private key
npx hardhat keystore set SEPOLIA_PRIVATE_KEY
# Deploy to Sepolia
npx hardhat ignition deploy --network sepolia ignition/modules/BasedBeats.ts
# Verify contract on Etherscan
npx hardhat verify --network sepolia DEPLOYED_CONTRACT_ADDRESS "USDC_ADDRESS" "DEFAULT_TIP_AMOUNT"// Upload track with IPFS CID
basedBeats.createTrack("QmXxxx...");// Approve USDC first
usdc.approve(address(basedBeats), tipAmount);
// Like the track (automatically sends tip)
basedBeats.like(trackId);// Set custom tip amount (in USDC decimals, e.g., 5 USDC = 5000000)
basedBeats.setTipPreference(5000000);// Approve USDC first
usdc.approve(address(basedBeats), tipAmount);
// Send tip without liking
basedBeats.tip(trackId);// Get all tracks (paginated)
(uint256[] memory trackIds, uint256 total) = basedBeats.getAllTracks(0, 10);
// Get tracks by creator
(uint256[] memory creatorTrackIds, uint256 total) = basedBeats.getCreatorTracks(creatorAddress, 0, 10);
// Get user's liked tracks
(uint256[] memory likedTrackIds, uint256 total) = basedBeats.getUserLikedTracks(userAddress, 0, 10);
// Get multiple tracks in one call
uint256[] memory trackIds = new uint256[](3);
trackIds[0] = 1;
trackIds[1] = 2;
trackIds[2] = 3;
Track[] memory tracks = basedBeats.getTracksBatch(trackIds);- Reentrancy Guards: All external state-changing functions protected
- SafeERC20: Secure token transfers with proper error handling
- Input Validation: Comprehensive checks for zero addresses and amounts
- Access Control: Owner-based permissions where needed
- Duplicate Prevention: Users cannot like the same track twice
MAX_BATCH_SIZE: 50 tracks per batch queryMAX_PAGINATION_LIMIT: 100 items per page- Default tip amount: Set during contract deployment
- Solidity: ^0.8.20
- Hardhat: 3.0.0-beta
- OpenZeppelin Contracts: ^5.1.0
- TypeScript: Testing framework
- Ethers.js: Ethereum library
0xdefiprof
MIT License - See LICENSE file for details
Contributions, issues, and feature requests are welcome!