如何在opensea批量发布NFT(Goerli测试网)

一、生成NFT图象

hashlips_art_engine

HashLips Art Engine 是一种用于根据提供的图层创建多个不同的艺术作品实例的工具。

1.安装

npm install
or
yarn install
在这里插入图片描述

2.使用

在“layers”目录中创建不同的图层作为文件夹,并在这些目录中添加所有图层资源。 一旦你有了所有的层,进入 src/config.js 并更新 layerConfigurations 对象的 layersOrder 数组,按照从低层到顶层的顺序,使其成为你的层文件夹名称。

每个图层对象的name代表图像所在文件夹的名称(在 /layers/ 中)。
在这里插入图片描述
growEditionSizeTo:生成图像的个数。
更新format尺寸,即输出的图像尺寸。
shuffleLayerConfigurations默认为false,并将按数字顺序保存所有图像。若设置为为true,将混淆图像的保存顺序。
还可以通过向config.js文件中的extraMetadata对象变量添加额外的项(key: value)对来为每个元数据文件添加额外的元数据。

const extraMetadata = {
    
    
  creator: "Tiger",
};

调试脚本 package.json

"scripts": {
    
    
    "build": "node index.js",
    "generate": "node index.js",
    "rarity": "node utils/rarity.js",
    "preview": "node utils/preview.js",
    "pixelate": "node utils/pixelate.js",
    "update_info": "node utils/update_info.js",
    "preview_gif": "node utils/preview_gif.js",
    "generate_metadata": "node utils/generate_metadata.js"
  }

2.1 运行命令 node index.js(or npm run build) 输出的艺术品将在build/images目录中,而 json 在build/json目录中。

在这里插入图片描述

2.2 更新 IPFS 的 baseUri 和描述

src/config.js中的baseUri = “ipfs://NewUriToReplace”

// General metadata for Ethereum
const namePrefix = "My Collection";
const description = "Remember to replace this description";
const baseUri = "ipfs://QmZwo1rMdDMErLx6csTjLEzhm6WpYDjJwciNq3KUVdc4GX";

QmZwo1rMdDMErLx6csTjLEzhm6WpYDjJwciNq3KUVdc4GX是ipfs中images文件夹的CID。
执行命令:node utils/update_info.js or npm run update_info
在这里插入图片描述

2.3 生成预览图像

npm run preview

在这里插入图片描述

2.4 从集合中生成像素化图像

npm run pixelate

所有图像都将输出到/build/pixel_images目录中。如果要更改像素化的比率,则可以更新文件中pixelFormat对象的比率属性src/config.js。左边的数字越低,图像的像素化程度就越高。

const pixelFormat = {
    
    
  ratio: 5 / 128,
};

2.5 打印稀有数据

npm run rarity
Trait type: Bottom lid
{
    
    
  trait: 'High',
  weight: '20',
  occurrence: '26 in 100 editions (26.00 %)'
}
{
    
    
  trait: 'Low',
  weight: '40',
  occurrence: '33 in 100 editions (33.00 %)'
}
{
    
    
  trait: 'Middle',
  weight: '40',
  occurrence: '41 in 100 editions (41.00 %)'
}

二、图像上传至IPFS

1.安装IPFS后,选择导入,点击文件夹,选中images文件夹并上传。

在这里插入图片描述

2. 更新json信息

  1. 复制images文件夹的CID,粘贴至src/config.js中的baseUri中。
    在这里插入图片描述 3. 执行命令:node utils/update_info.js or npm run update_info

3.选择导入,点击文件夹,选中json文件夹并上传。

三、NFT智能合约

SimpleNft.sol

// SPDX-License-Identifier: MIT

// Amended by HashLips
/**
    !Disclaimer!
    These contracts have been used to create tutorials,
    and was created for the purpose to teach people
    how to create smart contracts on the blockchain.
    please review this code on your own before using any of
    the following code for production.
    HashLips will not be liable in any way if for the use 
    of the code. That being said, the code has been tested 
    to the best of the developers' knowledge to work as intended.
*/

pragma solidity >=0.7.0 <0.9.0;

import "@openzeppelin/contracts/token/ERC721/extensions/ERC721Enumerable.sol";
import "@openzeppelin/contracts/access/Ownable.sol";

