Skip to content

Machovsky/ethereum-contracts

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

13 Commits
 
 
 
 
 
 

Repository files navigation

Read me first!!!

Disclaimer: You are using this contract on your own responsibility. I can help, but I don't take any responsibility if anything won't work during the mint. Hello everyone welcomy to my github. I created low gas optimized ERC721 contract for Ethereum network. Here you can find little tutorial how to use it. If any help will be needed, feel free to ask me on discord arczi.eth#7777

What are this contracts about?

ContractNFTLowGasERC721A.sol - ERC721A optimized contract with lower gas fees. This contract will let you create mint which has: 2 stages - first for example free mint, second with paid mints

To give you better example - you have 5000 NFT collection. With this contract you can make free mint for first 2000 NFTs and then 3000 paid mints.

Costs of mint in both phases, amount of mints per tx for both phases, amount of mints per wallet, total supply, mint pause and reveal after mint are fully configurable!

Tutorial of how to configure everything you can find below in next README chapters.

How to prepare contract for your project?

First thing - go to Remix https://remix.ethereum.org/ and create a new workspace

image

Then delete all files inside folders in your workspace:

image

It should look like this and be empty:

image

Then, add downloaded NFT contract - for this case we will use SampleNFTLowGas.sol contract. Open it and copy whole code from inside, then go back to remix and paste your code there as new file into "contracts" folder. After you paste file content, press ctrl+s to run compiler. You will see that compiler will process everything and create a bunch of new files. Don't worry about them. It should look like this:

image

If you have done everything correctly and you have same result as me, go to the code you pasted, starting from line 12. That will be only changes that you want to change in the contract. image

To summary a little - this is just example. I will create a bunch of contracts - separated for phases with different prices and others which have always the same price. Limited for amount of mints per wallet per phase etc. Don't bother about it now. If you want some other behavior and you don't know how to do that, just write straight to me on discord - https://discord.com/users/arczi.eth#7777

For this example cost1 - cost of phase 1

cost2 - cost of phase 2

supplyPhase1 - supply for phase 1 (amount of mints you wan't to sell using cost1)

totalSupply - whole supply of NFT collection

maxMintAmountPerTxPhase1 - mint amount per transaction with phase 1 cost

maxMintAmountPerTxPhase2 - mint amount per transaction with regular cost

maxLimitPerWallet - mint amount per wallet (for example if maxAmountPerTx is 10 and maxLimitPerWallet is 20, then you can mint 2 times 10 NFT's per transaction)

sale - if sale is set to false it means, that contract is paused automatically. Let it like it is. We will change that when we will start mint.

revealed - if revealed is set to false it means that you want to leave nft hidden using separate image.

Next part that you have to change is constructor part - that strings (the orange color). Leave " as they are, but change what is inside. First one is full name of your NFT collection. Second one is short name - best practice is to use 3 big letters for it. For example when we have something like AI Goblins, as short name use AIG letters.

image

If everything is done and saved by clicking ctrl+s, go to the left menu and choose this icon.

image

Set compiler to newest one. Check "Auto compile" checkbox, then expand advanced options and check "Enable optimization" checkbox with value set to 200.

image

If all works fine, go to left panel document view, find again your file and right click, choosing "Flatten" option.

image

After few second you will find flattener pop-up window. Click on "Accept"

image

After you accept that, you will see that a lot of new items were created. At the bottom of your files you will find new .sol file, called as your previous file but with added _flat in name.

image

Click on that file - you will see red exclamation mark in first line.

image

Add there code: // SPDX-License-Identifier: MIT

copy it with "//" sign.

Now error is gone and we don't have any additional errors to fix.

image

Your contract is ready to deploy! :)

How to approve contract?

After you have done all of above steps, it's time for contract deploy and getting an approval from etherscan! First thing to do now - go to "Deploy & Run transaction" and then choose "Injected Web3" from environment dropdown - remember to have the correct wallet chosen. The wallet which is connected to the site will be owner of the contract and after mint all money will be transferred back to wallet which is the contract owner. Just for this tutorial I will use rinkeby testnet just to show you how to proceed all the stuff on your ethereum mainnet. All will look the same! :)

image

Remember to pick correct contract by choosing "ContractName - FileName.sol" like the one on screen below.

image

As a next step click on expand button next to orange "Deploy" button.

image

As you can see there are 2 empty fields that we have to fill up. I assume that you have already your NFT collection created and you have ipfs CID's to folder with collection and to separate hidden NFT if you want to make a reveal after some time. That empty fields that we have to fill should look like that.

image

First field is called URI. We need to add there ipfs address to our folder with whole collection metadata (.json files). It should be in this format: ipfs://HerePasteYourCIDAddressToFolderWithWholeCollectionMetadata/ - remember about / at the end of uri. Metadata folder means whole folder with .json files.

Next field is HiddenMetadataUri is field where you add ipfs address to folder with hidden metadata files. Probably it will be only 1 picture but it have to be pasted separately. Format should look the same way: ipfs://HerePasteYourCIDAddressToFolderWithHiddenImageMetadata/

If you are not going to make a reveal, just leave this field empty and verify if you changed variable "revealed" to "true".

image

If you have done this, don't click "Transact" yet. First click on copy button next to transact:

image

Open notepad or some document editor and paste what you have copied. It will look similar to this:

image

After you done this, save it somewhere not to lose it and now you can click "Transact"

image

After you click it, you will see metamask notification to create a contract. After you approve this, your contract will be created and wallet that you used will be the owner of the contract.

image

At the bottom of remix ide, you will see that contract was deployed. Just click on button to expand and then click on copy button next to contract again:

image

Do the same as before - paste it to some file. This is your contract address which you can find already on etherscan. If you have your address copied, go now to etherscan and search for the contract.

image

You will see there whole information about the contract and also the only transaction which was creation of contract.

image

Go now to "Contract" page:

image

Then click "Verify and Publish" to verify your contract.

image

On the next page we need to pick some options about our contract.

  1. Compiler type - we are using flattened version of the contract. That means all libraries are "packed" into one file. In that case we pick here "Solidity (Single file)" option

  2. Compiler version - should be the same as in compiler tab in Remix IDE - automatically probably newest one. If you used different version, just change it to the one you have used.

  3. License - we pick MIT license.

image

After all is done, click on "Continue".

On the next page we will see window with "Contract Source Code". It should be configured like that:

  1. On the top right corner you will see "Optimization" - change it to "Yes" as you had "Enable optimization" checkbox in remix checked.
  2. In field "Enter the Solidity Contract Code below" you have to paste whole code from remix. It will have more or less about 2k lines, so just click ctrl+a to select all and then ctrl+c to copy whole contract.
  3. Next field is "Constructor Arguments ABI-encoded". My contract will be using constructors so this field needs to be filled automatically. If it is not, I will show you how to get it. In next step.

Finally all should look like this:

image

If you don't have ABI filled up automatically, go back to remix to your opened contract, change tab back to "Compiler", change contract to correct one and copy the "ABI" by clicking button visible on the screen:

image

Then go to page https://abi.hashex.org/ Paste whole contract ABI there and click on "Parse".

image

Pick function as "constructor". Then you will see 2 fields - URI and hiddenMetadataUri. You have to paste them your code in the same format as you did previously in remix:

image

^ it should be the same as this:

image

After you do it, you will see your constructor ABI encoded. Just copy it and paste on etherscan :)

