首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何将ERC1155数据(所有权)映射从一个智能契约转移到另一个智能契约?

如何将ERC1155数据(所有权)映射从一个智能契约转移到另一个智能契约?
EN

Ethereum用户
提问于 2022-03-31 06:49:42
回答 1查看 347关注 0票数 0

我正在开发一个NFT市场,在那里我分发免费的NFT(在3个定义的类别中,钻石,黄金,银)。我已经为这个发行开发了一个删除站点智能合同。下拉站点模块将只执行一次,就像它只创建1000个NFT一样,然后它将被关闭。

发行后,我希望那些NFT能够在Marketplace合同上使用。为此,我希望将分布式NFT的所有权从Dropsite合同发送到Marketplace契约。这样用户就可以在市场上发送/传输/出售那些NFT。

我怎样才能做到这一点?

这是我的Dropsite造币合同:

代码语言:javascript
复制
    //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));
    }
}
EN

回答 1

Ethereum用户

发布于 2022-04-04 09:06:41

如果我猜对了你的问题。您需要一个Marketplace contract来获得Distributed NFTs的所有权。

要做到这一点,通常需要使用transferOwnership()函数。您可以在OpenZeppelin库中找到它的一个示例。甚至有一个合同Ownabale.sol为这个特定的目的而写。(虽然它涉及合同的所有权)

在你的情况下,你似乎写了自己的所有权逻辑。我建议使用OpenZeppelin,我肯定他们有一个解决方案,甚至在ERC1155标准中也是如此。更重要的是,随着他们的代码被审计,引入安全漏洞的可能性要小得多。

票数 0
EN
页面原文内容由Ethereum提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://ethereum.stackexchange.com/questions/125112

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档