📜 [專欄新文章] 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.
👏 歡迎轉載分享鼓掌
同時也有128部Youtube影片,追蹤數超過40萬的網紅SLSMusic,也在其Youtube影片中提到,Enjoy our new episode of #THEPIANOTAKE with guest artist "計畫通行", presenting the song "The Reason Why I Thought I'd Die" original by amazarashi & Nakas...
「interesting story」的推薦目錄:
- 關於interesting story 在 Taipei Ethereum Meetup Facebook 的最佳解答
- 關於interesting story 在 全聯建築技術機構 -許偉揚.瓦建設計 Facebook 的最佳貼文
- 關於interesting story 在 Facebook 的最佳解答
- 關於interesting story 在 SLSMusic Youtube 的最佳解答
- 關於interesting story 在 Sascha Heusermann 賀少俠 Youtube 的精選貼文
- 關於interesting story 在 WenWei彣蔚 Youtube 的最讚貼文
- 關於interesting story 在 42 Interesting Stories ideas - Pinterest 的評價
- 關於interesting story 在 ChrisVal Interesting Story Base - Home | Facebook 的評價
- 關於interesting story 在 interesting story - YouTube 的評價
interesting story 在 全聯建築技術機構 -許偉揚.瓦建設計 Facebook 的最佳貼文
921大地震 (集集大地震),在1999年9月21日 凌晨1點47分15.9秒發生在臺灣中部山區的逆斷層型地震,總共持續大約102秒。
這場地震造成2,415人罹難,29人失蹤,11,305人受傷,51,711棟房屋全倒,53,768棟房屋半倒。
今年的 #中秋節,恰逢 #921大地震22周年, 回首山河變色那一夜,我們更珍惜與家人團圓聚首的這一天 !
九二一紀念型式 / 2002遠東國際數位建築競圖獎
01-INTRODUTION
Therefore before the memorial form does not yet model,What does – our attempt that I ask first is memorial?
Then artificial corpus city of civilization that construct or purchase, how many thousand years since then, always tell to say with the story that the nature match. But at win the nature at the same time, but neglect the unknowable power of great universe.
Usually in the nature of breakage of at the same time, crisis is hatching. This legal case, primarily and just attempt by the innate character that the formation of the memorial hall study the affairs to celebrate why? How the memory of the affairs of disaster is through concrete of emersion of building space.
02-Site
The choice of the position of base also not is to in advance plan to like of, but is through the imagine of the concept of design and filter but find out to most have to symbolize the base of the meaning. In fact ,921 the first step of memorial hall of earthquakeses plan, and then hope the memorial place is an occurrence on aly purely of the earthquake break the layer to take, rather than the death and harm of earthquake is miserably heavy location. With one kind of more detached attitude, afresh come considering the relation of mankind and nature.
03-Concept
Whole celebrates the scope of amenity, from the dam of the deformation, along seismicly break the layer to take to extend to the big bridge that dilapidated. Artificial with not artificial coexistence is on the earth crust of this deformation. Install the project: dam is with the memorial entrance of amenity of big each conduct and actions of bridge, whole celebrate the space to have no any word of text and record of like diagram, and only come illustrating all facts with the glossary of space.
04-Space 斷&續
Break- parable deformation and despair Continuously- the parable continues and eternity Interesting is, the break and continuously is a logic to exist together. Thering is break then can describe the continuously, thering is continuously then can describe the break
interesting story 在 Facebook 的最佳解答
วันนี้มีครอบครัวชาวสวิส ที่เดินทางมาด้วยรถบ้านแวะมาที่ไร่กุฎาคาร จึงชวนเขาร่วมรายการคุยกับวิกรมตอนเวลา 16:00 ด้วย เป็นเรื่องราวที่น่าสนใจว่าพวกเขาขายบ้านขายบริษัทแล้วย้ายมาอยู่อาศัยในรถบ้านเพื่อเดินทางจากยุโรปมาเอเชีย และกำลังจะไปอเมริกา เราจะมาคุยกันเรื่องราวของชีวิตการเดินทางของครอบครัวสวิสนี้กัน เชิญแฟนคลับทุกคนส่งคำถามมาได้เลย……..
Today, Swiss family traveling by motor home visits Baan Kudakan, Khaoyai. They will join my Facebook LIVE at 16:00 hrs. It's an interesting story that they sold their houses, sold their companies, and then living in a motorhome to travel from Europe to Asia and then to America. Let's talk about this Swiss family's travel life. Fanclub please send the questions for them on LIVE!! See you at 4 PM
interesting story 在 SLSMusic Youtube 的最佳解答
Enjoy our new episode of #THEPIANOTAKE with guest artist "計畫通行", presenting the song "The Reason Why I Thought I'd Die" original by amazarashi & Nakashima Mika.
↓ More INFO down below ↓
💬SLSTalk
Hope you enjoy 計畫通行's amazing voice, it's been a really long time since last time I collab with a male vocalist. Actually we've known each other for a while but didn't really get a chance to collab, finally this time we made it. Make sure to check out his channel as well, he's got many interesting works there.
About this amazing song, you could get a lot of info online. About the meaning of this song, the story behind all this, and about songwriter "amazarashi" and singer "Nakashima Mika". I just wanna say, it's a song of art. If you like this video, please also check out the original & live version from them.
🎙計畫通行
YouTube► https://www.youtube.com/user/x556xx623
Instagram► https://www.instagram.com/keikakutsuukou/
Facebook► https://www.facebook.com/keikakutsuukou
🟧Support us on Patreon and Get Rewards!
► https://www.patreon.com/slsmusic
🎁Get MP3s, Sheet Music, Exclusive Contents
※Sheet Music is unavailable to collaboration performance.
🎧Find SLSMusic on Spotify, iTunes, Apple Music, Amazon, Deezer and more
All► https://li.sten.to/slsmusic
Spotify► http://bit.ly/SLSMusicSpotify
iTunes► http://bit.ly/SLSiTunes
🎤Social Media
Website: https://www.slsmusic.net
Instagram: https://www.instagram.com/slsmusictw
Twitter: https://twitter.com/slsmusictw
Facebook: https://www.facebook.com/slsmusictt
🥁Direct Donation
PayPal► https://www.paypal.me/SLSMusic
歐付寶► https://www.bit.ly/DonateSLS
🙏THANKS YOU FOR SUPPORTING SLSMusic
🔵Patreon "Grand Piano"
Kater of Glencoe、Lyra Mao、かず K・、阿夜、清艵宮、Mikael Mazareth、Zythian、棠哥、炎南 白
🟢Patreon "Piano"
Deemo Harlos、LitGrass Chou、Judy Tseng、Joyce Ninomiya、Kezeranix、維恩 姜、Gordon
🔴YouTube Sponser
交替的白晝與黑夜・Chia-Chi Chang
🎧 Playlists
Official Playlist
https://www.youtube.com/playlist?list=PLqY5-xxyprjtckllGMQK4XljIu_5csx3z
THE PIANO TAKE 🎹 + 🎙
https://youtube.com/playlist?list=PLqY5-xxyprjsC1h0XIhRuZMsMmWjthNCp
🔧Equipment
●Piano / Nord Piano 3
●Speakers / ADAM A7X
●Audio Interface / Yamaha AG06
●Camera / Panasonic GH5
●Studio Desk / Wavebone HEADQUARTER
■──────────────────■
#amazarashi #中島美嘉
interesting story 在 Sascha Heusermann 賀少俠 Youtube 的精選貼文
Uyan Tien is a Brazilian-Taiwanese TV show host, model, entertainer and entrepreneur in Taiwan. His family's backstory is the stuff of movies. There are a thousand interesting things I could say about him, but you should really just listen to him share his incredible story himself. Two and a half hours were not enough to touch on all the exciting topics I wanted to cover. This episode is a must-see!
Follow Uyan on social media:
Facebook: https://www.facebook.com/uyantien
Instagram: https://www.instagram.com/tienuyan
interesting story 在 WenWei彣蔚 Youtube 的最讚貼文
SPM was supposed to be in 2020, but due to the pandemic, it was delayed till 2021 ! It was an interesting experience ?
Follow me !
Instagram : @wenweiyy
Twitter : @wenweiyy
Youtube : @wenwei彣蔚
Hello from Malaysia !
KON WEN WEI 官彣蔚 (known as wen wei in Malaysia) started her career at 16 as a youtuber and her work paved the way to numerous projects. She released her debut single “teenage dream” about her teenage love story ! A Chinese living in Malaysia, fluent in Mandarin, English & Bahasa Melayu. She wishes to share her personal stories, highschool, challenges she faced, about mental health, her passions & stories — through music and her platform. Thanks for watching :)
Camera / Sony zv-1 (PP3 + beauty settings)
Edited by / Jo
Business Enquiries ?
wenwei@gushcloudtalent.com
———————————————————
Music by Brooks - Boop Boop - https://thmatc.co/?l=7552E4D8
Music by Naomi - Osaka - https://thmatc.co/?l=2C5DD7CB
Song : Daystar - Lemon Cake / https://youtu.be/AunAZS5yYmw
#Highschool #NationalExam #wenweiyy
#SPM2020 #SPM2021
interesting story 在 ChrisVal Interesting Story Base - Home | Facebook 的推薦與評價
ChrisVal Interesting Story Base. 1824 likes · 185 talking about this. say goodbye to boredom because here is where boredom is been wiped out with very... ... <看更多>
interesting story 在 42 Interesting Stories ideas - Pinterest 的推薦與評價
Nov 24, 2020 - Explore Estine Griessel's board "Interesting Stories", followed by 102 people on Pinterest. See more ideas about amazing stories, ... ... <看更多>