# 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.&#x20;

```
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);
}
```

View full code at: <https://github.com/HashlandGamefi/hashland-core/blob/main/contracts/pool/HNBox.sol>


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://land-hash.gitbook.io/hashland/white-paper/hashland-application/blind-box-purchase-contract.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
