
1,摘要
從加密貓游戲開始,非同質(zhì)化資產(chǎn)NFT的概念深入人心。不過現(xiàn)在社區(qū)中講概念的多,真正落地發(fā)布自己ERC721資產(chǎn)的文章沒有看到。輝哥這篇文章就來彌補(bǔ)下這個空缺。
本文的內(nèi)容包括:
(1)采用REMIX編譯本地工程的方式完成合約編譯;
(2)采用REMIX IDE完成合約部署;
(3)創(chuàng)建自己的ERC721非同質(zhì)化資產(chǎn)生物;
(4)轉(zhuǎn)讓ERC721非同質(zhì)化資產(chǎn)生物;
(5)發(fā)布自己的ERC721非同質(zhì)化資產(chǎn)生物商店;
輝哥系統(tǒng)整合出了ERC721從理論到實踐的文章,可按需查看:
(1)第十七課 【ERC721實踐】迷戀貓從玩耍到開發(fā)
(2)第三十三課 如何創(chuàng)建自己的ERC721非同質(zhì)化資產(chǎn)生物商店?
(3)第三十四課 采用TRUFFLE框架如何創(chuàng)建自己的ERC721非同質(zhì)化資產(chǎn)生物商店?
(4)第三十五課 如何配置Metadata以便裝飾你的ERC721非同質(zhì)化資產(chǎn)?
2,實操內(nèi)容
2.1 環(huán)境準(zhǔn)備
1) 建立目錄,復(fù)制工程
針對簡單的邏輯執(zhí)行,輝哥認(rèn)為采用REMIX編譯和部署合約的方式遠(yuǎn)遠(yuǎn)比采用TRUFFLE方式方便,同時REMIX也可以加載本地包含import合約關(guān)系的復(fù)雜工程進(jìn)行編譯。不熟悉的同學(xué)可參考文章《第三十二課 如何在Windows環(huán)境搭建REMIX本地環(huán)境,訪問本地目錄?》完成配置。ERC721的智能合約就采用OpenZeppelin的ERC721模板合約。
具體的代碼架構(gòu)和分析輝哥就不展示了,有需要源碼工程的同學(xué)可直接加入輝哥的知識星球下載。

2) 啟動REMIX本地編譯環(huán)境
輝哥的SOLIDITY本地共享目錄為"D:\jusanban\doc\50-編碼實現(xiàn)\BlockChain",所以輝哥在WINDOWS下啟動命令行,輸入以下命令:
remixd -s D:\jusanban\doc\50-編碼實現(xiàn)\BlockChain --remix-ide https://remix.ethereum.org
命令行參考截圖:

在CHROME瀏覽器輸入https://remix.ethereum.org,點擊"Connect to Localhost"的聯(lián)調(diào)按鈕,可啟動REMIX本地編譯環(huán)境。

點擊"Start to Compile"完成Creature.sol合約編譯。
2.2 創(chuàng)建 Creature合約
在輝哥的管理員測試賬號"0xd1f7922e8b78cbeb182250753ade8379d1e09949"下,MetaMask的測試網(wǎng)絡(luò)選擇"Rinkeby Test Net",選擇部署的構(gòu)建參數(shù)(代理地址)為"0xf57b2c51ded3a29e6891aba85459d600256cf317"。
點擊"Deploy"按鈕:

部署成功的交易鏈接:
https://rinkeby.etherscan.io/tx/0x399cf4c1ed0a7dd52b36612be0c15e56ffce6b119a75024908560461721e38f2
Creature的合約地址:0x5c1188ac19ce51cd5d2dcd10ff5c749417da42d1
2.3 創(chuàng)建ERC721資產(chǎn)10個
在賬號“0xD1F7922e8b78cBEB182250753ade8379d1E09949”下運(yùn)行挖礦函數(shù)10次,創(chuàng)建10個ERC721資產(chǎn)給輝哥賬號。
函數(shù)定義: function mintTo(address _to)
執(zhí)行參數(shù): mintTo("0xD1F7922e8b78cBEB182250753ade8379d1E09949")
【執(zhí)行成功結(jié)果】
https://rinkeby.etherscan.io/tx/0x12ed4dc5bca13be134c2258f79d636a4f134a19961444a2b63bc5a23f064f604
查看交易記錄,可以看到已從系統(tǒng)地址發(fā)布了一個WOLF ERC721給輝哥賬號了。

然后再執(zhí)行9次,再創(chuàng)建其他9個野狼標(biāo)識資產(chǎn)。
點擊輝哥管理賬號,可以看到已收到10個ERC721資產(chǎn)。
https://rinkeby.etherscan.io/address/0xd1f7922e8b78cbeb182250753ade8379d1e09949#tokentxnsErc721

