Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

8 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

BasedBeats Smart Contracts

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.

🎡 Overview

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

✨ Features

Core Functionality

  • 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

Smart Contract Features

  • 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

πŸ“ Project Structure

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

πŸ—οΈ Contract Architecture

BasedBeats.sol

The main contract implementing the music platform functionality:

  • Inherits from OpenZeppelin's Ownable and ReentrancyGuard
  • Uses SafeERC20 for secure USDC transfers
  • Manages tracks, likes, and tips with efficient data structures

Key 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

πŸš€ Getting Started

Prerequisites

  • Node.js >= 16
  • npm or yarn

Installation

# Install dependencies
npm install

Environment Setup

Create a .env file (if deploying to testnet/mainnet):

SEPOLIA_PRIVATE_KEY=your_private_key_here
ETHERSCAN_API_KEY=your_etherscan_api_key_here

πŸ§ͺ Testing

Run 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 test

Test Coverage

The 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

πŸ“¦ Deployment

Local Deployment

# Start local Hardhat node
npx hardhat node

# Deploy to local network (in another terminal)
npx hardhat ignition deploy ignition/modules/BasedBeats.ts --network localhost

Testnet Deployment (Sepolia)

# 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"

πŸ“– Usage Examples

Creating a Track

// Upload track with IPFS CID
basedBeats.createTrack("QmXxxx...");

Liking a Track (with automatic tip)

// Approve USDC first
usdc.approve(address(basedBeats), tipAmount);

// Like the track (automatically sends tip)
basedBeats.like(trackId);

Setting Custom Tip Preference

// Set custom tip amount (in USDC decimals, e.g., 5 USDC = 5000000)
basedBeats.setTipPreference(5000000);

Sending a Tip

// Approve USDC first
usdc.approve(address(basedBeats), tipAmount);

// Send tip without liking
basedBeats.tip(trackId);

Querying Tracks

// 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);

πŸ”’ Security Features

  • 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

πŸ“Š Constants & Limits

  • MAX_BATCH_SIZE: 50 tracks per batch query
  • MAX_PAGINATION_LIMIT: 100 items per page
  • Default tip amount: Set during contract deployment

πŸ› οΈ Tech Stack

  • Solidity: ^0.8.20
  • Hardhat: 3.0.0-beta
  • OpenZeppelin Contracts: ^5.1.0
  • TypeScript: Testing framework
  • Ethers.js: Ethereum library

πŸ‘€ Author

0xdefiprof

πŸ“„ License

MIT License - See LICENSE file for details

🀝 Contributing

Contributions, issues, and feature requests are welcome!

πŸ”— Links

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages