📜 [專欄新文章] 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.
👏 歡迎轉載分享鼓掌
同時也有552部Youtube影片,追蹤數超過1萬的網紅Valentine in Paris,也在其Youtube影片中提到,【看名著學法文】瘟疫 鼠疫 LA PESTE Albert Camus 卡繆居然在70年前就精準的預言了covid19 新冠肺炎? 並不是因為他會看水晶球,只因他瞭解人性! 0:00 Introduction 0:59 書裡的故事 3:28 和新冠疫情相同之處 5:15 如何戰勝疫情? 6:55 ...
「the numbers of」的推薦目錄:
- 關於the numbers of 在 Taipei Ethereum Meetup Facebook 的最讚貼文
- 關於the numbers of 在 Facebook 的最佳貼文
- 關於the numbers of 在 Facebook 的最讚貼文
- 關於the numbers of 在 Valentine in Paris Youtube 的精選貼文
- 關於the numbers of 在 Hak Me Youtube 的最讚貼文
- 關於the numbers of 在 Einstein Majanil Youtube 的最佳解答
- 關於the numbers of 在 The numbers of something or the number of something 的評價
- 關於the numbers of 在 How can I count the numbers in a string of mixed text/numbers 的評價
- 關於the numbers of 在 Learn To Count from 1 to 10 - Number Rhymes For Children 的評價
the numbers of 在 Facebook 的最佳貼文
In memory of Richard H. Kirk (21 March 1956 – 21 September 2021) R.I.P.
Richard H. Kirk "Black Jesus Voice" (1986)
Sandoz "Digital Lifeforms" (1993)
Richard H. Kirk "Virtual State" (1993)
Richard H. Kirk "The Numbers of Magic" (1995)
Electronic Eye "Neurometrik" (2000)
Richard H. Kirk "Dasein" (2017)
#richardhkirk #riprichardhkirk
the numbers of 在 Facebook 的最讚貼文
Visited the Ministry of Health, Singapore COVID-19 Case Management Task Group (CMTG) Operations Office yesterday. They administer the whole process for COVID-19 patients, from detection to recovery. This includes assigning patients to appropriate care facilities, arranging for transport, and briefing them on what they need to do, especially those who choose Home Recovery.
We now encourage fully vaccinated patients to recover at home wherever possible. This is less disruptive for them, especially if their symptoms are mild. It will also reduce demand for hospital beds, so that the seriously ill ones can get the treatment they need.
I know this is a stressful time for those with family members who have COVID-19. Some of you have written to me to express your frustrations, or question why MOH takes so long to get in touch after you or a loved one has tested positive.
The CMTG have a very demanding task. They operate 24/7 in a rapidly changing situation. Case numbers are still growing, and we are doing our best to scale up our operations, and make sure all patients are well cared for.
I would like to thank the CMTG for their dedication and tireless efforts. If we all work together, get vaccinated, and wear our masks properly, we can slow down the current wave, and get through safely without overwhelming our hospitals or suffering unnecessary casualties. – LHL
the numbers of 在 Valentine in Paris Youtube 的精選貼文
【看名著學法文】瘟疫 鼠疫 LA PESTE
Albert Camus 卡繆居然在70年前就精準的預言了covid19 新冠肺炎?
並不是因為他會看水晶球,只因他瞭解人性!
0:00 Introduction
0:59 書裡的故事
3:28 和新冠疫情相同之處
5:15 如何戰勝疫情?
6:55 Camus給我們帶來怎樣的啟示?
___
醫生最早發現疫情
但掌權者為了穩定局勢與經濟利益極力隱瞞
直至瘟疫擴散不得已全面封城
人們開始瘋狂搶奪食物 奸商也開始囤貨炒高價格
城裡的市民孤立無助
染疫者不相信醫護人員,甚至產生攻擊行為...
以上的種種情節並不是對這次新冠肺炎疫情的總結
而是出自於七十幾年前 Albert Camus卡繆的一本書:la Peste
『瘟疫』
作者說 “La seule façon de lutter contre la peste, c'est l'honnêteté”
對抗瘟疫的唯一方法就是正直
那什麼又是正直呢?
而這 本書又能為 深處於疫情中的我們帶來怎樣的啟示?
_______________________________
請留言告訴我你的看法我會抽出三位幸運兒送上法文版的 La Peste 瘟疫(可以在INSTAGRAM YOUTUBE 兩邊重複留言)
________________________________
歡迎大家收看我的另一支影片:
♦️法國名著異鄉人 卡繆 L'ETRANGER
https://youtu.be/fFB1kYiy5rk
_________________________________
【能夠幫大家學習法文的影片】
♦️法國品牌故事
Louis Vuitton https://youtu.be/rvPQf8Y_X8A
Chaumet https://youtu.be/JdQCDcolEuc
♦️20個法國最受歡迎的名字
https://youtu.be/mMVnQMAMYFw
♦️12個歷史和神話故事中著名人物的法文名字
https://youtu.be/IqFZ2fDjupI
♦️看藝術學法文:5幅畫輕鬆看懂莫內和印象派
https://youtu.be/eQbWiXW9P74
♦️52個巴黎景點法文發音
https://youtu.be/OBHvu_NB8MI
♦️法文 French Numbers 1-100
https://youtu.be/Onl3GeNiURo
__________________________________
Material used in this video:
"Happiness" Directed and animated by Steve Cutts
Licensed under Creative Commons: By attribution 3.0 license
http://facebook.com/stevecuttart
Music:
Whisper in the Deep
Nocturne - Asher Fulero
Wandering Soul - Asher Fulero
Violet Vape - Cheel
_______________________________
L I N K S
個人 Instagram ➭ https://www.instagram.com/ValentineinParis
學法文 Instagram ➭ https://www.instagram.com/ValentineWords
個人 Facebook ➭ https://facebook.com/Valentineinparispage
歡迎追蹤!
__________________________________
C O N T A C T
➭ Hello@ValentineinParis.com
__________________________________
#瘟疫 #預言 #疫情 #camus #法國名著講解
the numbers of 在 Hak Me Youtube 的最讚貼文
#黑咪店 #hakmebeauty
Product Mentioned:-
⭐️ Talika Lash Conditioning Cleanser https://bit.ly/3tjahKg
⭐️ Talika Eyelash Lipocils Expert https://bit.ly/350VOIa
⭐️ Talika Eyebrow Lipocils Expert https://bit.ly/3tus5lO
⭐️ Talika Eye Therapy Patch (6 patches) + Case https://bit.ly/3fsUhk9
⭐️ Talika Bio Enzymes Eye Patch Ultra-Hydratant (1 pair) https://bit.ly/3oOfkAX
⭐️ Talika Time Control https://bit.ly/3vtebRH
⭐️ Esterel Eye Gel http://bit.ly/2LqeFAx
⭐️ Kind Bag https://bit.ly/2SkwgTN
? Current Talika Promotion: https://shop.hakmebeauty.com/collections/promotions
⭐️ Hakme Beauty App
?? IOS: https://apple.co/3fGIQpA
?? Android: https://bit.ly/2PmXibN
?? Huawei Phone: https://bit.ly/3meAtTD
⭐️ WhatsApp Numbers
?? 銅鑼灣店: 9164 1686
?? 旺角店: 9164 8012
Follow Hakme Beauty:-
?黑咪店地址: https://www.hakmebeauty.com/store-locations/
?黑咪店路線圖: http://bit.ly/2W3pUZr
?黑咪店Online: https://shop.hakmebeauty.com
?黑咪店Instagram: @hakmebeauty
?黑咪店MeWe: https://mewe.com/p/hakmebeauty
?黑咪店Facebook Page: https://www.facebook.com/hakmebeautyltd/
Follow Me:-
? My Instagram: @iamhakme
? Blog: www.hakmebeauty.com
? MeWe: https://mewe.com/p/iamhakme
? My Facebook: www.facebook.com/hakmebeauty
*************************************************************
Disclaimer: This video is created and edited by my editor. All the content are my own thoughts. As always, all opinions are based on my experience and honesty. Products are either purchased by me or for those which are sent by PR are marked with an “*”. For any collaboration with brands which involves monetary payment, “Ad” will be in the video so that you are aware of the collaboration. Some of the links used above might be affiliate links and please be aware that I will earn a % of commission if you decide to buy through the affiliate links.
the numbers of 在 Einstein Majanil Youtube 的最佳解答
Hi everyone, earlier this year I was in one of the worst states in my life. I took a month plus break from social media and locked myself in my room/home studio and made a whole album.
This is one of the tracks in it, including already released -
1) here we go again // https://youtu.be/97kMFeOZujc
2) safe & sound // https://youtu.be/EzRsAA-MUoQ
This is one of my proudest songs and I keep this in a special place in my heart. Putting aside the numbers, I hope all or some of you actually enjoy, or maybe relate to this track.
"by my side" by Einstein Majanil
Prod. by : Ryini
Music Written/ Mix & Mastered/ Arranged by : Einstein Majanil
Video Produced/ Directed/ Shot/ Edited by : Einstein Majanil
Special thanks to :
X Coffee Cafe, Papar - https://www.instagram.com/xcoffee20
Violet Cassandra's Residence
Hugo Amandus' Residence
Incredible Talents :
Janeveralenne Marcel - https://www.instagram.com/jnvera.m
Hugo Amandus - https://www.instagram.com/hugoamandus
DISCLAIMER : ALL CHARACTERS, SCENES, AND LYRICS ARE FICTITIOUS. NEITHER THE PRODUCER, DIRECTOR, WRITERS AND TALENTS INTEND TO OFFEND THE AUDIENCE INTENTIONALLY OR UNINTENTIONALLY, IN ANY SHAPE OR FORM.
Thank you / Terima Kasih / Kotohuadan / Ponsikou -
To each and everyone for the love and support! x
the numbers of 在 How can I count the numbers in a string of mixed text/numbers 的推薦與評價
... <看更多>
the numbers of 在 The numbers of something or the number of something 的推薦與評價
Well, "the number" alone is strictly singular in itself. And when "of" is added, the phrase, "the number of", will call for a plural noun ... ... <看更多>