📜 [專欄新文章] Gas Efficient Card Drawing in Solidity
✍️ Ping Chen
📥 歡迎投稿: https://medium.com/taipei-ethereum-meetup #徵技術分享文 #使用心得 #教學文 #medium
Assign random numbers as the index of newly minted NFTs
Scenario
The fun of generative art NFT projects depends on randomness. The industry standard is “blind box”, where both the images’ serial number and the NFTs’ index are predetermined but will be shifted randomly when the selling period ends. (They call it “reveal”) This approach effectively solves the randomness issue. However, it also requires buyers to wait until the campaign terminates. What if buyers want to know the exact card right away? We’ll need a reliable onchain card drawing solution.
The creator of Astrogator🐊 isn’t a fan of blind boxes; instead, it thinks unpacking cards right after purchase is more interesting.
Spec
When initializing this NFT contract, the creator will determine the total supply of it. And there will be an iterable function that is randomly picking a number from the remaining pool. The number must be in range and must not collide with any existing ones.
Our top priority is accessibility/gas efficiency. Given that gas cost on Ethereum is damn high nowadays, we need an elegant algorithm to control gas expanse at an acceptable range.
Achieving robust randomness isn’t the primary goal here. We assume there’s no strong financial incentive to cheat, so the RNG isn’t specified. Implementers can bring their own source of randomness that they think is good enough.
Implementation
Overview
The implementation is pretty short and straightforward. Imagine there’s an array that contains all remaining(unsold) cards. When drawIndex() is called, it generates a (uniform) random seed to draw a card from the array, shortens the array, and returns the selected card.
Algorithm
Drawing X cards from a deck with the same X amount of cards is equal to shuffling the deck and dealing them sequentially. It’s not a surprise that our algorithm is similar to random shuffling, and the only difference is turning that classic algo into an interactive version.
A typical random shuffle looks like this: for an array with N elements, you randomly pick a number i in (0,N), swap array[0] and array[i], then choose another number i in (1,N), swap array[1] and array[i], and so on. Eventually, you’ll get a mathematically random array in O(N) time.
So, the concept of our random card dealing is the same. When a user mints a new card, the smart contract picks a number in the array as NFT index, then grabs a number from the tail to fill the vacancy, in order to keep the array continuous.
Tweak
Furthermore, as long as the space of the NFT index is known, we don’t need to declare/initialize an array(which is super gas-intensive). Instead, assume there’s such an array that the n-th element is n, we don’t actually initialize it (so it is an array only contains “0”) until the rule is broken.
For the convenience of explanation, let’s call that mapping cache. If cache[i] is empty, it should be interpreted as i instead of 0. On the other hand, when a number is chosen and used, we’ll need to fill it up with another unused number. An intuitive method is to pick a number from the end of the array, since the length of the array is going to decrease by 1.
By doing so, the gas cost in the worst-case scenario is bound to be constant.
Performance and limitation
Comparing with the normal ascending index NFT minting, our random NFT implementation requires two extra SSTORE and one extra SLOAD, which cost 12600 ~ 27600 (5000+20000+2600) excess gas per token minted.
Theoretically, any instantly generated onchain random number is vulnerable. We can restrict contract interaction to mitigate risk. The mitigation is far from perfect, but it is the tradeoff that we have to accept.
ping.eth
Gas Efficient Card Drawing in Solidity was originally published in Taipei Ethereum Meetup on Medium, where people are continuing the conversation by highlighting and responding to this story.
👏 歡迎轉載分享鼓掌
同時也有1部Youtube影片,追蹤數超過4萬的網紅李根興 Edwin商舖創業及投資分享,也在其Youtube影片中提到,哈佛知識分享 - 行業分析及定位《點做生意? - 裙褂》Case Study (想睇全程 unedited 訪問,可whatsapp 我90361143) 做生意要識得分析個行頭, 你一定要認識哈佛教授 Michael Porter 的波特五力 Porter's 5 Forces: (1) ...
tradeoff 在 Starman 資本攻略 Facebook 的最佳解答
放棄「完美」的思維
林作這篇文章寫得很好,很欣賞也很認同這種思維。
事實上,大部份成功人士都是行動力和決策力極高的人,要做到「快」的關鍵就是放棄追求「完美」。這裡的「完美」是指對事情有過多的考慮。
凡事有得必有失,要凡事做到「完美」根本不現實,既然做任何事情都有tradeoff,我們只需平衡事情得失輕重後,獲得大致上的方向便要執行,然後在執行中再調整細節。有些事情只有執行過程中才能看得見,而這些都是在單純的「計劃」階段永遠不能預視。
另一樣是不怕失敗,因為怕失敗的人永遠不會執行,而他們都忽略了失敗過程中所得到的經驗,而這些經驗都是成功的必要因素。
套用投資思維,凡投資都有風險,害怕風險的人會要求完全沒有風險的情況下才投資,因此這些人從不投資,或有一萬個理由解釋不做投資的決定,而他們不知道不投資也是一種風險。害怕風險的人從不會做風險管理,只有明白風險而又決定執行的投資者才會做風險管理。
要成功,要有執行力,不執行就永遠沒有成功的可能性。要有高效的決策和執行力,首先要有接受「不完美」的思維。
tradeoff 在 台灣應用材料公司 Applied Materials Taiwan Facebook 的最佳解答
【應材喜訊迎新春🎉 榮獲ESG評選全球企業前20】
農曆春節將至,應材美名先揚,
在MSCI ESG研究部調查中,
獲評優等AA等級並名列全球前20名✨!
ESG是指環境保護(Environmental)、社會責任(Social)與公司治理(Governance)。相較傳統單純評估財務狀況,ESG的評選能提供更全面的企業狀況給社會大眾參考,
更以綜觀角度考量環境永續、人資訓練、管理能力等面向,
提高企業透明度並協助辨識風險和機遇🤓。
應材不僅在專業技術、資金和國際規模成績亮眼,
對於ESG同樣表現傑出,
全方位俱佳的雄厚企業實力備受國際肯定💯!
更多ESG的詳細資訊,請點擊網址:https://tinyurl.com/qurxkgn
#AppliedMaterials #ESG50
tradeoff 在 李根興 Edwin商舖創業及投資分享 Youtube 的最讚貼文
哈佛知識分享 - 行業分析及定位《點做生意? - 裙褂》Case Study
(想睇全程 unedited 訪問,可whatsapp 我90361143)
做生意要識得分析個行頭, 你一定要認識哈佛教授 Michael Porter 的波特五力 Porter's 5 Forces:
(1) Competitive Rivalries 行內的競爭性
(2) Threat of Substitution 代替品的威脅
(3) Threat of New Entry 新入行競爭者的威脅
(4) Supplier Power 供應商的議價能力
(5) Buyer Power 買家的議價能力
多謝經營了44年的鴻運繡莊老闆黃師傅接受訪問。
. 如何分析行業?
. 如何定位競爭?
. 做生意最忌什麼?
. 裙褂行業如今發展?
訪問內容有答案。大家有大喜事也可幫襯他。
鴻運繡莊
總店:
元朗教育路69號地下全層
(852) 2477 6688 (敬請預約)
營業時間:上午12:00 至 下午8:00
逢星期四休息
尖沙咀店:
尖沙咀金巴利道73號新業廣商業大廈2樓202室
(852) 2787 9708 (敬請預約)
營業時間:中午12:30 至 下午8:00
逢星期日休息
內文:
今次呢個case好特別,鴻運繡莊, 專做裙褂, since 1975 年,做咗44年,同我一樣,今年都係44歲。 佢個行頭又點呢,點做生意? 我後面呢間係去元朗嘅老店,而家又去佢尖沙咀嘅分店睇下。
呢盤生意係由阿黃師傅嘅爸爸44年前做起。Michael Porter 話你要分析一個行業,你睇五大影響個行業嘅大力量。
以5個力量唔係加起嚟(Additive)喎,只要其中一個失衡呢,就成個行頭可以玩完。 依家我逐一逐一同你解釋, 不過先了解下鴻運繡莊其實做乜先。
咁大家其實又知唔知道裙褂分類又點呢?
咁你又知唔知,褂係買多定租多呢? 幾錢呀?
(1) 要了解個行頭, 就要先了解行內競爭性 Competitive Rivalries. 咁你就要睇有幾多競爭者, 品質的差異性,顧客嘅忠誠度,同埋離開市場唔玩嘅成本。 有啲行頭視對手為死對頭,互相廝殺,割喉式減價! 有啲行頭就互相禮讓, 基本上可能係合謀競爭,好似油公司咁,抬高個價。 咁阿裙褂呢行又點呢?
(2) 市場上有冇代替品,都會影響成個行頭嘅表現。 例如以前有好多人用計數機, 依家一個智能電話就已經代替晒啦。 高鐵代替咗公路,港珠澳大橋代替咗搭船等。 當然要睇下個代替品係唔係代替得曬啦。咁裙褂呢?
(3) 新入行競爭者多唔多威脅呢? 係咪話抄就抄, 有冇咩特別專業知識? 有冇任何入行嘅障礙呢? 好似係外國醫生嚟香港一樣,未考過香港醫務委員會嘅試,就係唔準係香港做醫生。 有冇任何技術嘅保障, 或者 economy of scale 好似百佳/惠康咁大,先至壓得低個價錢呢?
(4) 供應商的議價能力。 你同邊個人入貨? 多唔多選擇? 佢哋會唔會大過你好多,大石砸死蟹? 你轉其他供應商議會唔會成本好大? 你係賣電腦嘅,可能大部分嘅利潤就去咗Intel 粒 chip 嗰道, 因為你部電腦冇咗佢粒chip 就唔值錢。
(5) 第五個力量, 最後你就要睇買家議價能力。 市場上多唔多買家?佢哋嘅order 大唔大? 佢哋對價格敏唔敏感? 佢哋入其他貨改變嘅成本高唔高? 例如,醫藥行業一向都好賺錢, 因為買家為咗身體好, 多多錢都願意畀。同埋佢哋轉食另一隻藥嘅話,改變嘅成本可能係付出健康,太大喇。 做藥廠嘅,反而最怕就係insurance 公司, 因為佢哋主宰咗客人見咩醫生同食咩藥。 裙褂呢個行業有點呢?
裙褂又點樣令到個買家願意畀多啲錢? 有咩新意呢?
Hello Kitty 呢啲叫做licensing專利授權。 一般你都會同個licensor簽訂的合約,用佢個圖案幾多年嘅時間,預期有幾錢嘅收入, 當中幾多百分比嘅營業額會畀返佢 Royalty Fees, 平則百分之幾,貴則20%至30%。 當然你作為licensee , 就要upfront 俾個minimum guarantee 佢, 即是你一件都賣唔出, 你都一早已經付出咗。 當然佢唔係個個批,都要你有返咁上下料到先畀你用啦。
除咗hello kitty 嘅褂, 一件傳統嘅裙褂需要有咩呢?
咁講完一大輪,做裙褂嘅成本架構係點? 賺幾錢呢?
一般做零售批發嘅,攞貨返嚟,轉手賣畀人,賣100蚊,賺3/4成啦。 但如果係自己品牌,H&M 馬沙等,賺5/6成啦,luxury brand, Prada 咁就7/8成啦。咁做褂呢? 人工超貴又點呢?
要提防新競爭者嘅進入威脅, 原來你做時裝零售都可以註冊外觀㗎喎。 你去知識產權署, 各種產品外觀設計都可以註冊㗎,包括電腦,電話,DVD/CD,紡織品,珠寶,同埋手錶。 只要你係獨特嘅, 填幾份文件交啲證據,成功註冊咗保障有效期最長就係25年,每五年續期一次。 咁做裙褂又點呢?
最後根據Michael Porter 做生意, 你先要用以上5 forces 去分析個行業好唔好做。 好做嘅,就有以下四種方法贏人,比行家做得更好。
(1) Cost Leadership 大眾市場, 成本平過人,好似佳寶, 百佳,惠康咁。
(2) Cost Focus 小眾市場,成本都係平過人, 例如而家好多新興嘅夾公仔機,專 target 一班年青人/細路仔, 半賭博嘅心態去刺激呀,唔使人管理, 啲公仔成本都唔值錢。
記住喎, 我講緊係成本平過人,唔係價錢平過人喎。 成本平過人,即是價錢一樣,你自然賺多啲啦。
要贏人? 仲有 (3) Differentitation 大眾市場,但係行差異化, 好似Starbucks 咁。
(4) Differentiation Focus 小眾市場,都係行差異化,啲嘢靚過人。好似Prada, Chanel 咁。
想知多啲,可以睇返我之前有條片講關於100間士多嘅故事, 就同你仔細分析左呢四格。 咁鴻運繡莊做裙褂又點呢?
好明顯黃師傅就係行緊第四, differentiation focus strategy. 我自己做商舖基金都係一樣, 做專啲,做好啲,我哋基金收費唔平, 但最緊要服務好,投資者同租客賺到錢。
根據Michael Porter, 四格入面做生意選擇邊格都得,但最忌就是Stuck in the Middle, 你唔願意作出tradeoff 取捨,就難贏競爭對手。
希望你都透過呢啲嘅影片學到嘢,做生意更加叻。 最後身邊有朋友結婚或者你自己又大事都好呢,記住呢鴻運繡莊啦!
買舖/租舖/放舖/投資商舖基金熱線: 28301111 或 whatsapp +852 90361143
盛滙商舖基金 Bridgeway 網頁 www.bwfund.com
李根興創業之友 https://www.facebook.com/EdwinNetwork/
李根興商舖之友 https://www.facebook.com/edwinprimeshop/
李根興 youtube 商舖創業及投資分享商舖創業及投資分享https://www.youtube.com/channel/UCEN66AnLghXESgCDIsz-3Nw
#哈佛知識,#鴻運繡莊,裙褂點做生意,#michaelporte#michaelporter, #點做生意,#商舖, #李根興, #創業, #edwinlee, #盛滙, #bridgeway, #舖, #商機
tradeoff 在 Trade Off - MoneyDJ理財網 的相關結果
Trade Off 在經濟學上常被譯為「抵換」,它的意思與中文的「取捨」很接近,取捨的意思比較強烈,即魚與熊掌不可得兼,要選A就不能同時有B,兩者之間只 ... ... <看更多>
tradeoff 在 tradeoff 的中文翻釋|影音字典- VoiceTube 看影片學英語 的相關結果
tradeoff. 分享單字. US /ˈtredˌɔf, -ˌɑf/. ・. UK /'treɪdˌɔ:f/. A1 初級. 定義 影片字幕. n. 在兩個理想但不兼容的功能之間取得平衡;妥協。 ... <看更多>
tradeoff 在 trade-off中文(繁體)翻譯:劍橋詞典 的相關結果
工作做得準確無誤和迅速快捷之間有個平衡。 She said that she'd had to make a trade-off between her job and her family. ... <看更多>