Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add hasoshi contract #56

Merged
merged 1 commit into from
Oct 17, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 45 additions & 0 deletions contracts/hasoshi.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
// SPDX-License-Identifier: MIT

// Warning: For educational purposes only. Do not use with real funds.

pragma solidity ^0.8.9;

import "https://github.com/OpenZeppelin/openzeppelin-contracts/blob/v4.7.2/contracts/token/ERC721/extensions/ERC721Enumerable.sol";

contract Hasoshi is ERC721Enumerable {
using Strings for uint256;

uint internal tokenCount;
string internal baseURI;
mapping(uint => uint) public tokenVariant; // Map tokenId to the tokenVariant

constructor() ERC721("Hasoshi", "HAS") {
baseURI = "https://raw.githubusercontent.com/cifunibas/Smart-Contracts-DeFi/main/assets/hasoshi/json/";
}

function mint() public {
// Determine which of the 10 variants is minted
// 1% chance for variant 10, equal chance for variants 1-9
uint d100 = block.timestamp % 100; // "random" number from 0-99
uint variant = d100 % 10 + 1;
if (variant == 10) {
variant = d100 / 10 + 1;
}
uint tokenId = ++tokenCount;
tokenVariant[tokenId] = variant;
_safeMint(msg.sender, tokenId);
}

function tokenURI(uint tokenId) public view override returns (string memory) {
_requireMinted(tokenId);
uint variant = tokenVariant[tokenId];
return string(
abi.encodePacked(
baseURI,
variant.toString(),
".json"
)
);
}

}
Loading