![]() |
|
Create Your Own NFT - ERC721 Solidity Smart Contract - Printable Version +- Hack Forums (https://hackforums.net) +-- Forum: Money (https://hackforums.net/forumdisplay.php?fid=241) +--- Forum: Crypto Currency (https://hackforums.net/forumdisplay.php?fid=380) +--- Thread: Create Your Own NFT - ERC721 Solidity Smart Contract (/showthread.php?tid=6271201) |
Create Your Own NFT - ERC721 Solidity Smart Contract - Hackers - May 16, 2024 ![]() Today you will learn how to create an ERC-721 smart contract. This is meant for Ethereum/EVM-based blockchain tokens, using Solidity as the core language. This is a basic example to help you get started, but does work as-is. You can deploy the contract and as the owner, you can mint NFTs to other addresses. The contract below (source code in spoiler at end of post) does not include IPFS or other onchain data, but instead acts as a mechanism to distribute tokens. You can use these tokens however you wish in external systems, such as using them for access, memberships, real-world representations, or other use cases. Feel free to add on features and extend this base contract however you wish to implement custom functions! ![]() Code // SPDX-License-Identifier: MITCode import "@openzeppelin/contracts/token/ERC721/ERC721.sol";We use Ownable to enforce on-chain security for token ownership so people can't manage other people's tokens and to keep things secure. Code contract FallenExampleERC721 is ERC721, Ownable {Code uint256 private _tokenIdCounter;Code constructor() ERC721("FallenExampleERC721", "FE721") {}Code function safeMint(address to) public onlyOwner {We set the token ID to the current token ID count, which is the newest #, starting from 1 on first mint, then 2, 3, and so on. We then increment the token id counter before we mint , so that the count is already +1 for the next mint that occurs on the contract. This is a safeguard / best practice to update data related to mints before the mint. The same is true if you are deducting balances - deduct from contract balance before sending. This is due to a thing called reentrancy but I won't go deep into that here. Just know that you should follow this rule 100% of the time. The _safeMint function corresponds to an openzeppelin method to mint the NFT to the destination address, for the new token ID. ![]() Full source code: Spoiler (Click to View) Looking for more? Check this out: https://hackforums.net/showthread.php?tid=6271197 RE: Create Your Own NFT - ERC721 Solidity Smart Contract - Vеrt - May 16, 2024 What an informative thread. Great job explaining everything. RE: Create Your Own NFT - ERC721 Solidity Smart Contract - Hackers - May 16, 2024 (May 16, 2024 06:27 AM)Vеrt Wrote: What an informative thread. Great job explaining everything. Thanks, hope this helps someone. Many people don't realize how easy it is to get started w/ this stuff. The contracts for the most basic versions of NFTs or other token types can be written with a very small amount of code. RE: Create Your Own NFT - ERC721 Solidity Smart Contract - LeetSpeed - May 16, 2024 Thanks for this! This is valuable information! RE: Create Your Own NFT - ERC721 Solidity Smart Contract - Hackers - May 16, 2024 (May 16, 2024 09:58 AM)LeetSpeed Wrote: Thanks for this! This is valuable information! You are welcome! Have you written much Solidity in the past? RE: Create Your Own NFT - ERC721 Solidity Smart Contract - idalistrades - May 16, 2024 Thank you I plan to use this for my NFT game in the future RE: Create Your Own NFT - ERC721 Solidity Smart Contract - 7 - May 16, 2024 Another mind blowing thread nodes! Great information, looking forward to understanding this by practise RE: Create Your Own NFT - ERC721 Solidity Smart Contract - LeetSpeed - May 16, 2024 (May 16, 2024 04:41 PM)nodes Wrote: You are welcome! No not too much. RE: Create Your Own NFT - ERC721 Solidity Smart Contract - Hackers - May 17, 2024 (May 16, 2024 04:50 PM)FemaleAI_CEO Wrote: Thank you awesome! You should look into ERC 1155 too because you can do batch minting which may be better and it works very similarly. (May 16, 2024 05:51 PM)NulldB Wrote: Another mind blowing thread nodes! Thank you! If you want to chat about anything just let me know (May 16, 2024 09:27 PM)LeetSpeed Wrote: No not too much. Ah, not too hard to get into, but it does help if you have prior programming experience of some sort. A cool language though and easier to bug test / fix than others in my opinion because of how strict Solidity is with types & logic. RE: Create Your Own NFT - ERC721 Solidity Smart Contract - crocsss - May 20, 2024 excuse me can i send you a pm on discord? RE: Create Your Own NFT - ERC721 Solidity Smart Contract - LeetSpeed - May 22, 2024 (May 17, 2024 04:45 AM)nodes Wrote: awesome! You should look into ERC 1155 too because you can do batch minting which may be better and it works very similarly. We'll be in contact I have a few questions for you. RE: Create Your Own NFT - ERC721 Solidity Smart Contract - Hackers - May 22, 2024 (May 20, 2024 11:11 AM)crocsss Wrote: excuse me can i send you a pm on discord? please reply in this thread or message onsite. (May 22, 2024 09:32 AM)LeetSpeed Wrote: We'll be in contact I have a few questions for you. no problem, feel free to reachout via convo or reply here! RE: Create Your Own NFT - ERC721 Solidity Smart Contract - Absence - May 22, 2024 Thank you for another high quality contribution Hackers RE: Create Your Own NFT - ERC721 Solidity Smart Contract - Hackers - May 24, 2024 (May 22, 2024 09:48 AM)Absence Wrote: Thank you for another high quality contribution Hackers thanks Absence, let me know if you want help w/ anything. I don't do as much web3/blockchain work in the last few months but figure I should practice with a couple contracts every couple of months so I don't lose knowledge about this stuff. I'm not a huge fan of the average NFT, but the technology itself can be very useful in real world for digitalized asset ownership & more. I'm sure as AI takes off we'll see more and more crypto-based microservices and tokenized access passes. |