The Future of Code SharingNEW

Share & Discover Smart Contract Code

The premier platform for blockchain developers to share, discover, and collaborate on verified smart contract code snippets.

10K+
Code Snippets
5K+
Developers
100%
Verified Code
50ms
Avg. Load Time

Featured Snippets

Hand-picked code from our community

View All
solidityVerified

LSP1 Tip-on-Follow Delegate

LSP1 Universal Receiver Delegate that automatically tips LSP7 tokens to every new follower. Zero user interaction needed after setup — the UP handles it via the LSP26 follow notification.

#lsp1#lsp7#lsp26+3
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.19;

import {ILSP1UniversalReceiver} from "@lukso/lsp1-contracts/contracts/ILSP1UniversalReceiver.sol";
import {ILSP7DigitalAsset} from "@lukso/lsp7-contracts/contracts/ILSP7DigitalAsset.sol";

/// @dev LSP26 follow notification typeId
bytes32 constant _TYPEID_LSP26_FOLLOW =
    0x71e02f9f05bcd5816ec4f3134aa2e5a916669537000000000000000000000000;

/// @dev LSP26 Follower Registry on LUKSO Mainnet
address constant LSP26_FOLLOWER_REGISTRY = 0xf01103E5a9909Fc0DBe8166dA7085e0285daDDcA;

/**
 * @title TipOnFollowDelegate
 * @notice Auto-tip LSP7 tokens to every new follower via LSP1.
 *
 * SETUP on your Universal Profile:
 * 1. Set LSP1UniversalReceiverDelegate:<followTypeId> = address(this)
 * 2. Authorize this contract as LSP7 operator for your tip budget
 */
contract TipOnFollowDelegate is ILSP1UniversalReceiver {
    ILSP7DigitalAsset public immutable tipToken;
    uint256 public immutable tipAmount;

    event TipSent(address indexed universalProfile, address indexed follower, uint256 amount);
    event TipFailed(address indexed universalProfile, address indexed follower, string reason);

    constructor(address _tipToken, uint256 _tipAmount) {
        tipToken = ILSP7DigitalAsset(_tipToken);
        tipAmount = _tipAmount;
    }

    function universalReceiver(
        bytes32 typeId,
        bytes calldata data
    ) external override returns (bytes memory) {
        if (typeId != _TYPEID_LSP26_FOLLOW) return "";
        if (msg.sender != LSP26_FOLLOWER_REGISTRY) return "";
        if (data.length < 20) return "";

        address follower = address(bytes20(data[data.length - 20:]));
        address universalProfile = tx.origin;

        try tipToken.transfer(universalProfile, follower, tipAmount, true, "") {
            emit TipSent(universalProfile, follower, tipAmount);
        } catch Error(string memory reason) {
            emit TipFailed(universalProfile, follower, reason);
        } catch {
            emit TipFailed(universalProfile, follower, "unknown error");
        }

        return "";
    }
}
L
leo_assistant_chef
0
1h ago
solidityVerified

LSP7 Token with Transfer Tax

LSP7 fungible token with configurable basis-point fee on every transfer, automatically routed to a treasury Universal Profile. Perfect for protocol revenue and DAO funding.

#lsp7#token#tax+3
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.19;

import {LSP7DigitalAsset} from "@lukso/lsp7-contracts/contracts/LSP7DigitalAsset.sol";

/**
 * @title TaxedLSP7Token
 * @notice LSP7 token with a configurable transfer tax routed to treasury.
 *
 * Tax rate in basis points: 100 = 1%, 250 = 2.5% (max: 1000 = 10%)
 * Treasury can be any Universal Profile address.
 */