One more thing - the same you can find just in your copied encoded number that we pasted to notepad. At the end of the string you will see that it have a lot of 0's. Just try to copy it starting from the first zero if you have any problems using ABI encoder.

image

Let's continue with etherscan. If you have your ABI there, just click on "Verify and Publish".

image

If everything is okay, you will see such screen with message: "Successfully generated ByteCode and ABI for Contract Address"

image

Congratulations! You have verified your contract! :)

If you go back to your contract, now you will see that it has green check.

image

How to start minting or change anything on the contract?

So now let's focus on mint management. Contract is paused by default. If you want to unlock your mint just go to etherscan, then pick "Contract" tab and then "Write contract". Below you will see "Connect to web3" button. Click it and connect to your wallet which is owner of the contract.

image

Connected wallet should look like that:

image

Now you have bunch of options there where you can manage your whole contract.

image

1. Airdrop of NFT's. If you want to airdrop NFT's to some wallet, just use "Airdrop" function. In mintAmount type amounts of NFT's you want to drop, and in receiver just write address that should be airdropped. After that click on "Write" and confirm transaction on Metamask.

image

2. Unlock minting option. If you have mint paused, you can unlock it by searching for "SetSaleStatus" function. Expand it and write "true" if you want to unlock minting. Then click on "Write" and confirm your action on MetaMask.

image

3. Changing the price. If you want to change the price during mint just find option "setcost1" or "setcost2" (in this case. some contracts will have only one cost). Again expand that function and set cost as you wish. Remember that price is not in ethers!!! It uses wei instead!!! For example if price is set to 0.003 ethers it is saved as 3000000000000000 wei. If you want to change your price, just go to https://eth-converter.com/ and there you can convert your price from ethers to wei.

image

How to withdraw money?

That's the most important part for every NFT creator :D In contract you will find function "Withdraw" If you want to withdraw your money, just expand the function, click on write and confirm transaction on metamask.

image

You will have to use owner wallet to do all that transactions. If you try to use other wallet you will get error:

image

So after transaction is approved, money will be automatically transferred to the adress you are using.

Good luck with your projects! :)