Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

initial mints to owner #39

Closed
mpixelz opened this issue Feb 26, 2022 · 12 comments
Closed

initial mints to owner #39

mpixelz opened this issue Feb 26, 2022 · 12 comments

Comments

@mpixelz
Copy link

mpixelz commented Feb 26, 2022

Hi,
As previously.. i asked the same question but assuming things have changed with this new package. As there are new terminal commands and different loops in them..
how can i make it so that when the contract is deployed, initial 10 nfts are automatically minted to owner..
we are looking to secure the initial mints on deployment for 2 main reasons..

  1. It will start populating on opensea right away.
  2. We will have some nfts available for giveaways for promotions.
    please let me know what would be the best way to accomplish it.
    Thanks.
@gitrevo
Copy link

gitrevo commented Feb 26, 2022

Hi @mpixelz

You can mint via etherscan as soon as you deployed and verified your contract using the ‘Write Contract’ feature. Please be sure to use the owner wallet address when you mint them.

@mpixelz
Copy link
Author

mpixelz commented Feb 26, 2022

Hi,
Yeah i know that can be done.. but i was hoping to get a solution where this is done as part of the contract itself.
thanks thou :)

@liarco
Copy link
Member

liarco commented Feb 26, 2022

Hi @mpixelz,
If you really need this, then I suggest testing this code:

  /*
   * DISCLAIMER: please test this code on a test network
   * before deploying your final contract.
   * 
   * Usage without proper testing is at your own risk.
   */
  constructor(
    string memory _tokenName,
    string memory _tokenSymbol,
    uint256 _cost,
    uint256 _maxSupply,
    uint256 _maxMintAmountPerTx,
    string memory _hiddenMetadataUri
  ) ERC721(_tokenName, _tokenSymbol) {
    cost = _cost;
    maxSupply = _maxSupply;
    maxMintAmountPerTx = _maxMintAmountPerTx;
    setHiddenMetadataUri(_hiddenMetadataUri);

    // Reserve initial tokens for giveaways and rewards...
    _mintLoop(msg.sender, 10);
  }

@ghost
Copy link

ghost commented Feb 26, 2022

@liarco makes a good point about testing. For any new features, it would be great to have a test added to this file: https://github.com/hashlips-lab/nft-erc721-collection/blob/main/smart-contract/test/index.ts

I'm not too familiar with Javascript so hard for me to contribute example.

@mpixelz If you look here at Cool Cats contract, they have a similar example in constructor with dedicated addresses:

    // withdraw addresses
    address t1 = 0xfc86A64a8DE22CF25410F7601AcBd8d6630Da93D;
    address t2 = 0x4265de963cdd60629d03FEE2cd3285e6d5ff6015;
    address t3 = 0x1b33EBa79c4DD7243E5a3456fc497b930Db054b2;
    address t4 = 0x92d79ccaCE3FC606845f3A66c9AeD75d8e5487A9;

    // Cool Cats are so cool they dont need a lots of complicated code :)
    // 9999 cats in total, cos cats have 9 lives
    constructor(string memory baseURI) ERC721("Cool Cats", "COOL")  {
        setBaseURI(baseURI);

        // team gets the first 4 cats
        _safeMint( t1, 0);
        _safeMint( t2, 1);
        _safeMint( t3, 2);
        _safeMint( t4, 3);
    }

@liarco
Copy link
Member

liarco commented Feb 27, 2022

@liarco makes a good point about testing. For any new features, it would be great to have a test added to this file: https://github.com/hashlips-lab/nft-erc721-collection/blob/main/smart-contract/test/index.ts

I'm not too familiar with Javascript so hard for me to contribute example.

Thank you for your suggestion, this is a diff file for the complete change:

