-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This might not work yet - not as extensively tested as other stuff. - Added sismondi_test.py script without the fee adjustement - script/images.py directly creates the contract
- Loading branch information
Showing
7 changed files
with
150 additions
and
16 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
// SPDX-License-Identifier: UNLICENSED | ||
|
||
pragma solidity ^0.8.0; | ||
|
||
import "@openzeppelin/contracts/token/ERC721/extensions/ERC721URIStorage.sol"; | ||
import "@openzeppelin/contracts/utils/Counters.sol"; | ||
|
||
|
||
import {Base64} from "./libraries/Base64.sol"; | ||
|
||
contract SismondiNFT is ERC721URIStorage { | ||
|
||
using Counters for Counters.Counter; | ||
Counters.Counter private _tokenIds; | ||
|
||
uint256 public totalSupply; | ||
|
||
string images_prefix = |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
; | ||
|
||
string[] images = [ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
]; | ||
string[] wordList = ["One", "Two", "Three", "Four", "Five", "Six", "Seven", "Eight"]; | ||
|
||
event NewSismondiNFTMinted(address sender, uint256 tokenId); | ||
|
||
|
||
constructor() ERC721 ("Sismondi Shoes Short", "SiSho4") { | ||
totalSupply = 10; | ||
} | ||
|
||
function pickRandomWord(uint256 tokenId) internal view returns (string memory) { | ||
uint256 rand = random(string(abi.encodePacked("WORD", Strings.toString(tokenId)))); | ||
rand = rand % wordList.length; | ||
return wordList[rand]; | ||
} | ||
|
||
function pickRandomImage(uint256 tokenId) internal view returns (string memory) { | ||
uint256 rand = random(string(abi.encodePacked("WORD", Strings.toString(tokenId)))); | ||
rand = rand % images.length; | ||
return images[rand]; | ||
} | ||
|
||
function random(string memory input) internal pure returns (uint256) { | ||
return uint256(keccak256(abi.encodePacked(input))); | ||
} | ||
|
||
function makeSismondiNFT() public { | ||
uint256 newItemId = _tokenIds.current(); | ||
require(newItemId < totalSupply, "Total supply has been reached!"); | ||
|
||
string memory randomWord = pickRandomWord(newItemId); | ||
string memory randomImage = pickRandomImage(newItemId); | ||
|
||
string memory TOKEN_JSON_URI = getTokenURI(randomWord, randomImage); | ||
|
||
_safeMint(_msgSender(), newItemId); | ||
_setTokenURI(newItemId, TOKEN_JSON_URI); | ||
_tokenIds.increment(); | ||
emit NewSismondiNFTMinted(_msgSender(), newItemId); | ||
} | ||
|
||
function getTokenURI(string memory words, string memory pngString) internal view returns (string memory) { | ||
|
||
string memory json = Base64.encode( | ||
bytes( | ||
string( | ||
abi.encodePacked( | ||
'{"name": "', words, | ||
'", "description": "A Sismondi NFT collection.",' | ||
'"image": "', images_prefix, pngString, | ||
'"}' | ||
) | ||
) | ||
) | ||
); | ||
|
||
string memory finalTokenUri = string( | ||
abi.encodePacked("data:application/json;base64,", json) | ||
); | ||
|
||
return finalTokenUri; | ||
} | ||
|
||
function getTotalNFTsMintedSoFar() public view returns (uint256) { | ||
return _tokenIds.current(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
from brownie import SismondiNFT, network, config, accounts, chain | ||
|
||
import logging, sys | ||
logging.basicConfig(filename='operations.log', encoding='utf-8', level=logging.INFO) | ||
|
||
if network.show_active() == "development": | ||
account = accounts[0] | ||
else: | ||
account = accounts.add(config["wallets"]["from_key"]) | ||
|
||
def log(txt): | ||
print(txt) | ||
logging.info(txt) | ||
|
||
def deploy(): | ||
sismondi_contract = SismondiNFT.deploy( | ||
{"from": account}, | ||
publish_source=config["networks"][network.show_active()].get("verify") | ||
) | ||
log(f"contract has been deployed successfully to : {sismondi_contract.address}") | ||
return sismondi_contract | ||
|
||
def mint(addr): | ||
sismondi_contract = SismondiNFT.at(addr) | ||
nft = sismondi_contract.makeSismondiNFT({'from': account}) | ||
nft_id = nft.events['NewSismondiNFTMinted']['tokenId'] | ||
log(f"A new NFT with id {nft_id} has been successfully created in block {nft.block_number} with transaction {nft.txid}") | ||
return nft | ||
|
||
def main(): | ||
contract = deploy() | ||
print("\n---\n") | ||
nft = mint(contract.address) | ||
print("\n---\n") | ||
nft = mint(contract.address) |