5

请问有没有参考的盲盒智能合约? | 登链社区 | 技术问答

 2 years ago
source link: https://learnblockchain.cn/question/2724
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client
请问有没有参考的盲盒智能合约? | 登链社区 | 技术问答

9 请问有没有参考的盲盒智能合约?

回答问题即可获得 5 经验值,回答被采纳后即可获得 14 学分。
温柔 1小时前

比如设定有30个A,20个B。 用户随机获得A或B。

温柔 1小时前
struct BoxFactory {
    uint256 id;
    uint8 bunnyId; // A
    string tokenURI;
    uint256 price;
    uint256 limit; // 限制x个,比如A 30
    uint256 minted; // 已经铸造 的个数, 比如A 1个
  }

  // factoryId: BoxFactory
  mapping(uint256 => BoxFactory) public _boxFactories;
温柔 1小时前
function addBoxFactory(
    uint8 bunnyId,
    string memory tokenURI,
    uint256 limit
  ) public onlyOwner returns (uint256) {
    _boxFactoriesId++;

    BoxFactory memory boxFactory;
    boxFactory.id = _boxFactoriesId;
    boxFactory.bunnyId = bunnyId;
    boxFactory.tokenURI = tokenURI;
    boxFactory.price = boxPrice;
    boxFactory.limit = limit;
    _boxFactories[_boxFactoriesId] = boxFactory;
    return _boxFactoriesId;
  }
温柔 1小时前

请问大佬如何实现一个方法,可以公平产出A或B,而且保证A和B的数量不能多也不能少。概率

function buyRandomBox() external payable nonReentrant returns(uint256 tokenId)  {
      // @????? 这里要怎么实现 公平随机决定 产出A还是B
    // uint256 factoryIdAorB??? = Random()????

    BoxFactory storage boxFactory = _boxFactories[factoryId];
    if (boxFactory.limit > 0) {
      require(
        boxFactory.limit.sub(boxFactory.minted) >= 1,
        "Over the limit"
      );
    }
    // 买一个生产一个box
    boxFactory.minted = boxFactory.minted.add(1);

    // 生产
    tokenId = factory.nft.mint(msg.sender, boxFactory.tokenURI, boxFactory.bunnyId);

  }
您需要登录后才可以回答问题,登录 或者 注册

About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK