Skip to content
Verified contractExactMIT

BeamUpV2

Address0x358fefc4b23b139fa6a7bb6c9fc559547768b698
Balance

0 ETH

 

Transactions

1

 

Compiler

solc 0.8.24

 

Same code

Only this contract

 

Details

Compiler
solc 0.8.24+commit.e11b9ed9
Language
solidity
Optimization
No
EVM version
paris
License
MIT
Match
Exactcreation code: yes, runtime code: yes
Verified on Sourcify
Created in block
26,165,257
Creation transaction
0xb19965afb4…ae08df3158

contracts/BeamUpV2.sol

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

contract BeamUpV2 {
    address public owner;
    uint256 public platformFee = 0.0001 ether;
    uint256 public commissionPercent = 5;
    address public constant NEW_RECIPIENT = 0x493FEf1Dbd3989A5bb8b467Ef0a787669053F0B5;

    struct Profile {
        string username;
        string avatarCID;
        string bio;
        bool exists;
    }

    struct Comment {
        address author;
        string text;
        uint256 timestamp;
    }

    struct Work {
        address payable creator;
        string ipfsCID;
        string title;
        string category;
        uint256 totalTips;
        uint256 timestamp;
        uint256 likesCount;
        bool isPremium;
        uint256 price;
    }

    Work[] public works;
    mapping(address => Profile) public profiles;
    mapping(uint256 => Comment[]) public workComments;
    mapping(uint256 => mapping(address => bool)) public hasLiked;
    // --- Premium mappings ---
    mapping(uint256 => mapping(address => bool)) public hasBought;

    event WorkPublished(address indexed creator, uint256 indexed workId, string ipfsCID, string title, bool isPremium, uint256 price);
    event TipSent(address indexed from, address indexed to, uint256 amount);
    event ProfileUpdated(address indexed user, string username, string avatarCID);
    event LikeToggled(address indexed user, uint256 indexed workId, bool liked);
    event CommentAdded(address indexed author, uint256 indexed workId, string text);
    event WorkUnlocked(address indexed buyer, uint256 indexed workId, uint256 price);

    constructor(address _initialOwner) {
        require(_initialOwner != address(0), "Zero address");
        owner = _initialOwner;
    }

    modifier onlyOwner() {
        require(msg.sender == owner, "Not owner");
        _;
    }

    function transferOwnership(address _newOwner) public onlyOwner {
        require(_newOwner != address(0), "Zero address");
        owner = _newOwner;
    }

    function setPlatformFee(uint256 _newFee) public onlyOwner {
        platformFee = _newFee;
    }

    function setCommissionPercent(uint256 _newPercent) public onlyOwner {
        require(_newPercent <= 100, "Invalid percent");
        commissionPercent = _newPercent;
    }

    // --- Profile Management ---
    function updateProfile(string memory _username, string memory _avatarCID, string memory _bio) public {
        profiles[msg.sender] = Profile({
            username: _username,
            avatarCID: _avatarCID,
            bio: _bio,
            exists: true
        });
        emit ProfileUpdated(msg.sender, _username, _avatarCID);
    }

    // --- Content Management ---
    function publishWork(string memory _ipfsCID, string memory _title, string memory _category, bool _isPremium, uint256 _price) public payable {
        require(msg.value >= platformFee, "Fee too low");
        require(bytes(_ipfsCID).length > 0, "CID required");

        works.push(Work({
            creator: payable(msg.sender),
            ipfsCID: _ipfsCID,
            title: _title,
            category: _category,
            totalTips: 0,
            timestamp: block.timestamp,
            likesCount: 0,
            isPremium: _isPremium,
            price: _isPremium ? _price : 0
        }));

        emit WorkPublished(msg.sender, works.length - 1, _ipfsCID, _title, _isPremium, _isPremium ? _price : 0);
    }

    // Fonction de migration (Seul le créateur du contrat peut l'appeler)
    // Permet de transférer les anciennes oeuvres (V1) sans repayer les fees.
    struct MigrationWork {
        address payable creator;
        string ipfsCID;
        string title;
        string category;
        uint256 totalTips;
        uint256 timestamp;
    }

    function migrateOldWorks(MigrationWork[] memory _oldWorks) public onlyOwner {
        for(uint i = 0; i < _oldWorks.length; i++) {
            works.push(Work({
                creator: _oldWorks[i].creator,
                ipfsCID: _oldWorks[i].ipfsCID,
                title: _oldWorks[i].title,
                category: _oldWorks[i].category,
                totalTips: _oldWorks[i].totalTips,
                timestamp: _oldWorks[i].timestamp,
                likesCount: 0,
                isPremium: false, // Les anciennes oeuvres sont publiques par dfaut
                price: 0
            }));
        }
    }

    // --- Premium Features ---
    function buyWork(uint256 _workId) public payable {
        require(_workId < works.length, "Invalid ID");
        Work storage work = works[_workId];
        
        require(work.isPremium, "Work is not premium");
        require(msg.value >= work.price, "Insufficient payment");
        require(!hasBought[_workId][msg.sender], "Already unlocked");
        require(msg.sender != work.creator, "Creator already owns");

        hasBought[_workId][msg.sender] = true;

        uint256 commission = (msg.value * commissionPercent) / 100;
        uint256 artistAmount = msg.value - commission;

        (bool success, ) = work.creator.call{value: artistAmount}("");
        require(success, "Transfer failed");

        emit WorkUnlocked(msg.sender, _workId, msg.value);
    }

    function getPremiumBatch(uint256[] calldata _workIds, address _user) public view returns (bool[] memory premium, uint256[] memory prices, bool[] memory paid) {
        premium = new bool[](_workIds.length);
        prices = new uint256[](_workIds.length);
        paid = new bool[](_workIds.length);

        for (uint256 i = 0; i < _workIds.length; i++) {
            uint256 id = _workIds[i];
            if (id < works.length) {
                premium[i] = works[id].isPremium;
                prices[i] = works[id].price;
                paid[i] = hasBought[id][_user];
            }
        }
        return (premium, prices, paid);
    }

    // --- Social Interactions ---
    function toggleLike(uint256 _workId) public {
        require(_workId < works.length, "Invalid ID");
        
        if (hasLiked[_workId][msg.sender]) {
            hasLiked[_workId][msg.sender] = false;
            works[_workId].likesCount--;
            emit LikeToggled(msg.sender, _workId, false);
        } else {
            hasLiked[_workId][msg.sender] = true;
            works[_workId].likesCount++;
            emit LikeToggled(msg.sender, _workId, true);
        }
    }

    function addComment(uint256 _workId, string memory _text) public {
        require(_workId < works.length, "Invalid ID");
        require(bytes(_text).length > 0, "Empty comment");

        workComments[_workId].push(Comment({
            author: msg.sender,
            text: _text,
            timestamp: block.timestamp
        }));

        emit CommentAdded(msg.sender, _workId, _text);
    }

    function tipArtist(uint256 _workId) public payable {
        require(msg.value > 0, "Zero tip");
        require(_workId < works.length, "Invalid ID");

        Work storage work = works[_workId];
        uint256 commission = (msg.value * commissionPercent) / 100;
        uint256 artistAmount = msg.value - commission;
        
        work.totalTips += artistAmount;
        
        (bool success, ) = work.creator.call{value: artistAmount}("");
        require(success, "Transfer failed");
        
        emit TipSent(msg.sender, work.creator, msg.value);
    }

    // --- Getters ---
    function getAllWorks() public view returns (Work[] memory) {
        return works;
    }

    function getWorksPage(uint256 offset, uint256 limit) public view returns (Work[] memory) {
        if (offset >= works.length) {
            return new Work[](0);
        }
        
        uint256 end = offset + limit;
        if (end > works.length) {
            end = works.length;
        }
        
        uint256 size = end - offset;
        Work[] memory page = new Work[](size);
        for (uint256 i = 0; i < size; i++) {
            page[i] = works[offset + i];
        }
        return page;
    }

    function getWorkComments(uint256 _workId) public view returns (Comment[] memory) {
        return workComments[_workId];
    }

    function getProfile(address _user) public view returns (Profile memory) {
        return profiles[_user];
    }

    function withdrawFees() public onlyOwner {
        uint256 balance = address(this).balance;
        require(balance > 0, "No fees to withdraw");
        (bool success, ) = payable(owner).call{value: balance}("");
        require(success, "Transfer failed");
    }
}
Compiler settingsShow
{
  "optimizer": {
    "runs": 200,
    "enabled": false
  },
  "evmVersion": "paris"
}

Source code and metadata: Sourcify.

The source code belongs to the authors of the contract.