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

一、生成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",
};

    1
    2
    3

调试脚本 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"
  }

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10

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";

    1
    2
    3
    4

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

npm run preview

    1

在这里插入图片描述
2.4 从集合中生成像素化图像

npm run pixelate

    1

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

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

    1
    2
    3

2.5 打印稀有数据

npm run rarity

    1

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 %)'
}

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16

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

在这里插入图片描述
2. 更新json信息

    复制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(0x943590A42C27D08e3744202c4Ae5eD55c2dE240D).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);
        // =============================================================================
    }
}


    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
    140
    141
    142
    143
    144
    145
    146
    147
    148
    149
    150
    151
    152
    153
    154
    155
    156
    157
    158

构造函数

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

    1
    2
    3
    4
    5
    6
    7
    8
    9

_name:NFT名字
_symbol:NFT符号
_initBaseURI:设置BaseURI
_initNotRevealedUri:设置不揭露URI的显示字段
在Remix上合约部署
1.打开Metamask

切换Rinkeby网络
在这里插入图片描述
2. remix选着执行环境

在这里插入图片描述
3. 部署合约传参

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

已成功部署:https://rinkeby.etherscan.io/address/0x42fE9E6345B26FDbeC7130823d48142B6dC1407f
3. 铸造nft

执行mint函数
在这里插入图片描述
获取tokenURI
1. 执行tokenURI()函数。

在这里插入图片描述
因为revealed默认为false,不显示tokenURI。
2. 执行reveal()函数,revealed更为true。
3. 再次执行tokenURI()函数。

在这里插入图片描述
此时tokenURI为揭露状态。
四、在opensea网站上导入智能合约
1.从主网导入合约

在这里插入图片描述
2.从测试网导入合约

在这里插入图片描述
3. 效果图

在这里插入图片描述
————————————————
版权声明:本文为CSDN博主「Meta吴彦祖」的原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接及本声明。
原文链接:https://blog.csdn.net/weixin_43405220/article/details/124961530

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值