diff --git a/smart-contract/contracts/YourNftToken.sol b/smart-contract/contracts/YourNftToken.sol
index 2c77d74..e86b002 100644
--- a/smart-contract/contracts/YourNftToken.sol
+++ b/smart-contract/contracts/YourNftToken.sol
@@ -42,6 +42,9 @@ contract YourNftToken is ERC721, Ownable, ReentrancyGuard {
     maxSupply = _maxSupply;
     maxMintAmountPerTx = _maxMintAmountPerTx;
     setHiddenMetadataUri(_hiddenMetadataUri);
+
+    // Reserve initial tokens for giveaways and rewards...
+    _mintLoop(msg.sender, 10);
   }
 
   modifier mintCompliance(uint256 _mintAmount) {
diff --git a/smart-contract/test/index.ts b/smart-contract/test/index.ts
index 739a382..8d17224 100644
--- a/smart-contract/test/index.ts
+++ b/smart-contract/test/index.ts
@@ -69,7 +69,9 @@ describe(CollectionConfig.contractName, function () {
     expect(await contract.whitelistMintEnabled()).to.equal(false);
     expect(await contract.revealed()).to.equal(false);
 
-    await expect(contract.tokenURI(1)).to.be.revertedWith('ERC721Metadata: URI query for nonexistent token');
+    expect(await contract.tokenURI(1)).to.equal(CollectionConfig.hiddenMetadataUri);
+    expect(await contract.tokenURI(10)).to.equal(CollectionConfig.hiddenMetadataUri);
+    await expect(contract.tokenURI(11)).to.be.revertedWith('ERC721Metadata: URI query for nonexistent token');
   });
 
   it('Before any sale', async function () {
@@ -91,7 +93,7 @@ describe(CollectionConfig.contractName, function () {
     )).to.be.revertedWith('Invalid mint amount!');
 
     // Check balances
-    expect(await contract.balanceOf(await owner.getAddress())).to.equal(1);
+    expect(await contract.balanceOf(await owner.getAddress())).to.equal(11);
     expect(await contract.balanceOf(await whitelistedUser.getAddress())).to.equal(1);
     expect(await contract.balanceOf(await holder.getAddress())).to.equal(0);
     expect(await contract.balanceOf(await externalUser.getAddress())).to.equal(0);
@@ -154,7 +156,7 @@ describe(CollectionConfig.contractName, function () {
     await contract.setCost(utils.parseEther(CollectionConfig.preSale.price.toString()));
 
     // Check balances
-    expect(await contract.balanceOf(await owner.getAddress())).to.equal(1);
+    expect(await contract.balanceOf(await owner.getAddress())).to.equal(11);
     expect(await contract.balanceOf(await whitelistedUser.getAddress())).to.equal(2);
     expect(await contract.balanceOf(await holder.getAddress())).to.equal(0);
     expect(await contract.balanceOf(await externalUser.getAddress())).to.equal(0);
@@ -214,15 +216,25 @@ describe(CollectionConfig.contractName, function () {
   it('Wallet of owner', async function () {
     expect(await contract.walletOfOwner(await owner.getAddress())).deep.equal([
       BigNumber.from(1),
-    ]);
-    expect(await contract.walletOfOwner(await whitelistedUser.getAddress())).deep.equal([
       BigNumber.from(2),
       BigNumber.from(3),
+      BigNumber.from(4),
+      BigNumber.from(5),
       BigNumber.from(6),
+      BigNumber.from(7),
+      BigNumber.from(8),
+      BigNumber.from(9),
+      BigNumber.from(10),
+      BigNumber.from(11),
+    ]);
+    expect(await contract.walletOfOwner(await whitelistedUser.getAddress())).deep.equal([
+      BigNumber.from(12),
+      BigNumber.from(13),
+      BigNumber.from(16),
     ]);
     expect(await contract.walletOfOwner(await holder.getAddress())).deep.equal([
-      BigNumber.from(4),
-      BigNumber.from(5),
+      BigNumber.from(14),
+      BigNumber.from(15),
     ]);
     expect(await contract.walletOfOwner(await externalUser.getAddress())).deep.equal([]);
   });
@@ -232,7 +244,7 @@ describe(CollectionConfig.contractName, function () {
       this.skip();
     }
 
-    const alreadyMinted = 6;
+    const alreadyMinted = 16;
     const maxMintAmountPerTx = 1000;
     const iterations = Math.floor((CollectionConfig.maxSupply - alreadyMinted) / maxMintAmountPerTx);
     const expectedTotalSupply = iterations * maxMintAmountPerTx + alreadyMinted;

You can replicate the changes manually or use the git-apply command to apply everything automatically.

@liarco liarco added the feedback requested To be closed if no feedback is received label Feb 27, 2022
@ghost
Copy link

ghost commented Feb 27, 2022

@liarco Thank you! Btw, I didn't mean for you to contribute the testing example. I was just trying to teach others that a test file exists and its good idea to update it when adding new features.

Anyway, I guess this was easy for you to do. Sorry if too much time taken by my comment.

@liarco
Copy link
Member

liarco commented Feb 27, 2022

Don't worry @spike-hue, all good! 😉

I did that because I thought it was a good idea to have an example, this may also be useful as future reference.

@liarco
Copy link
Member

liarco commented Mar 2, 2022

Closing for inactivity.

@liarco liarco closed this as completed Mar 2, 2022
@liarco liarco removed the feedback requested To be closed if no feedback is received label Mar 2, 2022
@mpixelz
Copy link
Author

mpixelz commented Mar 10, 2022

Hi @mpixelz, If you really need this, then I suggest testing this code:

  /*
   * DISCLAIMER: please test this code on a test network
   * before deploying your final contract.
   * 
   * Usage without proper testing is at your own risk.
   */
  constructor(
    string memory _tokenName,
    string memory _tokenSymbol,
    uint256 _cost,
    uint256 _maxSupply,
    uint256 _maxMintAmountPerTx,
    string memory _hiddenMetadataUri
  ) ERC721(_tokenName, _tokenSymbol) {
    cost = _cost;
    maxSupply = _maxSupply;
    maxMintAmountPerTx = _maxMintAmountPerTx;
    setHiddenMetadataUri(_hiddenMetadataUri);

    // Reserve initial tokens for giveaways and rewards...
    _mintLoop(msg.sender, 10);
  }

Hi
i tried the above but i keep getting an error: Undeclared identifier. on _mintLoop(msg.sender, 10);

@liarco
Copy link
Member

liarco commented Mar 10, 2022

Hi @mpixelz, that's because that specific code used version 1.0.0+, here is an updated example for 2.0.0:

  /*
   * DISCLAIMER: please test this code on a test network
   * before deploying your final contract.
   * 
   * Usage without proper testing is at your own risk.
   */
  constructor(
    string memory _tokenName,
    string memory _tokenSymbol,
    uint256 _cost,
    uint256 _maxSupply,
    uint256 _maxMintAmountPerTx,
    string memory _hiddenMetadataUri
  ) ERC721(_tokenName, _tokenSymbol) {
    cost = _cost;
    maxSupply = _maxSupply;
    maxMintAmountPerTx = _maxMintAmountPerTx;
    setHiddenMetadataUri(_hiddenMetadataUri);

    // Reserve initial tokens for giveaways and rewards...
    _safeMint(msg.sender, 10);
  }

Let me know if it works now...

@gitrevo
Copy link

gitrevo commented Apr 25, 2022

Hi @mpixelz, that's because that specific code used version 1.0.0+, here is an updated example for 2.0.0:

  /*
   * DISCLAIMER: please test this code on a test network
   * before deploying your final contract.
   * 
   * Usage without proper testing is at your own risk.
   */
  constructor(
    string memory _tokenName,
    string memory _tokenSymbol,
    uint256 _cost,
    uint256 _maxSupply,
    uint256 _maxMintAmountPerTx,
    string memory _hiddenMetadataUri
  ) ERC721(_tokenName, _tokenSymbol) {
    cost = _cost;
    maxSupply = _maxSupply;
    maxMintAmountPerTx = _maxMintAmountPerTx;
    setHiddenMetadataUri(_hiddenMetadataUri);

    // Reserve initial tokens for giveaways and rewards...
    _safeMint(msg.sender, 10);
  }

Let me know if it works now...

Will this work on the ERC721A new contract too?

@Niviere
Copy link

Niviere commented Jun 12, 2022

constructor(
string memory _name,
string memory _symbol,
string memory _initBaseURI,
string memory _initNotRevealedUri
) ERC721(_name, _symbol) {
setBaseURI(_initBaseURI);
setNotRevealedURI(_initNotRevealedUri);

_safeMint(msg.sender, 10);
}

when i set it like this it says the total of mints i have in my wallet is only one, im trying to mint 10 or more. Pls help

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants