第三十四課 采用TRUFFLE框架如何創(chuàng)建自己的ERC721非同質(zhì)化資產(chǎn)生物商店?

1. 摘要

《第三十三課 如何創(chuàng)建自己的ERC721非同質(zhì)化資產(chǎn)生物商店?》講解了如何使用REMIX本地環(huán)境搭建ERC721非同質(zhì)化資產(chǎn)生物商店,因?yàn)楹霞s相對復(fù)雜,采用solidity import多級合約編輯的方式。
本文采用TRUFFLE框架的形式來發(fā)布建ERC721非同質(zhì)化資產(chǎn)生物商店的內(nèi)容,以便后續(xù)js腳本擴(kuò)展和DAPP開發(fā)。
本文包括內(nèi)容:
(1)環(huán)境準(zhǔn)備
(2)智能合約編譯
(3)配置.env環(huán)境變量
(4)智能合約部署到rinkeby測試網(wǎng)
(5)配置.env環(huán)境和更新ABI
(6)創(chuàng)建ERC721資產(chǎn)

輝哥系統(tǒng)整合出了ERC721從理論到實(shí)踐的文章,可按需查看:
(1)第十七課 【ERC721實(shí)踐】迷戀貓從玩耍到開發(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)備

ERC721的智能合約就采用OpenZeppelin的ERC721模板合約。
具體的代碼架構(gòu)和分析輝哥就不展示了,有需要源碼工程的同學(xué)可直接加入輝哥的知識星球下載。


然后在Ubuntu環(huán)境建把工程文件復(fù)制過去。

2.2 智能合約編譯

編譯成功結(jié)果:

duncanwang@ubuntu:~/work/opensea-creatures$ truffle compile
Please set a mnemonic and infura key.
Compiling ./contracts/Creature.sol...
Compiling ./contracts/CreatureFactory.sol...
Compiling ./contracts/CreatureLootBox.sol...
Compiling ./contracts/DeployCreature.sol...
Compiling ./contracts/Factory.sol...
Compiling ./contracts/Migrations.sol...
Compiling ./contracts/Strings.sol...
Compiling ./contracts/TradeableERC721Token.sol...
Compiling openzeppelin-solidity/contracts/AddressUtils.sol...
Compiling openzeppelin-solidity/contracts/introspection/ERC165.sol...
Compiling openzeppelin-solidity/contracts/introspection/SupportsInterfaceWithLookup.sol...
Compiling openzeppelin-solidity/contracts/math/SafeMath.sol...
Compiling openzeppelin-solidity/contracts/ownership/Ownable.sol...
Compiling openzeppelin-solidity/contracts/token/ERC721/ERC721.sol...
Compiling openzeppelin-solidity/contracts/token/ERC721/ERC721Basic.sol...
Compiling openzeppelin-solidity/contracts/token/ERC721/ERC721BasicToken.sol...
Compiling openzeppelin-solidity/contracts/token/ERC721/ERC721Receiver.sol...
Compiling openzeppelin-solidity/contracts/token/ERC721/ERC721Token.sol...

