HashLand
  • welcome
    • Get to know us
    • Related Links
  • electricity
    • About HashLand Electricity
    • Daily Income
    • Contract
    • FAQ
  • GameFi
    • Hash Warfare
      • Hero
      • Game items
      • Game currency
      • Introduction of game props
      • Introduction of profile photo
      • Rank
      • Store
      • Team formation
      • Album
      • Mailbox
      • Friend system
      • Carnival
      • Daily task
      • Battle
      • PVP
      • Challenge
        • Space Exploration
        • Fissure of the Earth core
        • Astrolabe travel
        • Galaxy Ground
      • Game Mechanics
        • PVE
        • PVP
  • white paper
    • Abstract
    • HashLand Introduction
    • HashLand Purpose
    • HashLand NFT
      • Synthetic NFT Forging
      • Synthetic NFT Expandability
    • HashLand Application
      • S-NFT Card Levels And Mining Hash Rate
      • Purchase Contract
      • Blind Box Purchase Contract
      • S-NFT Cards Upgrade Contract
    • HashLand GameFi
    • Platform Token
      • HC Tokenomics
      • HC Token Purpose
    • Others
      • Roadmap
      • Risk Disclosure
      • Legal Information and Communications
  • DAO
    • About DAO
    • DAO Treasury
    • DAO Proposal
Powered by GitBook
On this page
  1. white paper
  2. HashLand Application

Blind Box Purchase Contract

Blind Boxes will contain cards with levels vary from 1 to 5. You will get 1 S-NFT card for every blind box purchased. The level of the card will be determined by a ramdon function.

function buyBoxes(uint256 boxesLength, uint256 tokenId)
        external
        payable
        nonReentrant
    {
        require(boxesLength > 0, "Boxes length must > 0");
        require(boxesLength <= 100, "Boxes length must <= 100");
        require(getBoxesLeftSupply() >= boxesLength, "Not enough boxes supply");
    
    uint256 price = boxesLength * boxTokenPrices[tokenId];
    if (tokenId == 0) {
        require(msg.value == price, "Price mismatch");
        payable(receivingAddress).transfer(price);
    } else {
        IERC20 token = IERC20(tokenAddrs[tokenId]);
        token.transferFrom(msg.sender, receivingAddress, price);
    }

    spawnHns(msg.sender, boxesLength);

    userBoxesLength[msg.sender] += boxesLength;
    userTokenBuyAmount[msg.sender][tokenId] += price;
    totalBoxesLength += boxesLength;
    totalTokenBuyAmount[tokenId] += price;
    users.add(msg.sender);
}
PreviousPurchase ContractNextS-NFT Cards Upgrade Contract

Last updated 3 years ago

View full code at:

https://github.com/HashlandGamefi/hashland-core/blob/main/contracts/pool/HNBox.sol