1,摘要
从加密猫游戏开始,非同质化资产NFT的概念深入人心。不过现在社区中讲概念的多,真正落地发布自己ERC721资产的文章没有看到。辉哥这篇文章就来弥补下这个空缺。
本文的内容包括:
(1)采用REMIX编译本地工程的方式完成合约编译;
(2)采用REMIX IDE完成合约部署;
(3)创建自己的ERC721非同质化资产生物;
(4)转让ERC721非同质化资产生物;
(5)发布自己的ERC721非同质化资产生物商店;
辉哥系统整合出了ERC721从理论到实践的文章,可按需查看:
(1)第十七课 【ERC721实践】迷恋猫从玩耍到开发
(2)第三十三课 如何创建自己的ERC721非同质化资产生物商店?
(3)第三十四课 采用TRUFFLE框架如何创建自己的ERC721非同质化资产生物商店?
(4)第三十五课 如何配置Metadata以便装饰你的ERC721非同质化资产?
2,实操内容
2.1 环境准备
1) 建立目录,复制工程
针对简单的逻辑执行,辉哥认为采用REMIX编译和部署合约的方式远远比采用TRUFFLE方式方便,同时REMIX也可以加载本地包含import合约关系的复杂工程进行编译。不熟悉的同学可参考文章《第三十二课 如何在Windows环境搭建REMIX本地环境,访问本地目录?》完成配置。ERC721的智能合约就采用OpenZeppelin的ERC721模板合约。
具体的代码架构和分析辉哥就不展示了,有需要源码工程的同学可直接加入辉哥的知识星球下载。
2) 启动REMIX本地编译环境
辉哥的SOLIDITY本地共享目录为"D:\jusanban\doc\50-编码实现\BlockChain",所以辉哥在WINDOWS下启动命令行,输入以下命令:
remixd -s D:\jusanban\doc\50-编码实现\BlockChain --remix-ide https://remix.ethereum.org
命令行参考截图:
在CHROME浏览器输入https://remix.ethereum.org,点击"Connect to Localhost"的联调按钮,可启动REMIX本地编译环境。
点击"Start to Compile"完成Creature.sol合约编译。
2.2 创建 Creature合约
在辉哥的管理员测试账号"0xd1f7922e8b78cbeb182250753ade8379d1e09949"下,MetaMask的测试网络选择"Rinkeby Test Net",选择部署的构建参数(代理地址)为"0xf57b2c51ded3a29e6891aba85459d600256cf317"。
点击"Deploy"按钮:
部署成功的交易链接:
https://rinkeby.etherscan.io/tx/0x399cf4c1ed0a7dd52b36612be0c15e56ffce6b119a75024908560461721e38f2
Creature的合约地址:0x5c1188ac19ce51cd5d2dcd10ff5c749417da42d1
2.3 创建ERC721资产10个
在账号“0xD1F7922e8b78cBEB182250753ade8379d1E09949”下运行挖矿函数10次,创建10个ERC721资产给辉哥账号。
函数定义: function mintTo(address _to)
执行参数: mintTo("0xD1F7922e8b78cBEB182250753ade8379d1E09949")
【执行成功结果】
https://rinkeby.etherscan.io/tx/0x12ed4dc5bca13be134c2258f79d636a4f134a19961444a2b63bc5a23f064f604
查看交易记录,可以看到已从系统地址发布了一个WOLF ERC721给辉哥账号了。
然后再执行9次,再创建其他9个野狼标识资产。
点击辉哥管理账号,可以看到已收到10个ERC721资产。
https://rinkeby.etherscan.io/address/0xd1f7922e8b78cbeb182250753ade8379d1e09949#tokentxnsErc721
2.4 转让资产
1) 转给1#给欧阳哥哥
辉哥把野狼标识资产转给野狼队成员,作为野狼队成员的荣誉特征之一。辉哥首先把珍贵的1#通证转移给欧阳哥哥(地址:0x17b1177E0491D25a13a8329a8D2C46621b6ca19F)。
函数声明:
function safeTransferFrom( address _from, address _to, uint256 _tokenId )
函数调用:safeTransferFrom("0xd1f7922e8b78cbeb182250753ade8379d1e09949","0x17b1177E0491D25a13a8329a8D2C46621b6ca19F", 1)
转让成功地址:
https://rinkeby.etherscan.io/tx/0x4f56f968748257bf298fd5bcd0e7c2987713bf0086713f410a1ff6dba4af831e
转让成功截图:
2) 转给2#给ELLA小姐姐
辉哥也想给ELLA小姐姐转一个野狼队的标识资产,同时祝她2019年新年快乐。ELLA小姐姐的地址:0xcE689dBB962DbF45534Af13e4414cCB2dFC78c30 。
查看https://onlinehextools.com/convert-utf8-to-hex网站,
可以得知"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"。
函数原型: function safeTransferFrom(address _from, address _to,uint256 _tokenId,bytes _data)
调用参数:
safeTransferFrom("0xd1f7922e8b78cbeb182250753ade8379d1e09949","0xcE689dBB962DbF45534Af13e4414cCB2dFC78c30",2,"0x204861707079204e65772059656172203230313921")
交易成功的地址:
https://rinkeby.etherscan.io/tx/0x6f234589b641cc00af7e54afa757c00427cf3379c01411e35109522820e9b2fb
转移成功截图和新年祝福语:
2.5 创建商店
使用OpenSea可创建非同质化资产交易商店。该创建者将在OpenSea上填充您的所有资产,并为您的项目提供专用的店面页面。
点击地址:https://rinkeby.opensea.io/get-listed/step-two
1),输入本次智能合约地址
智能合约地址:0x5c1188ac19ce51cd5d2dcd10ff5c749417da42d1
点击"Commit"按钮:
2),导入资产
进入第二步,导入野狼队的10个ERC721资产。
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),查看店面
跳转到我的店面主页:
https://rinkeby.opensea.io/category/wildwolfteam
4),转移给大明
艺术家大明账号地址:0x8fc02f03c15179f8C6D37C3a29FE7A338DC68192 。辉哥通过店面转移一个资产3#给大明。
输入大明地址,点击"Transfer"按钮就转移给大明了。
5),标价出售
把第4个资产标价为0.1 WETH,用于定价出售。
https://rinkeby.opensea.io/assets/0x5c1188ac19ce51cd5d2dcd10ff5c749417da42d1/4
点击"SELL"按钮:
选择固定价格0.1 ETH出售,点击"Post Your List":
点击授权后,等候有心人点击购买了。
2.6 资产形象优化
这个店铺资产的图形是采用默认的海洋生物图标,并不是辉哥期望的野狼队标识。
这个需要配置每个资产的MetaData元素。
例如在浏览器输入1# ERC721资产的URI:
https://rinkeby-api.opensea.io/api/v1/asset/0x5c1188ac19ce51cd5d2dcd10ff5c749417da42d1/1/
可以返回由OpenSea配置的ERC721资产特性信息。
辉哥会在下一篇文章详细介绍如何修改ERC721的MetaDATA,让它们跟野狼队的标识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
}
}