当前位置:网站首页>如何在opensea批量发布NFT(Rinkeby测试网)
如何在opensea批量发布NFT(Rinkeby测试网)
2022-07-07 13:03:00 【Meta吴彦祖】
一、生成NFT图象
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信息
- 复制images文件夹的CID,粘贴至src/config.js中的baseUri中。
3. 执行命令:node utils/update_info.js or npm run update_info
3.选择导入,点击文件夹,选中json文件夹并上传。
三、NFT智能合约
// 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);
// =============================================================================
}
}
构造函数
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
切换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. 效果图

边栏推荐
- Unity之ASE实现卡通火焰
- C 6.0 language specification approved
- 连接ftp服务器教程
- "Baidu Cup" CTF competition 2017 February, web:include
- CTFshow,信息搜集:web6
- [understanding of opportunity -40]: direction, rules, choice, effort, fairness, cognition, ability, action, read the five layers of perception of 3GPP 6G white paper
- Apache多个组件漏洞公开(CVE-2022-32533/CVE-2022-33980/CVE-2021-37839)
- Xiaomi's path of chip self-development
- 众昂矿业:萤石继续引领新能源市场增长
- Integer learning
猜你喜欢

Discussion on CPU and chiplet Technology

【深度学习】图像超分实验:SRCNN/FSRCNN

Five pain points for big companies to open source

【服务器数据恢复】戴尔某型号服务器raid故障的数据恢复案例

MySQL bit类型解析

时空可变形卷积用于压缩视频质量增强(STDF)

什么是数据泄露

Ctfshow, information collection: web5

Guangzhou Development Zone enables geographical indication products to help rural revitalization

【数据挖掘】视觉模式挖掘:Hog特征+余弦相似度/k-means聚类
随机推荐
Novel Slot Detection: A Benchmark for Discovering Unknown Slot Types in the Dialogue System
Ctfshow, information collection: web2
JSON解析实例(Qt含源码)
Ctfshow, information collection: web9
Lidar Knowledge Drop
CTFshow,信息搜集:web8
【跟着江科大学Stm32】STM32F103C8T6_PWM控制直流电机_代码
CTFshow,信息搜集:web3
MySQL installation configuration 2021 in Windows Environment
最安全的证券交易app都有哪些
Ctfshow, information collection: web12
word中删除一整页
[understanding of opportunity -40]: direction, rules, choice, effort, fairness, cognition, ability, action, read the five layers of perception of 3GPP 6G white paper
Niuke real problem programming - Day10
CTFshow,信息搜集:web4
How does the database perform dynamic custom sorting?
Niuke real problem programming - day13
[today in history] July 7: release of C; Chrome OS came out; "Legend of swordsman" issued
Ctfshow, information collection: web1
CTFshow,信息搜集:web12