<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: alcrypto</title>
    <description>The latest articles on DEV Community by alcrypto (@alcrypto82).</description>
    <link>https://dev.to/alcrypto82</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F730218%2F57c28c9b-d32b-476c-8c37-8fa0e682cb77.png</url>
      <title>DEV Community: alcrypto</title>
      <link>https://dev.to/alcrypto82</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/alcrypto82"/>
    <language>en</language>
    <item>
      <title>I got it. My First Smart Contract - NFT Collection</title>
      <dc:creator>alcrypto</dc:creator>
      <pubDate>Tue, 19 Oct 2021 12:19:19 +0000</pubDate>
      <link>https://dev.to/alcrypto82/i-got-it-my-first-smart-contract-nft-collection-19gl</link>
      <guid>https://dev.to/alcrypto82/i-got-it-my-first-smart-contract-nft-collection-19gl</guid>
      <description>&lt;p&gt;I got it.&lt;/p&gt;

&lt;p&gt;Hello everybody.&lt;/p&gt;

&lt;p&gt;My aim is more to learn than to teach, so I don't want to spend too much time trying to explain something I still understand.&lt;/p&gt;

&lt;p&gt;anyway i am happy because i finished my first smart contract, and i would like to share it with you and who knows that may also serve as a basis for those who are starting.&lt;/p&gt;

&lt;p&gt;It's a pretty simple contract for my NFT collection, but apparently it's working.&lt;/p&gt;

&lt;p&gt;My idea now is to implement a function that donates part of sales to an institution against hunger. I will try to do this together with The Giving Block.&lt;/p&gt;

&lt;p&gt;Thanks for your time, hope this helps someone in some way and suggestions and constructive criticism are welcome.&lt;/p&gt;

&lt;p&gt;Sorry if I did something wrong when posting.&lt;/p&gt;

&lt;p&gt;A hug and be well&lt;/p&gt;

&lt;p&gt;The contract.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// SPDX-License-Identifier: GPL-3.0
pragma solidity &amp;gt;=0.7.0 &amp;lt;0.9.0;

import "@openzeppelin/contracts/token/ERC721/extensions/ERC721Enumerable.sol";
import "@openzeppelin/contracts/access/Ownable.sol";


contract Nft_Collection is ERC721Enumerable, Ownable {
    using Strings for uint256;

    string public baseURI;
    string public baseExtension = ".jason";
    uint256 public cost = 0.015 ether;
    uint256 public maxSupply = 3000;
    uint256 public maxMintAmount = 10;
    bool public paused = false;

    mapping(address =&amp;gt; uint256) public addressMintedBalance;


    constructor(string memory _name, string memory _symbol, string memory _initBaseUri) 
    ERC721(_name, _symbol) {setBaseURI(_initBaseUri); mint(msg.sender, 10);}

    function _baseURI() internal view virtual override returns (string memory) {
        return baseURI;
    }

    //public
    function mint(address, uint256 _mintAmount)  public payable {
        require(!paused, "the contract is paused");
        uint256 supply = totalSupply();
        require(_mintAmount &amp;gt; 0);
        require(_mintAmount &amp;lt;= maxMintAmount);
        require(supply + _mintAmount &amp;lt;= maxSupply);
        if (msg.sender != owner()) {
            require(msg.value &amp;gt;= cost * _mintAmount);
        }
        for (uint256 i = 1; i &amp;lt;= _mintAmount; i++) {
            addressMintedBalance[msg.sender]++;
            _safeMint(msg.sender, supply + i);
        }
    }

    function walletOfOwner (address _owner) public view returns (uint256[] memory) {
        uint256 ownerTokenCount = balanceOf (_owner);
        uint256[] memory tokenIds = new uint256[] (ownerTokenCount);
        for (uint256 i; i &amp;lt; ownerTokenCount; i++) {
            tokenIds[i] = tokenOfOwnerByIndex (_owner, i);
        }
        return tokenIds;
    }

    function tokenURI (uint256 tokenId) public view virtual override returns (string memory) {
        require(_exists(tokenId));
        string memory currentBaseURI = _baseURI();
        return bytes(currentBaseURI).length &amp;gt; 0 ? string(abi.encodePacked(currentBaseURI, tokenId.toString(), baseExtension)): "";
    }

    //only owner
    function setCost (uint256 _newCost) public onlyOwner() {
        cost = _newCost;
    }

    function setMinAmount (uint256 _newMaxMintAmount) public onlyOwner {
        maxMintAmount = _newMaxMintAmount;
    }

    function setBaseURI (string memory _newBaseURI) public onlyOwner {
        baseURI = _newBaseURI;
    }

    function setBaseExtension (string memory _newBaseExtesion) public onlyOwner {
        baseExtension = _newBaseExtesion;
    }

    function pause (bool _state) public onlyOwner {
        paused = _state;
    }

    function withdraw() public payable onlyOwner {
        require(payable(msg.sender).send(address(this).balance));
    }

}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



</description>
      <category>beginners</category>
      <category>blockchain</category>
      <category>nft</category>
    </item>
  </channel>
</rss>