2.4 轉(zhuǎn)讓資產(chǎn)
1) 轉(zhuǎn)給1#給歐陽哥哥
輝哥把野狼標(biāo)識資產(chǎn)轉(zhuǎn)給野狼隊成員,作為野狼隊成員的榮譽(yù)特征之一。輝哥首先把珍貴的1#通證轉(zhuǎn)移給歐陽哥哥(地址:0x17b1177E0491D25a13a8329a8D2C46621b6ca19F)。
函數(shù)聲明:
function safeTransferFrom( address _from, address _to, uint256 _tokenId )
函數(shù)調(diào)用:safeTransferFrom("0xd1f7922e8b78cbeb182250753ade8379d1e09949","0x17b1177E0491D25a13a8329a8D2C46621b6ca19F", 1)
轉(zhuǎn)讓成功地址:
https://rinkeby.etherscan.io/tx/0x4f56f968748257bf298fd5bcd0e7c2987713bf0086713f410a1ff6dba4af831e
轉(zhuǎn)讓成功截圖:

2) 轉(zhuǎn)給2#給ELLA小姐姐
輝哥也想給ELLA小姐姐轉(zhuǎn)一個野狼隊的標(biāo)識資產(chǎn),同時祝她2019年新年快樂。ELLA小姐姐的地址:0xcE689dBB962DbF45534Af13e4414cCB2dFC78c30 。
查看https://onlinehextools.com/convert-utf8-to-hex網(wǎng)站,
可以得知"Happy New Year 2019!"的UTF8的
HEX碼為"0x20 0x48 0x61 0x70 0x70 0x79 0x20 0x4e 0x65 0x77 0x20 0x59 0x65 0x61 0x72 0x20 0x32 0x30 0x31 0x39 0x21",
剔除" 0x"后的輸出為:
"0x204861707079204e65772059656172203230313921"。
函數(shù)原型: function safeTransferFrom(address _from, address _to,uint256 _tokenId,bytes _data)
調(diào)用參數(shù):
safeTransferFrom("0xd1f7922e8b78cbeb182250753ade8379d1e09949","0xcE689dBB962DbF45534Af13e4414cCB2dFC78c30",2,"0x204861707079204e65772059656172203230313921")
交易成功的地址:
https://rinkeby.etherscan.io/tx/0x6f234589b641cc00af7e54afa757c00427cf3379c01411e35109522820e9b2fb
轉(zhuǎn)移成功截圖和新年祝福語:

2.5 創(chuàng)建商店
使用OpenSea可創(chuàng)建非同質(zhì)化資產(chǎn)交易商店。該創(chuàng)建者將在OpenSea上填充您的所有資產(chǎn),并為您的項目提供專用的店面頁面。
點擊地址:https://rinkeby.opensea.io/get-listed/step-two
1),輸入本次智能合約地址
智能合約地址:0x5c1188ac19ce51cd5d2dcd10ff5c749417da42d1
點擊"Commit"按鈕:

2),導(dǎo)入資產(chǎn)
進(jìn)入第二步,導(dǎo)入野狼隊的10個ERC721資產(chǎn)。

Currently loading 4 of 11 items...
This might take a while so take a break and come back a bit later. In fact, just start a conversation on our [discord](https://discord.gg/ga8EJbv), read our [wikis](https://cryptokitties.opensea.io/), or browse our [marketplace](https://rinkeby.opensea.io/assets).
3),查看店面
跳轉(zhuǎn)到我的店面主頁:
https://rinkeby.opensea.io/category/wildwolfteam

4),轉(zhuǎn)移給大明
藝術(shù)家大明賬號地址:0x8fc02f03c15179f8C6D37C3a29FE7A338DC68192 。輝哥通過店面轉(zhuǎn)移一個資產(chǎn)3#給大明。

輸入大明地址,點擊"Transfer"按鈕就轉(zhuǎn)移給大明了。

5),標(biāo)價出售
把第4個資產(chǎn)標(biāo)價為0.1 WETH,用于定價出售。
https://rinkeby.opensea.io/assets/0x5c1188ac19ce51cd5d2dcd10ff5c749417da42d1/4
點擊"SELL"按鈕:

選擇固定價格0.1 ETH出售,點擊"Post Your List":

點擊授權(quán)后,等候有心人點擊購買了。

