一、生成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資訊
- 複制images檔案夾的CID,粘貼至src/config.js中的baseUri中。 3. 執行指令:node utils/update_info.js or npm run update_info
如何在opensea批量釋出NFT(Goerli測試網)一、生成NFT圖象二、圖像上傳至IPFS三、NFT智能合約四、在opensea網站上導入智能合約
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為揭露狀态。