第101篇 盲盒智能合约(ERC1155)

 本文环境:

          区块链版本:以太坊POA联盟链  + metamask + remix

          节点版本: geth 1.9.19

          操作系统:windows 64

          合约版本:solidity ^0.8.0

本文介绍一种实现盲盒功能的智能合约,作为 ERC1155 的示例;

1. 合约源码

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

import "@openzeppelin/contracts/token/ERC1155/ERC1155.sol";
import "@openzeppelin/contracts/access/Ownable.sol";
import "@openzeppelin/contracts/security/Pausable.sol";

contract BlindBox is Ownable, ERC1155, Pausable {
    string public name;
    string public symbol;
    string public baseURL;

    mapping(address => bool) public minters;
    modifier onlyMinter() {
        require(minters[_msgSender()], "Mint: caller is not the minter");
        _;
    }

    struct Box {
        uint    id;
        string  name;
        uint256 mintNum;
        uint256 openNum;
        uint256

猜你喜欢

转载自blog.csdn.net/wonderBlock/article/details/122284996