Here we go again.
I've been studying NFT contracts and I've written one of my own. Going to break it down line by line.
Nothing fancy just playing around with ERC721 functions.
I hope you guys enjoy and learn as much as I did.
#Solidity #NFT #Contract #etherum #ftm #eth
1//
Declare the license that you will be using.
2//
Define the version of solidity that you will be using, we do this by using 'pragma'

^ These two lines of code will go in to every contract you write. make friends with them. kisssh.
4 & 5/
The 'import' statement allows you to pull in libraries and use them in your code.
The good people at @OpenZeppelin provide tested secured packages.
Why rebuild a minting function when you can just pull in already tested secure code?
Truly doing the lords work.
In the first line I am pulling in the ERC721 contract so that we can mint our NFT

In the second line I'm pulling in the the Ownable function, we could just use a require function to set the owner but this contract will more have robust logic to protect against security risks.
7/
Here we declare our contract and we can use 'is' to inherit the ERC720 and Ownable contracts and use them inside 'SimpleMint'
Now we can declare our Variables.
9/ this var sets our mint price declare this as a 'uint'.
10/ totalSupply will store the amount of NFTS minted.
11/ maxSupply will store the total number of NFTS in the collection
12/ 'bool' only returns true or false. this var will control mint on and off, when you don't specify its state it is automatically set to false.
13/mapping allows us to keep track of the wallets that have minted an NFT.
15/
A constructor is essentially a function that is activated on deployment.
we set it as payable
There is another constructor inside the ERC721 contract that we are calling, the constructor takes two string input the name of the NFT and the ticker.
ERC721 code attached
17/
Inside the constructor we we set our maxSupply to 2, set the number low so you can set all the functions were about to declare.
18/
This function can only be called by the owner of the contract, we are using code inside of the ownable contract that we have imported.
The function is set to external as it can only be accessed externally and not be called from an internal function.
19/
This function will be used to switch the state of the bool variable to true, thus turning the minting on.
23/
This function is almost like a back door which you wouldn't really want in your actual project, unless you want to change the max supply.
27/ 'mint' our final function which will be called externally and will be payable which means we can send ether to it.
we will run our check inside this function to ensure the wallet meets our requirements before we mint.
28/
First we check to see if mint is turned on.
29/
we're only going to allow 1 wallet per mint, we do this using our mapping var to ensure the wallet hasn't already minted
30/
next we need that to ensure the the ether sent to our wallet equals the 'mintPrice'
31/
Our final require statment will check to ensure the total supply is not greater than max supply, if it is then we have sold out.
32/
next we increase the mintedWallets mapping with the senders wallet address.
33/
Increase the total supply variable by 1 using '++'
34/
we're declaring a uint named 'tokenId' and storing it inside the 'totalSupply' variable.
35//
The '_safeMint' function is pulled form the ERC721 contract we imported.
This allows us to to safely mint our NFT and pass in the senders address along with our tokenId.
Annnnnd thats it folks. a very very simple ERC721 contract where you can mint 2 NFTS.
feel free to copy this code in to remix.ethereum.org and testing it.

• • •

Missing some Tweet in this thread? You can try to force a refresh
 

Keep Current with Kevin Barker | Byte Masons

Kevin Barker | Byte Masons Profile picture

Stay in touch and get notified when new unrolls are available from this author!

Read all threads

This Thread may be Removed Anytime!

PDF

Twitter may remove this content at anytime! Save it as PDF for later use!

Try unrolling a thread yourself!

how to unroll video
  1. Follow @ThreadReaderApp to mention us!

  2. From a Twitter thread mention us with a keyword "unroll"
@threadreaderapp unroll

Practice here first or read more on our help page!

More from @KevinBarker1111

Feb 26
1/5
@Bytemasons LBP Launch link below.

We are almost ready for action, and swapping will be enabled today at 10AM PST/6PM UTC and end at the same time on 3/1/2022.

What’s a LBP? beets.fi/#/lge/0x2dbd75…
2/5
A Liquidity Bootstrapping Pool, is a price discovery mechanism created by Balancer Labs on $ETH and enabled by Beethoven-X here on $FTM. It's designed to rebalance the liquidity pool over time from a very high ratio of the native token (85% $OATH) to a normal one (50% $OATH).
3/
re-weighting will cause price decay over time, as pictured in the curve below. Any purchases made during the length of the event will increase the price floor and flatten the curve. At the end of the LBP, we will have achieved a pretty accurate token price. Next stop, market
Read 5 tweets

Did Thread Reader help you today?

Support us! We are indie developers!


This site is made by just two indie developers on a laptop doing marketing, support and development! Read more about the story.

Become a Premium Member ($3/month or $30/year) and get exclusive features!

Become Premium

Don't want to be a Premium member but still want to support us?

Make a small donation by buying us coffee ($5) or help with server cost ($10)

Donate via Paypal

Or Donate anonymously using crypto!

Ethereum

0xfe58350B80634f60Fa6Dc149a72b4DFbc17D341E copy

Bitcoin

3ATGMxNzCUFzxpMCHL5sWSt4DVtS8UqXpi copy

Thank you for your support!

Follow Us on Twitter!

:(