

Smart Contract 智能合約玩轉 NFT 盲盒模式
source link: https://www.frank.hk/blog/smart-contract-mystery-box/
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

Smart Contract 智能合約玩轉 NFT 盲盒模式
最近有留意一些 NFT 的項目專案,發現絕大多數都是採用了「盲盒模式」來玩,即購買的時候並不知道裡面是什麼,等到了一定的時間後,盲盒會開啟,才會知道你買的 NFT 具體的屬性,是否稀有等。
MekaVerse 盲盒這裏我們不討論 Marketing 的做法,純粹從技術角度探討一下「盲盒模式」要怎麼做到。
我之前寫過一篇文章講怎樣輕鬆編寫 ERC 721 智能合約,裡面有說過 NFT 在 OpenSea 等市場中顯示的名稱,圖像,屬性等資料,完全是由 NFT 的 metadata 決定,而 metadata 則是靠調用 NFT 智能合約中的 tokenURI
function 而得到。因此,這個 metadata 並不是像大家想像的一樣不可更改,只要能夠讓智能合約返回不同的 tokenURI
, 則在市場中顯示的圖像以及屬性就會隨之更改。
聰明的你可能想到,如果 tokenURI
是一個 http 連接,即 metadata 是存放在傳統伺服器中,則非常容易做到這個效果。只要修改伺服器程式,返回完全不同的 metadata 即可。沒錯,但如果 tokenURI
是一條 IPFS 連結,那要如何處理? IPFS 不是不可更改嗎? 哈哈,是的 IPFS 連結是不能更改,但是 tokenURI
可以呀。只要對智能合約的代碼做一點更改,便可以輕鬆做到效果。
我們的大概思路是,有一個開關參數控制盲盒開啟與否,如果 true,則 tokenURI
將返回一條盲盒專用的 metadata IPFS 連結,裡面的 name,image 等都是固定的名稱和圖像。另外我們還需要有兩個 function ,供授權的地址調用,一個用以改變上述開關參數的狀態,另一個用以設定盲盒開啟後新的 baseURI
。等到開啟盲盒的神聖日子來臨,被授權的地址調用這兩個 function,即可揭開盲盒的神秘面紗。
(當然,聰明的你也應該想到,不使用開關參數,完全依靠更改baseURI
也是可以的。只是我覺得有個開關更容易操作一些)
以下是參考的代碼:
當盲盒沒有開啟時,進入 OpenSea 看到的會是這樣:

當盲盒開啟後,進入 OpenSea 看到的會是這樣:

訂閱我的網站,接收更新以及其他有趣的消息 ? 。 訂閱不收費,走過路過別錯過。
Subscribe to my website, I will email you if any new posts or interesting stuff available.
如果你喜歡我的內容,請考慮用一杯咖啡支持我一下吧,非常感謝 ? 。
If you like my contents, please support me via BuyMeCoffee, Thanks a lot.
其它相關文章
Recommend
-
19
NFT Marketplace Development Relies on a Smart Contract ProtocolMarch 29th 2021 5
-
5
一周之内状况百出,NFT盲盒真的安全吗?
-
10
When it comes to layer-1 blockchains, storing metadata on-chain is very expensive and doesn’t make sense for most people. The preferred way is to leverage IPFS while keeping a reference to each token’s attributes on the blockchain. Let’s disc...
-
8
“顶流”NFT中诞生的盲盒模式,会成功“出道”还是难逃“塌房”?深眸财经1小时前裹着‘盲盒“外衣的NFT作品,是”蜜糖“还是”砒霜“?今年以来,NFT已...
-
19
Introduction In my previous tutorials, we showed you how to use our generative art library to create a
-
13
阿狸NFT盲盒变「明盒」 技术翻车引群嘲BTCWan6小时前836NFT浪潮的兴起让各大IP找到了新的市场,1月19日,国产知名动漫IP阿狸的官方社媒宣布进军NFT领域,推出「Ali&His Friends」...
-
1
阿狸 NFT 盲盒变「明盒」,技术翻车引群嘲 蜂巢财经NEWS 原创 2022-02-17 01:53 热度 201109 分享 微信扫一扫:分享 ...
-
14
Analyzing Pepsi NFT Smart ContractDecoding Smart Contract 01Pepsi’s NFT collectionPepsi dropped its genesis NFT collection on Dec. 2021 (source), till today...
-
19
How to Implement an NFT Staking Contract Many NFT projects are looking for ways to...
-
15
NFT smart contract development company Maticz offers the best NFT smart contract development on ethereum, solana, cardano, polygon, binance chain, etc. Whatsapp +91 9384587998 Telegram @maticzofficial
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK