当前位置:网站首页>如何在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. 效果图
边栏推荐
- Niuke real problem programming - Day17
- Es log error appreciation -- allow delete
- Navigation - are you sure you want to take a look at such an easy-to-use navigation framework?
- Ascend 910 realizes tensorflow1.15 to realize the Minist handwritten digit recognition of lenet network
- Ctfshow, information collection: web1
- #yyds干货盘点# 解决名企真题:交叉线
- Data Lake (IX): Iceberg features and data types
- Niuke real problem programming - Day12
- JSON parsing instance (QT including source code)
- ⼀个对象从加载到JVM,再到被GC清除,都经历了什么过程?
猜你喜欢
数学建模——什么是数学建模
"July 2022" Wukong editor update record
Stream learning notes
[Yugong series] go teaching course 005 variables in July 2022
CTFshow,信息搜集:web9
时空可变形卷积用于压缩视频质量增强(STDF)
Five pain points for big companies to open source
JSON parsing instance (QT including source code)
Data Lake (IX): Iceberg features and data types
Apache multiple component vulnerability disclosure (cve-2022-32533/cve-2022-33980/cve-2021-37839)
随机推荐
Niuke real problem programming - Day9
PG basics -- Logical Structure Management (locking mechanism -- table lock)
Niuke real problem programming - Day17
数据库如何进行动态自定义排序?
IDA pro逆向工具寻找socket server的IP和port
Xiaomi's path of chip self-development
Es log error appreciation -trying to create too many buckets
最安全的证券交易app都有哪些
【服务器数据恢复】某品牌StorageWorks服务器raid数据恢复案例
Jetson AGX Orin CANFD 使用
The method of parsing PHP to jump out of the loop and the difference between continue, break and exit
With 8 modules and 40 thinking models, you can break the shackles of thinking and meet the thinking needs of different stages and scenes of your work. Collect it quickly and learn it slowly
Ctfshow, information collection: web1
⼀个对象从加载到JVM,再到被GC清除,都经历了什么过程?
Compile advanced notes
Cocoscreator resource encryption and decryption
【跟着江科大学Stm32】STM32F103C8T6_PWM控制直流电机_代码
JSON解析实例(Qt含源码)
CTFshow,信息搜集:web9
Data Lake (IX): Iceberg features and data types