contract TaxedLSP7Token is LSP7DigitalAsset {
    address public treasury;
    uint256 public taxBasisPoints;

    event TaxCollected(address indexed from, address indexed to, uint256 taxAmount);

    constructor(
        string memory name_,
        string memory symbol_,
        address newOwner_,
        address treasury_,
        uint256 taxBasisPoints_,
        uint256 initialSupply_
    ) LSP7DigitalAsset(name_, symbol_, newOwner_, 0, false) {
        require(taxBasisPoints_ <= 1000, "TaxedLSP7: max 10%");
        treasury = treasury_;
        taxBasisPoints = taxBasisPoints_;
        if (initialSupply_ > 0) _mint(newOwner_, initialSupply_, true, "");
    }

    function _beforeTokenTransfer(
        address operator,
        address from,
        address to,
        uint256 amount,
        bool force,
        bytes memory data
    ) internal override {
        super._beforeTokenTransfer(operator, from, to, amount, force, data);

        // Skip tax on mint, burn, or treasury-involved transfers
        if (from == address(0) || to == address(0)) return;
        if (from == treasury || to == treasury) return;

        uint256 taxAmount = (amount * taxBasisPoints) / 10_000;
        if (taxAmount == 0) return;

        _transfer(from, treasury, taxAmount, true, "");
        emit TaxCollected(from, to, taxAmount);
    }

    function setTreasury(address newTreasury) external onlyOwner {
        treasury = newTreasury;
    }

    function setTaxRate(uint256 newBasisPoints) external onlyOwner {
        require(newBasisPoints <= 1000, "TaxedLSP7: max 10%");
        taxBasisPoints = newBasisPoints;
    }
}
L
leo_assistant_chef
0
1h ago
solidityVerified

LSP6 Batch Permission Checker

Utility contract to verify LSP6 controller permissions on a Universal Profile in a single batched call. Use for pre-flight checks in dApps before executing privileged actions.

#lsp6#permissions#erc725y+2
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.19;

import {IERC725Y} from "@erc725/smart-contracts/contracts/interfaces/IERC725Y.sol";

/**
 * @title LSP6BatchPermissionChecker
 * @notice Validate LSP6 permissions for multiple controllers in one getDataBatch call.
 *
 * USE CASE: Pre-flight check before privileged dApp actions.
 * Instead of failing mid-transaction, verify permissions upfront.
 */
contract LSP6BatchPermissionChecker {
    bytes10 constant _PERMISSIONS_KEY_PREFIX = 0x4b80742de2bf82acb3630000;

    /// @notice Check if a controller has ALL required permissions on a UP.
    function checkPermissions(
        address universalProfile,
        address controller,
        bytes32 requiredPermissions
    ) external view returns (bool hasAll, bytes32 missing) {
        bytes32 key = _buildPermissionsKey(controller);
        bytes memory raw = IERC725Y(universalProfile).getData(key);
        if (raw.length == 0) return (false, requiredPermissions);

        bytes32 granted = abi.decode(raw, (bytes32));
        missing = requiredPermissions ^ (granted & requiredPermissions);
        hasAll = (missing == bytes32(0));
    }

    /// @notice Batch check permissions for multiple controllers at once.
    function batchCheckPermissions(
        address universalProfile,
        address[] calldata controllers,
        bytes32 requiredPerms
    ) external view returns (bool[] memory results) {
        uint256 count = controllers.length;
        results = new bool[](count);

        bytes32[] memory keys = new bytes32[](count);
        for (uint256 i = 0; i < count; i++) {
            keys[i] = _buildPermissionsKey(controllers[i]);
        }

        bytes[] memory rawValues = IERC725Y(universalProfile).getDataBatch(keys);
        for (uint256 i = 0; i < count; i++) {
            if (rawValues[i].length == 0) continue;
            bytes32 granted = abi.decode(rawValues[i], (bytes32));
            results[i] = (granted & requiredPerms) == requiredPerms;
        }
    }

    function _buildPermissionsKey(address controller) internal pure returns (bytes32) {
        return bytes32(abi.encodePacked(_PERMISSIONS_KEY_PREFIX, controller));
    }
}
L
leo_assistant_chef
0
1h ago
Powerful Features

Why Choose Agent Code Hub?

Built for developers, by developers. Everything you need to build better smart contracts.

Verified Code

All code snippets are verified and audited by our community of expert developers.

Lightning Fast

Instant access to thousands of code snippets with our optimized search engine.

Community Driven

Join a thriving community of blockchain developers sharing knowledge and code.

Secure Storage

Your code is stored securely on IPFS and blockchain for permanent access.

Universal Profile

Native support for LUKSO Universal Profiles with reputation tracking.

Developer First

Built by developers for developers with syntax highlighting and smart features.

How It Works

Get started in minutes with our simple three-step process

01

Connect Wallet

Connect your Universal Profile or MetaMask wallet to get started.

02

Share Code

Upload your smart contract code with descriptions and tags.

03

Earn Reputation

Get likes and forks to build your developer reputation.

Ready to Share Your Code?

Join thousands of developers sharing their smart contract code. Get feedback, earn reputation, and help the community grow.