2.6 資產(chǎn)形象優(yōu)化
這個店鋪資產(chǎn)的圖形是采用默認(rèn)的海洋生物圖標(biāo),并不是輝哥期望的野狼隊標(biāo)識。
這個需要配置每個資產(chǎn)的MetaData元素。
例如在瀏覽器輸入1# ERC721資產(chǎn)的URI:
https://rinkeby-api.opensea.io/api/v1/asset/0x5c1188ac19ce51cd5d2dcd10ff5c749417da42d1/1/
可以返回由OpenSea配置的ERC721資產(chǎn)特性信息。
輝哥會在下一篇文章詳細(xì)介紹如何修改ERC721的MetaDATA,讓它們跟野狼隊的標(biāo)識LOGO更加匹配。
{
"token_id": "1",
"image_url": "https://storage.googleapis.com/opensea-rinkeby/0x5c1188ac19ce51cd5d2dcd10ff5c749417da42d1/1.png",
"image_preview_url": "https://storage.googleapis.com/opensea-rinkeby/0x5c1188ac19ce51cd5d2dcd10ff5c749417da42d1-preview/1.png",
"image_thumbnail_url": "https://storage.googleapis.com/opensea-rinkeby/0x5c1188ac19ce51cd5d2dcd10ff5c749417da42d1-thumbnail/1.png",
"image_original_url": "https://storage.googleapis.com/opensea-prod.appspot.com/creature/1.png",
"animation_url": null,
"name": "Sprinkles Fisherton",
"description": "Friendly OpenSea Creature that enjoys long swims in the ocean.",
"external_link": "https://openseacreatures.io/1",
"asset_contract": {
"address": "0x5c1188ac19ce51cd5d2dcd10ff5c749417da42d1",
"name": "Wild Wolf Team",
"symbol": "WOLF",
"image_url": null,
"featured_image_url": null,
"featured": false,
"description": null,
"external_link": null,
"wiki_link": null,
"stats": {
"seven_day_volume": 0,
"seven_day_change": 0,
"total_volume": 0,
"count": 10,
"num_owners": 3,
"market_cap": 0,
"average_price": 0,
"items_sold": 0
},
"traits": {
"aqua_power": {
"min": 10,
"max": 40
},
"stamina": {
"min": 1.2,
"max": 90.2
},
"level": {
"min": 2,
"max": 8
},
"generation": {
"min": 1,
"max": 2
},
"stamina_increase": {
"min": 5,
"max": 15
},
"personality": {
"sad": 1,
"boring": 1,
"sleepy": 1,
"happy": 1
},
"mouth": {
"pleased": 1,
"surprised": 1,
"happy": 1,
"cute": 1
},
"eyes": {
"content": 1,
"joy": 1,
"wink": 1,
"big": 1,
"sleepy": 1
},
"base": {
"crab": 1,
"goldfish": 1,
"narwhal": 1,
"jellyfish": 1,
"starfish": 1,
"tealfish": 1
}
},
"hidden": true,
"nft_version": "3.0",
"schema_name": "ERC721",
"display_data": {
"images": [
"https://storage.googleapis.com/opensea-rinkeby/0x5c1188ac19ce51cd5d2dcd10ff5c749417da42d1/10.png",
"https://storage.googleapis.com/opensea-rinkeby/0x5c1188ac19ce51cd5d2dcd10ff5c749417da42d1/9.png",
"https://storage.googleapis.com/opensea-rinkeby/0x5c1188ac19ce51cd5d2dcd10ff5c749417da42d1/8.png",
"https://storage.googleapis.com/opensea-rinkeby/0x5c1188ac19ce51cd5d2dcd10ff5c749417da42d1/7.png",
"https://storage.googleapis.com/opensea-rinkeby/0x5c1188ac19ce51cd5d2dcd10ff5c749417da42d1/6.png",
"https://storage.googleapis.com/opensea-rinkeby/0x5c1188ac19ce51cd5d2dcd10ff5c749417da42d1/5.png"
]
},
"short_description": null,
"total_supply": null,
"owner": null,
"buyer_fee_basis_points": 0,
"seller_fee_basis_points": 250
},
"owner": {
"user": null,
"profile_img_url": "https://storage.googleapis.com/opensea-static/opensea-profile/3.png",
"address": "0x17b1177e0491d25a13a8329a8d2c46621b6ca19f",
"config": ""
},
"permalink": "https://rinkeby.opensea.io/assets/0x5c1188ac19ce51cd5d2dcd10ff5c749417da42d1/1",
"background_color": null,
"auctions": [],
"sell_orders": null,
"traits": [
{
"trait_type": "generation",
"value": 2,
"display_type": "number",
"max_value": null,
"trait_count": 3,
"order": null
},
{
"trait_type": "stamina_increase",
"value": 10,
"display_type": "boost_percentage",
"max_value": null,
"trait_count": 4,
"order": null
},
{
"trait_type": "aqua_power",
"value": 40,
"display_type": "boost_number",
"max_value": null,
"trait_count": 4,
"order": null
},
{
"trait_type": "personality",
"value": "sad",
"display_type": null,
"max_value": null,
"trait_count": 3,
"order": null
},
{
"trait_type": "stamina",
"value": 2.3,
"display_type": null,
"max_value": null,
"trait_count": 2,
"order": null
},
{
"trait_type": "level",
"value": 2,
"display_type": null,
"max_value": null,
"trait_count": 2,
"order": null
},
{
"trait_type": "mouth",
"value": "surprised",
"display_type": null,
"max_value": null,
"trait_count": 3,
"order": null
},
{
"trait_type": "eyes",
"value": "joy",
"display_type": null,
"max_value": null,
"trait_count": 2,
"order": null
},
{
"trait_type": "base",
"value": "starfish",
"display_type": null,
"max_value": null,
"trait_count": 2,
"order": null
}
],
"last_sale": null,
"num_sales": 0,
"top_bid": null,
"current_price": null,
"current_escrow_price": null,
"listing_date": null,
"is_presale": false,
"related_assets": [],
"orders": [],
"supports_wyvern": true,
"visitor_stats": {
"rank": 3
}
}
3,參考
1)開發(fā)文檔導(dǎo)航
2) 在OpenSea登記Rinkeby網(wǎng)絡(luò)的ERC721資產(chǎn)