GenSOL is a ERC-721 contract for generative art. Written in Solidity, it is designed to be used with the Foundry framework.
- On-chain metadata (base64 encoded JSON)
- Ability to set maximum supply
- Art is generated from account + token ID + block number
- Contract URI
Generative.sol- The main contractBaseGen.sol- The base contract for generative artBaseTokenGen.sol- The base contract but payable with ERC-20 tokens
In case of BaseGen.sol we need to define a set of parameters (see script/BaseGen.s.sol)
address initialOwner = vm.addr(deployerPrivateKey);
string memory name = "Koda.";
string memory symbol = "KODA";
string memory contractURI = "ipfs://bafkreige4zmihk32by3n5aeoq7svlqeyhoaapt4l7hoyspsnr2hm7ljjgq";
string memory baseURI = "https://dyndata.deno.dev/base/content/";
uint256 maxSupply = 64;
address receiver = 0xE844b2a0a6453250c920BD2b4B7741946aB16C08;
BaseGen nft = new BaseGen(initialOwner, name, symbol, contractURI, baseURI, maxSupply, receiver);As you may know from other NFT Galleries
contractURIis a link to the contract metadatanameandsymbolare from the ERC-721 standardbaseURIis a link to the token metadata- it is used to generate the
tokenURI-baseURI/address(this)/tokenId- whereaddress(this)is the contract address - we leverage vikiival/dyndata to generate the metadata
- it is used to generate the
maxSupplyis the maximum number of tokens that can be mintedreceiveris the address that will receive the funds from the minting
Important
The receiver address is a recipient of 5% royalties
Function safeMint is payable - you need to send 0.0015 ETH to mint a token
Tip
Last time I wrote a smart contract was in 2019. I am still learning new things in Solidity and code looks like a mess. I am open to any suggestions and improvements.
We use OpenZeppelin contracts for the ERC-721 implementation.
forge install OpenZeppelin/[email protected] --no-commitforge testYou can simulate a deployment by running the script:
forge script script/Generative.s.solTo deploy fully with a verification
source .env;
forge script script/BaseGen.s.sol:MyScript --rpc-url $RPC_URL --broadcast --verify -vvvvalternatively use just
just deployImportant
You need to have a .env file with the RPC_URL variable set.
Do not forget to obtain ehterscan or basescan API key and set it in the .env file.
See Solidity scripting guide for more information.
-
https://blog.thirdweb.com/guides/create-a-generative-art-nft-collection-using-solidity-javascript/
-
https://medium.com/coinmonks/creating-generative-art-nfts-with-python-solidity-a95eaeea515e
-
https://medium.com/quick-programming/how-to-implement-fully-on-chain-nft-contracts-8c409acc98b7
-
https://docs.alchemy.com/docs/how-to-make-nfts-with-on-chain-metadata-hardhat-and-javascript
-
https://stackoverflow.com/questions/71626871/why-is-my-nft-metadata-not-showing-on-opensea
-
https://medium.com/coinmonks/how-to-create-on-chain-nfts-with-solidity-1e20ff9dd87e
-
https://ethereum.stackexchange.com/questions/124874/nft-metatdata-not-showing-on-opensea
-
https://www.reddit.com/r/ethdev/comments/v13sk1/how_to_store_metadata_on_nfts_on_chain_and_how/