contract NFT is ERC721Enumerable, Ownable {
    
    
    using Strings for uint256;

    string baseURI;
    string public baseExtension = ".json";
    uint256 public cost = 0.00001 ether;
    uint256 public maxSupply = 10000;
    uint256 public maxMintAmount = 20;
    bool public paused = false;
    bool public revealed = false;
    string public notRevealedUri;

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

    // internal
    function _baseURI() internal view virtual override returns (string memory) {
    
    
        return baseURI;
    }

    // public
    function mint(uint256 _mintAmount) public payable {
    
    
        uint256 supply = totalSupply();
        require(!paused);
        require(_mintAmount > 0);
        require(_mintAmount <= maxMintAmount);
        require(supply + _mintAmount <= maxSupply);

        if (msg.sender != owner()) {
    
    
            require(msg.value >= cost * _mintAmount);
        }

        for (uint256 i = 1; i <= _mintAmount; i++) {
    
    
            _safeMint(msg.sender, supply + i);
        }
    }

    function walletOfOwner(address _owner)
        public
        view
        returns (uint256[] memory)
    {
    
    
        uint256 ownerTokenCount = balanceOf(_owner);
        uint256[] memory tokenIds = new uint256[](ownerTokenCount);
        for (uint256 i; i < ownerTokenCount; i++) {
    
    
            tokenIds[i] = tokenOfOwnerByIndex(_owner, i);
        }
        return tokenIds;
    }

    function tokenURI(uint256 tokenId)
        public
        view
        virtual
        override
        returns (string memory)
    {
    
    
        require(
            _exists(tokenId),
            "ERC721Metadata: URI query for nonexistent token"
        );

        if (revealed == false) {
    
    
            return notRevealedUri;
        }

        string memory currentBaseURI = _baseURI();
        return
            bytes(currentBaseURI).length > 0
                ? string(
                    abi.encodePacked(
                        currentBaseURI,
                        tokenId.toString(),
                        baseExtension
                    )
                )
                : "";
    }

    //only owner
    function reveal() public onlyOwner {
    
    
        revealed = true;
    }

    function setCost(uint256 _newCost) public onlyOwner {
    
    
        cost = _newCost;
    }

    function setmaxMintAmount(uint256 _newmaxMintAmount) public onlyOwner {
    
    
        maxMintAmount = _newmaxMintAmount;
    }

    function setNotRevealedURI(string memory _notRevealedURI) public onlyOwner {
    
    
        notRevealedUri = _notRevealedURI;
    }

    function setBaseURI(string memory _newBaseURI) public onlyOwner {
    
    
        baseURI = _newBaseURI;
    }

    function setBaseExtension(string memory _newBaseExtension)
        public
        onlyOwner
    {
    
    
        baseExtension = _newBaseExtension;
    }

    function pause(bool _state) public onlyOwner {
    
    
        paused = _state;
    }

    function withdraw() public payable onlyOwner {
    
    
        // This will pay HashLips 5% of the initial sale.
        // You can remove this if you want, or keep it in to support HashLips and his channel.
        // =============================================================================
        (bool hs, ) = payable(0x7F4acD90047b121Ef8479ADC56F2379C0d359f70).call{
    
    
            value: (address(this).balance * 5) / 100
        }("");
        require(hs);
        // =============================================================================

        // This will payout the owner 95% of the contract balance.
        // Do not remove this otherwise you will not be able to withdraw the funds.
        // =============================================================================
        (bool os, ) = payable(owner()).call{
    
    value: address(this).balance}("");
        require(os);
        // =============================================================================
    }
}


构造函数

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

_name:NFT名字
_symbol:NFT符号
_initBaseURI:设置BaseURI
_initNotRevealedUri:设置不揭露URI的显示字段

在Remix上合约部署

1.打开Metamask

切换Goerli网络
在这里插入图片描述

2. remix选着执行环境

在这里插入图片描述

3. 部署合约传参

在这里插入图片描述
_initBaseURI:“ipfs://QmVAQetWCZcX187qGu7heW3uEmdgPeGQhbdsv3YQc6PTTW/”
QmVAQetWCZcX187qGu7heW3uEmdgPeGQhbdsv3YQc6PTTW 为json文件夹的CID。
_initNotRevealedUri: “Now, not reveraled”

已成功部署:https://goerli.etherscan.io/address/0x8140d4589633db201e7f007f186fe51f3c6e649e

3. 铸造nft

执行mint函数
在这里插入图片描述

获取tokenURI

1. 执行tokenURI()函数。

在这里插入图片描述
因为revealed默认为false,不显示tokenURI。

2. 执行reveal()函数,revealed更为true。

3. 再次执行tokenURI()函数。

在这里插入图片描述
此时tokenURI为揭露状态。

四、在opensea网站上导入智能合约

opensea已更新,自动识别并导入你部署的合约

1、若你部署的主网,打开链接,查看nft具体信息

2、若你部署的测试网,打开链接,查看nft具体信息

3、刚刚部署的合约在opensea 上的具体信息 eyes-nfts

猜你喜欢

转载自blog.csdn.net/weixin_43405220/article/details/124961530