采用TRUFFLE框架如何创建自己的ERC721非同质化资产生物商店?
《第三十三课 如何创建自己的ERC721非同质化资产生物商店?》讲解了如何使用REMIX本地环境搭建ERC721非同质化资产生物商店,因为合约相对复杂,采用solidity import多级合约编辑的方式。 本文采用TRUFFLE框架的形式来发布建ERC721非同质化资产生物商店的内容,以便后续js脚本扩展和DAPP开发。 本文包括内容: (1)环境准备 (2)智能合约编译 (3)配置.env环境变量 (4)智能合约部署到rinkeby测试网 (5)配置.env环境和更新ABI (6)创建ERC721资产
辉哥系统整合出了ERC721从理论到实践的文章,可按需查看: (1) 第十七课 【ERC721实践】迷恋猫从玩耍到开发 (2) 第三十三课 如何创建自己的ERC721非同质化资产生物商店? (3) 第三十四课 采用TRUFFLE框架如何创建自己的ERC721非同质化资产生物商店? (4) 第三十五课 如何配置Metadata以便装饰你的ERC721非同质化资产?
ERC721的智能合约就采用OpenZeppelin的ERC721模板合约。 具体的代码架构和分析辉哥就不展示了,有需要源码工程的同学可直接加入辉哥的知识星球下载。
然后在Ubuntu环境建把工程文件复制过去。
编译成功结果:
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
.env的配置内容参考:
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钱包导出。记得从ropsten,rinkeby测试网水龙头网址申请一点测试ETH。请不要用辉哥的助记词哦。 (2)INFURA_KEY为你在infura网络申请的KEY,申请地址为 https://infura.io/ 。 (3)NFT_CONTRACT_ADDRESS在部署后才可以获取。
运行命令:
truffle migrate --network rinkeby --reset --compile-all 【成功运行结果】
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...
【说明】 所以,对应的生物合约creature的交易地址为 https://rinkeby.etherscan.io/tx/0x636f9f4060142298518a36fec820c7b6de1d123342108cd7cf142752cbc17617 和合约地址为 0x6f155409060919c3035727fd88f437c2d0a83d1a
更新.env文件参数。 OWNER_ADDRESS为ERC721生物商店需要归属的以太坊地址,NFT_CONTRACT_ADDRESS为刚才编译成功的creature合约地址。
OWNER_ADDRESS="0xD1F7922e8b78cBEB182250753ade8379d1E09949"
NFT_CONTRACT_ADDRESS="0x6f155409060919c3035727fd88f437c2d0a83d1a"
修改mint_test.js的NFT_ABI为truffle框架编译文件Creature.json的JSON内容。
node scripts/mint_test.js
【运行成功结果】
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
输入合约地址,可见已创建了12个ERC721的资产。 https://rinkeby.etherscan.io/address/0x6f155409060919c3035727fd88f437c2d0a83d1a
参考《第三十三课 如何创建自己的ERC721非同质化资产生物商店?》文章,在 https://rinkeby.opensea.io/get-listed/step-two 地址输入智能合约地址,导入items后,就可以看到OpenSea的店铺了。 本案例使用的智能合约地址为0x6f155409060919c3035727fd88f437c2d0a83d1a 创建成功后,进入账号可以看到该智能合约对应的海洋生物商店。 网址: https://rinkeby.opensea.io/category/creaturev16
如果觉得我的文章对您有用,请随意打赏。你的支持将鼓励我继续创作!