坚固性:从市场合同中调用NFT合同的函数,只有市场才能访问

发布于 2025-02-06 20:18:20 字数 370 浏览 1 评论 0原文

我正在做一个NFT市场,我必须实施每次将NFT出售时,这些图像随机散发。 市场具有购买NFTS的功能性,因此我们已经参考了NFTS智能合约。当调用函数buy()时,它将调用NFT智能合约中的Tranvers()和Suffle()。但是我只希望市场致电Suffle(),因此我决定添加一个要求检查呼叫的地址是否等于市场地址的要求。 问题在于,为了部署市场,我需要NFT地址,而Deverigig则需要NFT合同,我需要市场地址。 我该如何解决?是智能合约的逻辑问题还是有一种方法可以以这种方式解决它? 谢谢你!!

智能合约逻辑图

I'am doing a NFT marketplace, and i have to implement that everytime a NFT is sold the images shuffle.
The Marketplace has the functionallity to buy the NFTs so we have referenciate tha NFTs smart contract. When the function buy() is called, it calls the transfer() and suffle() from NFT smart contract. But i want only the marketplace to call the suffle(), so I decided to add a require that checks if the address that is calling is equal to the Marketplace address.
The problem is that for deploying the Marketplace i need the NFT address and the same for deployig the NFT contract i need the Marketplace address.
How can i solve this? Is a problem of the logic of the smart contract or there is a way to solve it in this way?
Thank you!!

Smart Contracts Logic Diagram

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

您的好友蓝忘机已上羡 2025-02-13 20:18:20

您可以使用设置器函数在部署后设置依赖项地址。

例子:

contract NFT {
    address marketplace;

    function setMarketplace(address _marketplace) public onlyOwner {
        marketplace = _marketplace;
    }
}
contract Marketplace {
    address nft;

    function setNft(address _nft) public onlyOwner {
        nft = _nft;
    }
}

You can use a setter function to set the dependency address after deployment.

Example:

contract NFT {
    address marketplace;

    function setMarketplace(address _marketplace) public onlyOwner {
        marketplace = _marketplace;
    }
}
contract Marketplace {
    address nft;

    function setNft(address _nft) public onlyOwner {
        nft = _nft;
    }
}
孤凫 2025-02-13 20:18:20

我写了一个简单的框架,应该对您有所帮助。 :)

 //SPDX-License-Identifier: UNLICENSED

pragma solidity 0.6.12;


contract NFT {

    //Ensure that only the owner can call important functions
    address owner; 
    

    constructor() public {
        owner = msg.sender;
    }

    mapping (address => bool) public _onlyIfMarketplace;

    function mint() public {
        require(owner == msg.sender);
    }

    function transfer() public {

    }


    function shuffle() public {
        require(_onlyIfMarketplace[msg.sender] == true);
    }

    //You can always add an address that can call this function, 
    //and you can also write another one to remove the address which can call this function
    function setMarketplaceContract(address MarketplaceContract) public {
        require(owner == msg.sender);
        _onlyIfMarketplace[MarketplaceContract] = true;
    }
}


contract Marketplace {

    //Call NFT contract
    NFT nftContract; 

     //Ensure that only the owner can call important functions
    address owner; 
   

    constructor(address nftAddress) public {
        owner = msg.sender;
        nftContract = NFT(nftAddress);
    }

    // You can change the NFT contract you want to call at any time
    function changeNFTAddress(address newNFTAddress) public {
        require(owner == msg.sender);
        nftContract = NFT(newNFTAddress);
    }

    //Call the function of NFT contract
    function buy() public {
        nftContract.transfer();
        nftContract.shuffle();
    }

}

I wrote a simple framework that should help you. :)

 //SPDX-License-Identifier: UNLICENSED

pragma solidity 0.6.12;


contract NFT {

    //Ensure that only the owner can call important functions
    address owner; 
    

    constructor() public {
        owner = msg.sender;
    }

    mapping (address => bool) public _onlyIfMarketplace;

    function mint() public {
        require(owner == msg.sender);
    }

    function transfer() public {

    }


    function shuffle() public {
        require(_onlyIfMarketplace[msg.sender] == true);
    }

    //You can always add an address that can call this function, 
    //and you can also write another one to remove the address which can call this function
    function setMarketplaceContract(address MarketplaceContract) public {
        require(owner == msg.sender);
        _onlyIfMarketplace[MarketplaceContract] = true;
    }
}


contract Marketplace {

    //Call NFT contract
    NFT nftContract; 

     //Ensure that only the owner can call important functions
    address owner; 
   

    constructor(address nftAddress) public {
        owner = msg.sender;
        nftContract = NFT(nftAddress);
    }

    // You can change the NFT contract you want to call at any time
    function changeNFTAddress(address newNFTAddress) public {
        require(owner == msg.sender);
        nftContract = NFT(newNFTAddress);
    }

    //Call the function of NFT contract
    function buy() public {
        nftContract.transfer();
        nftContract.shuffle();
    }

}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文