Compilation warnings encountered:
...
  function baseTokenURI() public view returns (string) {
  ^ (Relevant source part starts here and spans across multiple lines).

Writing artifacts to ./build/contracts

2.3 配置.env環(huán)境變量

.env的配置內(nèi)容參考:

mnemonic_ropsten=mosquito electric slim hybrid craft charge shrimp digital car wonder term oven
mnemonic_rinkeby=mosquito electric slim hybrid craft charge shrimp digital car wonder term oven
mnemonic_mainnet=
NETWORK="rinkeby"
INFURA_KEY="8ce5ebd357144bef8dceae3de1915e29"
MNEMONIC="mosquito electric slim hybrid craft charge shrimp digital car wonder term oven"
OWNER_ADDRESS=""
NFT_CONTRACT_ADDRESS=""
FACTORY_CONTRACT_ADDRESS=""

其中,
(1)mnemonic_ropsten,mnemonic_rinkeby,MNEMONIC為你的metaMask錢包助記詞,可以從metaMask錢包導(dǎo)出。記得從ropsten,rinkeby測試網(wǎng)水龍頭網(wǎng)址申請一點(diǎn)測試ETH。請不要用輝哥的助記詞哦。
(2)INFURA_KEY為你在infura網(wǎng)絡(luò)申請的KEY,申請地址為https://infura.io/。
(3)NFT_CONTRACT_ADDRESS在部署后才可以獲取。

2.4 智能合約部署到rinkeby測試網(wǎng)

運(yùn)行命令:

truffle migrate --network rinkeby --reset --compile-all
【成功運(yùn)行結(jié)果】

duncanwang@ubuntu:~/work/opensea-creatures$ truffle migrate --network rinkeby  --reset --compile-all
{ mnemonic_ropsten: 'mosquito electric slim hybrid craft change shrimp digital car wonder term oven',
  mnemonic_rinkeby: 'mosquito electric slim hybrid craft change shrimp digital car wonder term oven',
  mnemonic_mainnet: '',
  INFURA_KEY: '8ce5ebd357144bef8dceae3de1915e29',
  MNEMONIC: 'mosquito electric slim hybrid craft change shrimp digital car wonder term oven',
  OWNER_ADDRESS: '0xD1F7922e8b78cBEB182250753ade8379d1E09949',
  NFT_CONTRACT_ADDRESS: '',
  FACTORY_CONTRACT_ADDRESS: '',
  NETWORK: 'rinkeby' }
Compiling ./contracts/Creature.sol...
Compiling ./contracts/CreatureFactory.sol...
Compiling ./contracts/CreatureLootBox.sol...
Compiling ./contracts/DeployCreature.sol...
Compiling ./contracts/Factory.sol...
Compiling ./contracts/Migrations.sol...
Compiling ./contracts/Strings.sol...
Compiling ./contracts/TradeableERC721Token.sol...
Compiling ./contracts/openzeppelin-solidity/contracts/AddressUtils.sol...
Compiling ./contracts/openzeppelin-solidity/contracts/AutoIncrementing.sol...
Compiling ./contracts/openzeppelin-solidity/contracts/Bounty.sol...
Compiling ./contracts/openzeppelin-solidity/contracts/ECRecovery.sol...
Compiling ./contracts/openzeppelin-solidity/contracts/LimitBalance.sol...
Compiling ./contracts/openzeppelin-solidity/contracts/MerkleProof.sol...
Compiling ./contracts/openzeppelin-solidity/contracts/ReentrancyGuard.sol...
...
Compiling ./contracts/openzeppelin-solidity/contracts/token/ERC721/ERC721Basic.sol...
Compiling ./contracts/openzeppelin-solidity/contracts/token/ERC721/ERC721BasicToken.sol...
Compiling ./contracts/openzeppelin-solidity/contracts/token/ERC721/ERC721Holder.sol...
Compiling ./contracts/openzeppelin-solidity/contracts/token/ERC721/ERC721Receiver.sol...
Compiling ./contracts/openzeppelin-solidity/contracts/token/ERC721/ERC721Token.sol...

Compilation warnings encountered:

/home/duncanwang/work/opensea-creatures/contracts/Strings.sol:1:1: Warning: Source file does not specify required compiler version!Consider adding "pragma solidity ^0.4.25;"
...
 function finalization() internal {
  ^ (Relevant source part starts here and spans across multiple lines).

Writing artifacts to ./build/contracts

Using network 'rinkeby'.

Running migration: 1_initial_migrations.js
  Deploying Migrations...
  ... 0x69f08d29bcc86b3777e59d88f84fe63ee487ef09b1764b29994e3f1de1ee4625
  Migrations: 0x09ce911c5b355a8e9d51ddfa10c1f666bf04e23b
Saving artifacts...
Running migration: 2_deploy_contracts.js
  Replacing Creature...
  ... 0x636f9f4060142298518a36fec820c7b6de1d123342108cd7cf142752cbc17617
  Creature: 0x6f155409060919c3035727fd88f437c2d0a83d1a
Saving artifacts...

【說明】
所以,對應(yīng)的生物合約creature的交易地址為https://rinkeby.etherscan.io/tx/0x636f9f4060142298518a36fec820c7b6de1d123342108cd7cf142752cbc17617
和合約地址為 0x6f155409060919c3035727fd88f437c2d0a83d1a

2.5 配置.env環(huán)境和更新ABI

更新.env文件參數(shù)。
OWNER_ADDRESS為ERC721生物商店需要?dú)w屬的以太坊地址,NFT_CONTRACT_ADDRESS為剛才編譯成功的creature合約地址。

OWNER_ADDRESS="0xD1F7922e8b78cBEB182250753ade8379d1E09949"
NFT_CONTRACT_ADDRESS="0x6f155409060919c3035727fd88f437c2d0a83d1a"

修改mint_test.js的NFT_ABI為truffle框架編譯文件Creature.json的JSON內(nèi)容。

2.6 創(chuàng)建ERC721資產(chǎn)

node scripts/mint_test.js

【運(yùn)行成功結(jié)果】

duncanwang@ubuntu:~/work/opensea-creatures$ node scripts/mint_test.js
{ mnemonic_ropsten: 'mosquito electric slim hybrid craft change shrimp digital car wonder term oven',
  mnemonic_rinkeby: 'mosquito electric slim hybrid craft change shrimp digital car wonder term oven',
  mnemonic_mainnet: '',
  INFURA_KEY: '8ce5ebd357144bef8dceae3de1915e29',
  MNEMONIC: 'mosquito electric slim hybrid craft change shrimp digital car wonder term oven',
  OWNER_ADDRESS: '0xD1F7922e8b78cBEB182250753ade8379d1E09949',
  NFT_CONTRACT_ADDRESS: '0x6f155409060919c3035727fd88f437c2d0a83d1a',
  FACTORY_CONTRACT_ADDRESS: '',
  NETWORK: 'rinkeby' }
Minted creature. Transaction: 0x7406aa1ca11683f8adc4a34cee9d0802bc5863f48106835303a5d9a36537b063
Minted creature. Transaction: 0x27f98c17b9711c1a509f4619c687869fd745016d26d8d0d64e97a991f2822932
Minted creature. Transaction: 0xa37c55cf29670861cc1908cd27cfd44ca84a73c55fc57cd81ab73a9f7ac3e286
Minted creature. Transaction: 0x85ee81892e0456aa63531c5add1880629360023099fa479e2276c3024ce81ab1
Minted creature. Transaction: 0x2217ddf87c614442e90ef5a60ab0976cfa495d2ca0d37ee8afd419b0719a8b7f
Minted creature. Transaction: 0xa89d82f308dc3ce73282a8651e016b3b4f4daffb9b1650121afd6f56e5d29c3b
Minted creature. Transaction: 0x7102b9100eeca5aa5cd0cafb891885d72a1e862bec2d040c58bd4600b489cfc0
Minted creature. Transaction: 0xa990cdaebd316272810734915ece71b61988f7e4155beb837dab4fa58b8780f7
Minted creature. Transaction: 0x0e843118952ef6f0e81777b513879f2155847a4388b654c180602f0012fec3ce
Minted creature. Transaction: 0x14df62607acf9fe296a4a4a5c8d6d5a295ee283b78a05cab3b8138666d524fbe
Minted creature. Transaction: 0xcbb76447fd4102ad7092a1e14446755200a4f321a774898ef85b213072587367
Minted creature. Transaction: 0x38e4ae0155f49506a16f8a701fd31d86ab8c120bb2a4cf7ebb559fd470b4386f

輸入合約地址,可見已創(chuàng)建了12個(gè)ERC721的資產(chǎn)。
https://rinkeby.etherscan.io/address/0x6f155409060919c3035727fd88f437c2d0a83d1a

2.7 發(fā)布生物商店

參考《第三十三課 如何創(chuàng)建自己的ERC721非同質(zhì)化資產(chǎn)生物商店?》文章,在https://rinkeby.opensea.io/get-listed/step-two地址輸入智能合約地址,導(dǎo)入items后,就可以看到OpenSea的店鋪了。
本案例使用的智能合約地址為0x6f155409060919c3035727fd88f437c2d0a83d1a
創(chuàng)建成功后,進(jìn)入賬號可以看到該智能合約對應(yīng)的海洋生物商店。
網(wǎng)址: https://rinkeby.opensea.io/category/creaturev16

3.參考

1)英文文檔導(dǎo)航
2)在 rinkeby上發(fā)然后去opensea登記

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容