Music Sampling Rights Contract

What it does:
Allows musicians and producers to license audio samples on-chain, granting permission to sample a track while automatically enforcing royalty payments.

Why it matters:
Simplifies sample clearance, reduces legal friction, prevents unauthorized use, and ensures original artists are fairly compensated when their work is sampled.

How it works:

  • Original artists register tracks or samples with licensing terms and royalty rates

  • Producers request sampling rights by paying an upfront fee on-chain

  • Smart contract grants a non-exclusive sampling license

  • Royalties from derivative works are routed to the original artist automatically

  • Licenses and usage rights are tracked immutably on-chain

  • Supports time-limited or perpetual sample licenses

  • Integrates with publishing, streaming revenue, and NFT music platforms

      // SPDX-License-Identifier: MIT
pragma solidity ^0.8.20;

import "@openzeppelin/contracts/access/Ownable.sol";
import "@openzeppelin/contracts/token/ERC20/IERC20.sol";

/**
 * @title MusicSamplingRights
 * @author Nam
 * @notice On-chain licensing and royalty distribution for music sampling
 */
contract MusicSamplingRights is Ownable {

    struct Sample {
        string metadataURI;
        address payable originalArtist;
        uint256 upfrontFee; // ETH
        uint256 royaltyRate; // out of 10000 (e.g. 500 = 5%)
        bool active;
        mapping(address => bool) licensedProducers;
        mapping(address => uint256) pendingRoyalties;
    }

    uint256 public sampleCount;
    mapping(uint256 => Sample) private samples;

    // -------------------- EVENTS --------------------

    event SampleRegistered(uint256 indexed sampleId, address indexed artist);
    event SampleLicensed(uint256 indexed sampleId, address indexed producer);
    event RoyaltyPaid(uint256 indexed sampleId, address indexed producer, uint256 amount);
    event Withdrawal(uint256 indexed sampleId, address indexed artist, uint256 amount);

    // -------------------- SAMPLE REGISTRATION --------------------

    function registerSample(
        string calldata _metadataURI,
        uint256 _upfrontFee,
        uint256 _royaltyRate
    ) external {
        require(_royaltyRate  0, "Nothing to withdraw");

        s.pendingRoyalties[msg.sender] = 0;
        payable(msg.sender).transfer(amount);

        emit Withdrawal(_sampleId, msg.sender, amount);
    }
}