# PecuLab WEB3 LiveCoding (2022-05-12 & 2002-05-26) ## 許願池 https://capturetheether.com/challenges/ ~~1. Discord運作機制及機器人程式開發_BrianYang~~ 2. 上公鏈(正式環境)程序與成本評估_BrianYang (+1 Emma 或有沒有比測試鏈需要注意的事情) 3. 燃燒代幣運作機制_BrianYang ~~4. 代幣銀行,代幣銷售運作機制_秀暐~~ 5. Discord 連結錢包的相關應用(連結錢包後實際的運作方式介紹、應用可能性發展性等)_Emma ## ERC721 盲盒製作 https://github.com/HashLips/solidity_smart_contracts/blob/main/contracts/NFT/NFT_REVEAL.sol * 盲盒合約範本(定型化契約):[ERC721Enumerable](https://docs.openzeppelin.com/contracts/4.x/api/token/erc721#IERC721Enumerable) 1. 批次發行的合約範本 2. Ownable:onlyowner(發此張合約的錢包地址才能操作) 3. Opensea測試環境合約資料抓取有時間差,可能合約已經異動,但畫面連結資訊還沒更新 ## [Token Standards](https://docs.openzeppelin.com/contracts/4.x/tokens) * ERC20:widespread token standard for fungible assets * ERC721:solution for non-fungible tokens, often used for collectibles and games. * ERC777:a richer standard for fungible tokens * ERC1155:multi-tokens, allowing for a single contract to represent multiple fungible and non-fungible tokens * [參考說明](https://www.cool3c.com/article/163618) --- ## Verify & Publish Contract Source Code | Etherscan https://moralis.io/how-to-verify-a-smart-contract-with-hardhat/ https://hardhat.org/plugins/nomiclabs-hardhat-etherscan.html#tasks ## 範例程式 https://github.com/pecu/PecuLab4SEP/tree/main/reveal --- ## 2022-05-12 智能合約解析(以Opensea NFT為例) * Opensea提供視覺易懂的介面給用戶,並非擁有各個NFT的項目資訊 * 範例:https://testnets.opensea.io/assets/rinkeby/0xf73b4445976a8e3127015edf45a60c4eaa22ab03/20 * 項目方提供哪些賦能需透過智能合約去查證:找尋合約地址>Read&Write contract 1.balanceOf:驗證擁有幾張NFT 3.baseURI:基本照片原始資料位置 4.cost:定價(單位為wei,轉換ETH: https://mycointool.com/EtherConverter) 5.getApproved:是否已經開賣 7.maxMintAmount:最多買幾張 10.notRevealedUri:盲盒圖片檔位置(json格式,放的是圖片的描述) https://raw.githubusercontent.com/pecu/PecuLab4SEP/main/NFT-ERC1155/0.json 13.paused:此合約是否暫停販賣中 14.revealed:盲盒啟動/關閉 --- * 嘟嘟房終身免費停車NFT https://nft.findatacrypto.com/Roadmap * Opensea: https://opensea.io/collection/carman-metaverse * [嘟嘟房事件懶人包(一) ](https://www.potatomedia.co/post/a5b7f0d1-b9ee-4ee2-9838-455c45c2acd0) * [嘟嘟房事件懶人包(二)](https://medium.com/fuly-ai-%E6%99%BA%E8%83%BD%E6%8A%95%E8%B3%87%E7%AD%96%E7%95%A5%E6%A9%9F%E5%99%A8%E4%BA%BA-bitfinex-%E6%94%BE%E8%B2%B8%E6%A9%9F%E5%99%A8%E4%BA%BA/%E5%98%9F%E5%98%9F%E6%88%BFnft%E5%87%BA%E5%8C%85%E4%BA%8B%E4%BB%B6%E6%87%B6%E4%BA%BA%E5%8C%85-4a4acd7fe0c2) * 在智能合約裡面用 for loop 去一個一個檢查資料,如果當array資料少的時候沒什麼太大問題,但如果白名單增長了,那問題可就大了。 * 那這樣的問題該怎麼解決呢? 1.比較簡單的做法就是不要用array去存,用一個 mapping 去存這個地址是這個地址是白名單。 2.然後判斷的時候直接判斷,就不用一個for loop去跑。 3.但缺點是初始設定白名單一樣成本很高,但至少不會造成用戶去mint的時候成本很高! ## 2022-05-26 Vendor contract 可以理解為代銷合約,就像賣房子的代銷人員,幫忙賣我們自己的coin。合約中有一個自己的錢包存要賣的coin和收買家付的以太幣,寫完之後要記得把coin 轉一些到這vendor contract裡面。這麼做的好處是去中間化,避免人為所造成的問題,例如忘記轉帳、錢被捲走等等或是人為造成的行政費用,讓所有買賣、支付都自動化也不會出錯。 * 參考資料: 1. [vendor.sol](https://github.com/pecu/PecuLab4SEP/blob/main/reveal/contracts/vendor.sol) 2. [deploy_vendor.js](https://github.com/pecu/PecuLab4SEP/blob/main/reveal/scripts/deploy_vendor.js) 3. 領測試幣:https://faucets.chain.link/rinkeby * 建立vendor contract 四步驟: 1. Compile: ``$ npx hardhat clean`` ``$ npx hardhat compile`` 2. Deploy: ``$ npx hardhat run /.scripts/deploy_vendor.js --network rinkeby`` 3. Verify: ``$ npx hardhat verify –network rinkeby << deploy 後的address>>`` * 小提醒:deploy完之後要接著verify,如果deploy完又改了code,verify就不會成功。 * Verify的重要性:做完Verify才會出現合約明碼,該合約才能夠閱讀、核對。沒有做Verify只能看到數字(Bytecode)。在contract address中閱讀合約時,要看到明碼確認合約中提供的function和提供商說宣稱一致,才表示這個合約可信、可互動。 4. 把自己的coin轉到vendor contract中 * Code解讀: 1. vendor.sol  2. deploy_vendor.js (1) 連結合約 (2) Deploy vendor合約 (3) 等待礦工認證 (4) 確認合約發布狀態&address 
×
Sign in
Email
Password
Forgot password
or
Sign in via Google
Sign in via Facebook
Sign in via X(Twitter)
Sign in via GitHub
Sign in via Dropbox
Sign in with Wallet
Wallet (
)
Connect another wallet
Continue with a different method
New to HackMD?
Sign up
By signing in, you agree to our
terms of service
.