Skip to content

Commit

Permalink
Improvements _after_ the show
Browse files Browse the repository at this point in the history
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
ineiti committed Jan 10, 2024
1 parent 9a24d8b commit bdf253f
Show file tree
Hide file tree
Showing 7 changed files with 150 additions and 16 deletions.
19 changes: 9 additions & 10 deletions contracts/SismondiNFT.sol

Large diffs are not rendered by default.

18 changes: 18 additions & 0 deletions scripts/SismondiNFT_1.sol
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 =
3 changes: 3 additions & 0 deletions scripts/SismondiNFT_2.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
;

string[] images = [
67 changes: 67 additions & 0 deletions scripts/SismondiNFT_3.sol
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();
}
}
19 changes: 15 additions & 4 deletions scripts/images.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,18 @@ def get_common(images):


prefix, images_short = get_common(images_long)
print("Prefix is:")
print(prefix)
print("Images are:")
print(",\n".join(images_short))

nft_parts_prefix = os.path.join(os.path.dirname(__file__), "SismondiNFT_")
with open(os.path.join(image_dir, "..", "contracts", "SismondiNFT.sol"), "w") as nft:
with open(f"{nft_parts_prefix}1.sol") as pre:
nft.write(pre.read())

nft.write(prefix)
with open(f"{nft_parts_prefix}2.sol") as middle:
nft.write(middle.read())

nft.write(",\n".join(images_short))
with open(f"{nft_parts_prefix}3.sol") as end:
nft.write(end.read())

print("../contracts/SismondiNFT.sol has been rewritten.")
5 changes: 3 additions & 2 deletions scripts/sismondi.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
from brownie import SismondiNFT, network, config, accounts, chain
priority = 5_000_000_000
network.priority_fee(priority)
network.max_fee(chain.base_fee + priority)

import logging, sys
logging.basicConfig(filename='operations.log', encoding='utf-8', level=logging.INFO)
Expand Down Expand Up @@ -31,10 +34,8 @@ def deploy_mint():
contract = deploy()
print("\n---\n")
nft = mint(contract.address)
log(f"{nft.events}")
print("\n---\n")
nft = mint(contract.address)
log(f"{nft.events}")

def main():
print("Please choose one of the following actions:")
Expand Down
35 changes: 35 additions & 0 deletions scripts/sismondi_test.py
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)

0 comments on commit bdf253f

Please sign in to comment.