0

I am developing an NFT Marketplace where I am distributing free NFTs(out of 3 defined categories, Diamond,Gold,Silver). I have developed a dropsite smart contract for this distribution. The dropsite module will only be executed once like it will mint only 1000 NFTs then it will be closed.

After distribution, I want those NFTs to be usable on Marketplace contract. For this I want to send the ownerships of Distributed NFTs from Dropsite contract to Marketplace contract. SO that the user may send/transfer/sell those NFTs on marketplace.

How can I achieve this?

Here is my Dropsite minting Contract:

    //SPDX-License-Identifier:MIT
pragma solidity ^0.8.0;
pragma experimental ABIEncoderV2;
import "./ERC1155_Dropsite.sol"; 
contract Dropsite is ERC1155_Dropsite  { 

    //NFT category
    bytes  data ="";

    uint TotalNFTsMinted;     //Total NFTs
    uint numOfCopies;         //A user can mint only 1 NFT
    //Initial Minting
    uint Diamond;            
    uint Gold;
    uint Silver;

    //owner-NFT-ID Mapping
    mapping (address=>uint)  dropsite_NFT_Owner;
    //payments Mapping
     mapping (address => uint) deposits;
  modifier OnlyOwner {
        require(_msgSender() == Owner, "Only NFT-ES Owner can Access");
        _;
    }

    //Pausing and activating the contract
    modifier contractIsNotPaused(){
        require (IsPaused == false, "Dropsite is not Opened Yet." );
        _;
    }
      bool public IsPaused = true;
    address payable public  Owner;
    string private _name;
    
    constructor (string memory name){
        _name = name;
        Owner = payable(msg.sender);

        TotalNFTsMinted=0;     //Total NFTs Minted
        numOfCopies=1;         //A user can mint only 1 NFT
        Diamond=0;            
        Gold=0;
        Silver=0;
    }
     
     function checkMintedCategoryWise() public view OnlyOwner returns(uint,uint,uint){
         return (Diamond,Gold,Silver);
     }
    function checkTotalMinted() public view OnlyOwner returns(uint){
         return TotalNFTsMinted;
     }
     function stopDropsite() public OnlyOwner{
        require(IsPaused==false, "Dropsite is already Stopped");
        IsPaused=true;
    }

     function openDropsite() public OnlyOwner {
        require(IsPaused==true, "Dropsite is already Running");
        IsPaused=false;
    }
    
     //To WithDraw All Ammount from Contract to Owners Address 
    function withDraw(address payable to) public payable OnlyOwner {
        uint Balance = address(this).balance;
        require(Balance > 0 wei, "Error! No Balance to withdraw"); 
        to.transfer(Balance);
    }  
    
    //To Check Contract Balance in Wei
      function ContractBalance() public view OnlyOwner returns (uint){
        return address(this).balance;
    }

    function random() internal view returns (uint) {
        //Only Returns 0,1,2
    uint randomnumber = uint(keccak256(abi.encodePacked(block.timestamp, msg.sender))) % 3;
    return randomnumber;
    }

   function updateConditions(uint nftId) internal contractIsNotPaused {
           // if nftID is 0, and less than 51 so 50 MAX
           
    if(nftId == 0 && Diamond < 50) {
        data = "Diamond";
        Diamond++; 

    // if nftID is 0 or 1 and Diamond is more than 150, it will go there
    } else if(nftId <= 1 && Gold < 100) {
        data = "Gold";
        Gold++;

    // if any of the above conditions are filled it will mint silver if enough silver available
    } else if(nftId <= 2 && Silver <= 850) {
        data="Silver";
        Silver++;
    }
    else 
    revert("Some Error Occured");     
   }
    //Random minting after Fiat Payments
    function FiatrandomMint(address user_addr) OnlyOwner contractIsNotPaused public returns (uint,string memory) {
     require(TotalNFTsMinted<1000, "Max Minting Limit reached");
   uint nftId = random(); // we're assuming that random() returns only 0,1,2    
    updateConditions(nftId);
    _mint(user_addr, nftId, numOfCopies, data);
    TotalNFTsMinted++;
    dropsite_NFT_Owner[user_addr]=nftId;
    return (nftId,string(data));
    }
    
    function depositAmount(address payee,uint amountToDeposit) internal {
        deposits[payee] += amountToDeposit;
    }
    //Random minting after Crypto Payments
    function CryptoRandomMint(address user_addr)  contractIsNotPaused public payable returns (uint,string memory) {
     require(TotalNFTsMinted<1000, "Max Minting Limit reached");
     require(msg.value == (25), "Balance must be 25 Matics");
   uint nftId = random(); // we're assuming that random() returns only 0,1,2
     updateConditions(nftId);
    _mint(user_addr, nftId, numOfCopies, data);
    depositAmount(_msgSender(), msg.value);
    TotalNFTsMinted++;
    dropsite_NFT_Owner[user_addr]=nftId;
    return (nftId,string(data));
    }
}
2

1 Answer 1

0

If I figured your question right. You want for a Marketplace contract to get ownership of Distributed NFTs.

To do that, you would usually use transferOwnership() function. You can find an example of it in OpenZeppelin library. There is even a contract Ownabale.sol written for that specific purpose. (Though it deals with ownership of contracts)

It seems like you had written your own Ownership logic in your case. I would advise using OpenZeppelin instead, I am positive they have a solution for this, likey even inside the ERC1155 standard. Even more so, as their code is audited, there is far less chance of introducing security exploits.

1
  • Yes, You figured out right. OpenZeppelin Ownable library works only for contracts. But I want to only have record(Or any other solution) of Minted NFTs from Dropsite Contract to Marketplace contract. So that my users may sell them on Marketplace. In my marketplace contract I have used OpenZeppelin contracts and its completely secure. But for dropsite the custom logic is my requirement. It is simple minting on an address using Openzeppelin _mint() function. What I want now is some way to sell that minted NFT from Dropsite on my marketplace. Apr 4, 2022 at 9:18

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.