我如何实现懒惰的智能合约,而不是薄荷nfts?
这是我第一次写智能合约的经历,因此我仍在尝试浏览所有这些工作的工作方式。我在Rinkeby测试网络上有一份智能合约,该合同当前在部署时按预期工作,然后进口到OpenSea(他们的“获取”页面)。
问题是,我必须通过调用_mint()方法来使其根据我的智能合约地址生成的集合中显示,以使它们显示在智能合约的构造函数中。我只通过铸造了该系列的前10个NFT部署了测试智能合约,并且正如我所期望的那样,这10个NFT出现在Opensea上。但是,我想利用Opensea的懒惰铸造能力来避免收藏中的每个NFT造成的汽油费用(其中有10,000个)。
是否有一种方法可以建立智能合约,以告知Opensea(可能还有其他交易所),我正在懒惰,并且在Opensea内显示了所有10,000个NFT,而无需实际上在合同中预先铸造每一个NFT?
我知道人们可以开发自己的网站,然后其他人可以购买他们想要购买的每个NFT来完成懒惰的磨损,但是我希望这些NFT在Opensea中可见和可见,而无需正式铸造它们(懒惰) 。我将所有的NFT和元数据都放在IPF上,当我执行实际的薄荷操作时,一切似乎都在正确地链接,所以我知道这可以正常工作。我只需要了解是否可以/如何设置我的智能合约来启用此功能。
这是我目前与IPF URL的智能合同,取而代之的是占位符:
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.4;
import "@openzeppelin/contracts/token/ERC1155/ERC1155.sol";
import "@openzeppelin/contracts/access/Ownable.sol";
import "@openzeppelin/contracts/security/Pausable.sol";
import "@openzeppelin/contracts/utils/math/SafeMath.sol";
import "@openzeppelin/contracts/interfaces/IERC2981.sol";
import "./ContextMixin.sol";
contract MyTestContract is ERC1155, IERC2981, Ownable, Pausable, ContextMixin {
using SafeMath for uint256;
string public name;
string public symbol;
uint256 public total_supply;
address private _recipient;
constructor() ERC1155("IPFS_URL_TO_JSON_FILES_GOES_HERE") {
name = "MY Collection Name Goes Here";
symbol = "TESTING";
total_supply = 10000;
_recipient = owner();
_mint(msg.sender, 1, 1, "");
_mint(msg.sender, 2, 1, "");
_mint(msg.sender, 3, 1, "");
_mint(msg.sender, 4, 1, "");
_mint(msg.sender, 5, 1, "");
_mint(msg.sender, 6, 1, "");
_mint(msg.sender, 7, 1, "");
_mint(msg.sender, 8, 1, "");
_mint(msg.sender, 9, 1, "");
_mint(msg.sender, 10, 1, "");
}
function setURI(string memory newuri) public onlyOwner {
_setURI(newuri);
}
function pause() public onlyOwner {
_pause();
}
function unpause() public onlyOwner {
_unpause();
}
function mint(address account, uint256 id, uint256 amount, bytes memory data)
public
onlyOwner
{
_mint(account, id, amount, data);
}
function mintBatch(address to, uint256[] memory ids, uint256[] memory amounts, bytes memory data)
public
onlyOwner
{
_mintBatch(to, ids, amounts, data);
}
function _beforeTokenTransfer(address operator, address from, address to, uint256[] memory ids, uint256[] memory amounts, bytes memory data)
internal
whenNotPaused
override
{
super._beforeTokenTransfer(operator, from, to, ids, amounts, data);
}
function royaltyInfo(uint256 _tokenId, uint256 _salePrice) external view override returns (address receiver, uint256 royaltyAmount) {
return (_recipient, (_salePrice * 500) / 10000);
}
function _setRoyalties(address newRecipient) internal {
require(newRecipient != address(0), "Royalties: new recipient is the zero address");
_recipient = newRecipient;
}
function setRoyalties(address newRecipient) external onlyOwner {
_setRoyalties(newRecipient);
}
function supportsInterface(bytes4 interfaceId) public view virtual override(ERC1155, IERC165) returns (bool) {
return (interfaceId == type(IERC2981).interfaceId || super.supportsInterface(interfaceId));
}
/**
* Override isApprovedForAll to auto-approve OS's proxy contract
*/
function isApprovedForAll(
address _owner,
address _operator
) public override view returns (bool isOperator) {
// if OpenSea's ERC1155 Proxy Address is detected, auto-return true
if (_operator == address(0x207Fa8Df3a17D96Ca7EA4f2893fcdCb78a304101)) {
return true;
}
// otherwise, use the default ERC1155.isApprovedForAll()
return ERC1155.isApprovedForAll(_owner, _operator);
}
/**
* This is used instead of msg.sender as transactions won't be sent by the original token owner, but by OpenSea.
*/
function _msgSender() internal override view returns (address sender) {
return ContextMixin.msgSender();
}
// Update for collection-specific metadata.
function contractURI() public pure returns (string memory) {
return "CONTRACT_LEVEL_METADATA_URL_GOES_HERE";
}
}
任何帮助将不胜感激。
This is my first experience writing a smart contract, so I am still trying to navigate how this all works. I have a smart contract on the Rinkeby test network that currently works as expected when deploying and then importing into OpenSea (their "get listed" page).
The problem is I have to mint NFTs within the constructor of the smart contract by calling the _mint() method to make them display in the collection that OpenSea generates based on my smart contract's address. I have only deployed the test smart contract with minting the first 10 NFTs of the collection and those 10 NFTs show up on OpenSea as I would expect. However, I want to utilize OpenSea's lazy minting ability to avoid the gas fees for minting each NFT(there are 10,000 of them) in the collection myself.
Is there a way to set up the smart contract that informs OpenSea(and possibly other exchanges) that I am lazy-minting and have all 10,000 NFTs display within OpenSea without actually having to mint each one upfront within the contract?
I know people can develop their own site where others can then mint each NFT they would like to purchase to accomplish lazy-minting, but I want these NFTs to all be visible and purchasable within OpenSea without them officially being minted yet(lazy-minted). I have all my NFTs and metadata out on IPFS and everything seems to be linking up properly when I perform an actual mint action, so I know that works just fine. I just need to understand if/how it is possible to set up my smart contract to enable this functionality.
Here is my current smart contract with the URLs to IPFS replaced with a placeholder:
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.4;
import "@openzeppelin/contracts/token/ERC1155/ERC1155.sol";
import "@openzeppelin/contracts/access/Ownable.sol";
import "@openzeppelin/contracts/security/Pausable.sol";
import "@openzeppelin/contracts/utils/math/SafeMath.sol";
import "@openzeppelin/contracts/interfaces/IERC2981.sol";
import "./ContextMixin.sol";
contract MyTestContract is ERC1155, IERC2981, Ownable, Pausable, ContextMixin {
using SafeMath for uint256;
string public name;
string public symbol;
uint256 public total_supply;
address private _recipient;
constructor() ERC1155("IPFS_URL_TO_JSON_FILES_GOES_HERE") {
name = "MY Collection Name Goes Here";
symbol = "TESTING";
total_supply = 10000;
_recipient = owner();
_mint(msg.sender, 1, 1, "");
_mint(msg.sender, 2, 1, "");
_mint(msg.sender, 3, 1, "");
_mint(msg.sender, 4, 1, "");
_mint(msg.sender, 5, 1, "");
_mint(msg.sender, 6, 1, "");
_mint(msg.sender, 7, 1, "");
_mint(msg.sender, 8, 1, "");
_mint(msg.sender, 9, 1, "");
_mint(msg.sender, 10, 1, "");
}
function setURI(string memory newuri) public onlyOwner {
_setURI(newuri);
}
function pause() public onlyOwner {
_pause();
}
function unpause() public onlyOwner {
_unpause();
}
function mint(address account, uint256 id, uint256 amount, bytes memory data)
public
onlyOwner
{
_mint(account, id, amount, data);
}
function mintBatch(address to, uint256[] memory ids, uint256[] memory amounts, bytes memory data)
public
onlyOwner
{
_mintBatch(to, ids, amounts, data);
}
function _beforeTokenTransfer(address operator, address from, address to, uint256[] memory ids, uint256[] memory amounts, bytes memory data)
internal
whenNotPaused
override
{
super._beforeTokenTransfer(operator, from, to, ids, amounts, data);
}
function royaltyInfo(uint256 _tokenId, uint256 _salePrice) external view override returns (address receiver, uint256 royaltyAmount) {
return (_recipient, (_salePrice * 500) / 10000);
}
function _setRoyalties(address newRecipient) internal {
require(newRecipient != address(0), "Royalties: new recipient is the zero address");
_recipient = newRecipient;
}
function setRoyalties(address newRecipient) external onlyOwner {
_setRoyalties(newRecipient);
}
function supportsInterface(bytes4 interfaceId) public view virtual override(ERC1155, IERC165) returns (bool) {
return (interfaceId == type(IERC2981).interfaceId || super.supportsInterface(interfaceId));
}
/**
* Override isApprovedForAll to auto-approve OS's proxy contract
*/
function isApprovedForAll(
address _owner,
address _operator
) public override view returns (bool isOperator) {
// if OpenSea's ERC1155 Proxy Address is detected, auto-return true
if (_operator == address(0x207Fa8Df3a17D96Ca7EA4f2893fcdCb78a304101)) {
return true;
}
// otherwise, use the default ERC1155.isApprovedForAll()
return ERC1155.isApprovedForAll(_owner, _operator);
}
/**
* This is used instead of msg.sender as transactions won't be sent by the original token owner, but by OpenSea.
*/
function _msgSender() internal override view returns (address sender) {
return ContextMixin.msgSender();
}
// Update for collection-specific metadata.
function contractURI() public pure returns (string memory) {
return "CONTRACT_LEVEL_METADATA_URL_GOES_HERE";
}
}
Any help would be greatly appreciated.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
不,目前还不可能。当你去一个网站为自己铸造 NFT 时,该网站会执行以下操作:
当您访问 Opensea 时,他们能够获取您帐户上的 NFT,然后加载他们的数据。
目前,如果数据未与 EOA 或合约帐户关联,则无法实现获取数据。
基本上,NFT 必须是某人的。当您拥有数据但没有所有者时,它就不是某人的。
No, that is not possible for now. When there is a website you go to mint NFTs for yourself, the website is doing the following:
When you go to Opensea, they are able to fetch the NFTs on your account and then to load their data.
There is, for right now, no implementation of them getting the data without the data being associated with a EOA or a Contract Account.
Basically, the NFT must be someone's. When you have the data, but no a owner, it's not someone's.
我认为您想要做的是在某个市场中展示“懒惰铸造”的 NFT,对吧?如果这就是您所需要的,也许这个 文章会对您有帮助吗?您使用 rarible 的 API 将惰性铸造数据上传到 Rarible,然后可以在他们的网站上查看和铸造 NFT。我不确定 Openseas 是否也提供 API 来执行此操作。一旦 NFT 被铸造出来,我想它可以在 Openseas 或 Rarible 中看到。
I think that what you want to do is to display a "lazy minted" NFT in one of the marketplaces right? If that's what you need, maybe this article will help you? You upload your lazy minted data to Rarible using rarible's API, and then the NFT can be viewed and minted on their site. I'm not sure if Openseas provide an API to do this too. Once the NFT is minted, I guess it can be seen in either Openseas or Rarible.