📜 [專欄新文章] 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.
👏 歡迎轉載分享鼓掌
同時也有126部Youtube影片,追蹤數超過24萬的網紅Square Enix,也在其Youtube影片中提到,The original FINAL FANTASY IV comes to life with updated graphics and audio as a 2D pixel remaster! The Kingdom of Baron sent their elite airship fle...
「elements of a story」的推薦目錄:
- 關於elements of a story 在 Taipei Ethereum Meetup Facebook 的精選貼文
- 關於elements of a story 在 Jessie Chung锺潔希 Facebook 的最佳貼文
- 關於elements of a story 在 WE5 - Shibaland Facebook 的精選貼文
- 關於elements of a story 在 Square Enix Youtube 的精選貼文
- 關於elements of a story 在 AKaMiKz Youtube 的精選貼文
- 關於elements of a story 在 Dainghia25 Youtube 的精選貼文
- 關於elements of a story 在 The elements of a story | Reading | Khan Academy - YouTube 的評價
- 關於elements of a story 在 Story Elements Part 1: Characters, Setting, and Events 的評價
- 關於elements of a story 在 19 Story Elements--Narrative ideas - Pinterest 的評價
elements of a story 在 Jessie Chung锺潔希 Facebook 的最佳貼文
小帮手:
【云剧场🤩线上观剧】✨✨✨
✨Cloud Theatre, enjoy theatre online!✨
🌟星音符为您诚意打造《红楼梦》话剧,根据史实与原著改编
——让您深刻体验古典名著的艺术魅力🤩13场演出场场满座,好评如潮!
💝演出购票处 Cloud Theatre :
https://www.cloudtheatre.com/my/shows/the-bream-of-red-mansions/
此次在云剧场上演,票券收入100%捐作抗疫物资❤️
🌹中国古代四大名著之首《红楼梦》话剧🌹
💥必看10大重点💥
✨《红楼梦》在大马首度以话剧演出
✨《红楼梦》根据史实和原著改编
✨知名艺人锺洁希与多位资深演员同台,演员阵容多达26人
✨男主角为全球万里挑一的林霆坚,为寻找贾宝玉剧组发动了全球《寻找贾宝玉》的活动
✨最新3D科技绝美LED背景视觉影像
✨星音符特邀美籍音乐制作人为《红楼梦》话剧操刀,由女主角锺洁希演唱插曲《黑夜将残的炉光》,并与男主角林霆坚深情对唱主题曲《心念》
✨逼真的音效与专业背景音乐配搭
✨精致的古风道具布置
✨精美雅致大气有诚意的古代服装
✨《红楼梦》话剧票券收入100%捐作抗疫物资
🌷由锺洁希领衔主演女主角——出淤泥而不染的林黛玉,💘男主角为全球万里挑一,犹如贾宝玉再现的——林霆坚。为您演绎一场刻骨铭心、至真至爱、荡气回肠的爱情故事❤
📅演出日期:
🤩『第一场』18/09/2021 (六) 8:00p.m. (GMT+8) 【供48小时内观看】
🤩『第二场』27/09/2021 (一) 8:00p.m. (GMT+8) 【供48小时内观看】
🗨 [ 此剧语言为中文,备有中英文字幕]
📲【询问联络】03-55690139 (Ann) https://bit.ly/3yyzYJk
《红楼梦》话剧——谁为情种?
❤眼空蓄泪泪空垂,暗洒闲抛却为谁~
Cloud Theatre, enjoy theatre online! ✨✨✨
The play “The Dream of Red Mansions” was met with overwhelming response, selling out tickets to 13 full houses!
Ticketing platform: Cloud Theatre
https://www.cloudtheatre.com/my/shows/the-bream-of-red-mansions/
🤩100% of the proceeds from the tickets will be donated as Covid-19 medical supplies. Together, let’s do our part and show our love!
🌹 “The Dream of Red Mansions”, an adaptation of the most celebrated classical Chinese novel! 🌹
💥10 reasons why you must watch: 💥
✨This marks the first public performance of the stage play “The Dream of Red Mansions” in Malaysia.
✨ “The Dream of Red Mansions” is based on the original historical novel.
✨Well-known artist Jessie Chung takes the stage with 26 experienced actors.
✨Lead actor Terry Lim, a one-in-a-million actor who portrays Jia Baoyu, was chosen through a worldwide search for a Jia Baoyu lookalike.
✨Stage backdrops created through the latest 3D technology for stunning, lifelike environments.
✨Symphony Theatre invited an American composer to create the soundtrack for “The Dream of Red Mansions,” while lead actress Jessie Chung performed the soundtrack song “A Dying Light in the Dark” and the theme song, “Hearts Apart”—an emotional duet—with lead actor Terry Lim.
✨Accompanied by realistic sound effects and professional background music.
✨Stage design incorporates exquisite ancient Chinese elements and props.
✨Actors wear elegant, refined, majestic and authentic period costumes.
✨100% of the proceeds from the tickets will be donated as Covid-19 medical supplies. Together, let’s do our part and show our love!
🌷Jessie Chung takes the stage as lead actress, portraying the pure and unadulterated Lin Daiyu, while Terry Lim, the lead actor, was chosen out of a ton of applicants from around the world. Come and enjoy a performance of an unforgettable, passionate, and heart-rending love story.
📅Performance Dates:
🤩 First performance:
Saturday, September 18, 2021, 8:00 p.m. (GMT+8)
🤩 Second performance:
Monday, September 27, 2021, 8:00 p.m. (GMT+8)
🗨 (Performed in Mandarin, with Mandarin and English subtitles available.)
📲 Contact us: 03-55690139 (Ann) https://bit.ly/3yyzYJk
“The Dream of Red Mansions,” calling all lovers…❤
“Vain are all these idle tears, tears shed secretly—for whom?”
elements of a story 在 WE5 - Shibaland Facebook 的精選貼文
WE5 ONLINE STORY BOOK 2021-
P.10 Around June or July 2010, 🐷🐷🐷🐷 finally finished their vaccinations and could do walks with Papa & Mama! We often paid visits to the doggy park located next to the Sheung Wan promenade and made a lot of furry friends there!
.
In October 2010 I eventually got a new job, as Assistant Manager in an Italian Restaurant in Elements. The Italian Restaurant Manager liked my professionals very much, but my salary range had reached the company limit and he knew I have difficulties for livings, therefore he paid me extra from his own pocket. Thank you Sir!
.
P.10 差不多在2010年的年中,🐷🐷🐷🐷終於打齊預防針,可以跟阿豬爸、阿豬媽一起外出散步!以前經常到家附近的上環海濱狗狗公園放空,也認識到很多朋友仔!但之後再搬屋後就沒有再去過了。
.
在2010年的10月終於找到公作,在圓方的一家意大利餐廳當副經理。因為當時我的薪酬已經是餐廳可以給予的上限,而意大利經理很賞識我且知道我有困難,所以他每個月自己掏荷包補貼我,感激🙇🏻♂️
🤠
.
大家記得戴口罩😷勤洗手🤲🏻🚿留家抗疫💪🏻
Stay Home Stay Safe & Healthy & Happy!
Wear Mask 😷 Wash Ur Hands 🤲🏻🚿
🤠
*拍照前請先打招呼詢問一下哦
*拍照前請先注意交通安全哦
*狗狗上廁所時請不要拍照哦
*我清理和拿著狗狗便便時請不要拍照哦
*摸狗狗前請先問一下
*我們鼓勵人與人之間應該多聯繫
*打個招呼拍拍照何樂而不為
*PleaseGreet&AskBeforeYouSnap
*PleasePayAttentionToTrafficBeforeYouSnap
*PleaseDoNotSnapWhenDoggiesPeeAndPoo
*PleaseDoNotSnapWhenAmCleaningAndCarryingTheirPoops
*PleaseAskBeforeYouPat
*WeEncourageHumanEngagement
*NothingToLooseToSayHi
🤠
#WE5 #Shibaland #Shibainus #shibas #ShibaGang #GrandpaDogTraining #Grandpa狗噏 #DogTraining #MutualRespect #WE5ShibaFamily
#多尊重少包容 #文明旅遊 #柴犬 #HKShibas #ShibaFamily
#HKShibas #柴犬香港
#DiscoverHongKong #DogsofInstagram #DogPhotography #WE5Story
#GrandpaPhotoGraphy
#LoveWillKeepUsTogether
#只要不投降就是成功 #不要棄養 #AwesomeHongKong @hk_dog_owners
elements of a story 在 Square Enix Youtube 的精選貼文
The original FINAL FANTASY IV comes to life with updated graphics and audio as a 2D pixel remaster!
The Kingdom of Baron sent their elite airship fleet, the Red Wings, to attack the surrounding countries. Distressed by his mission, Cecil, a dark knight and captain of the Red Wings, decides to fight against the tyrannical Baron with his trusted friend and his paramour at his side.
Witness the dramatic story and dynamic battles in this fourth installment of the FINAL FANTASY series!
Available individually or as part of a bundle on Steam.
*Full bundle will be available upon launch of FINAL FANTASY VI
*These games are newly developed remaster editions based on the original titles. Some of the changes and additional elements found in other remakes of these games are not included.
FINAL FANTASY IV pixel remaster is available now!
• Steam®: https://store.steampowered.com/app/11...
• AppStore: https://apps.apple.com/us/app/final-f...
• Google Play: https://play.google.com/store/apps/de...
• Amazon Appstore: http://www.amazon.com/dp/B09D2Y1CHH
elements of a story 在 AKaMiKz Youtube 的精選貼文
Awaken - Chaos Era Gameplay (CBT)
Size: 2.15 GB
Links:
https://www.facebook.com/AwakenChaosEra
https://play.google.com/store/apps/details?id=com.raid.fourelements
CBT APK: https://bit.ly/2RMBozd
------------------------------------------------------------------
Enter the mythical world of Awaken, an ancient land held together only by the elements that brought it into existence. Peace is now being torn apart as the former King has disturbed the balance and brought the continent to the brink of destruction. As the constant struggle between light and darkness wages on, it’s time to join the battle and awaken your inner hero!
- Game Features:
▲ CHOOSE YOUR PATH
Take up arms and protect the balance of the land or embrace the darkness that is destroying the land. The fate of Awaken is in your hands!
▲ ANYONE CAN COMPETE
All heroes have the same max star-rating, regardless of their initial summoning level. When you step onto the battlefield, strategy, and skill reign supreme!
▲ CINEMATIC-STYLE VISUALS
Get lost in an immersive story with captivating 3D artwork as your heroes unleash a variety of attack effects and skill animations!
▲ GATHER YOUR FORCES
With nearly 120 heroes from 8 different factions, assemble the right combination to dismantle your opponent!
▲ IMMERSIVE STORYLINE
Uncover the mysteries of Awaken as you follow the Evelyn and explore a narrative storyline filled with hero origins.
▲ LOTS TO EXPLORE
Climb the arena rankings in fast-paced PVP action, crawl through rogue-like dungeons, challenge tough guild bosses, track down wanted heroes to claim bounties, and much more!
elements of a story 在 Dainghia25 Youtube 的精選貼文
Destiny 2 (also known as Destiny 2: New Light) is a free-to-play online-only multiplayer first-person shooter video game developed by Bungie. It was originally released as a pay to play game in 2017 for the PlayStation 4, Xbox One, and Microsoft Windows platforms.[1][2] It became free-to-play under the New Light title on October 1, 2019, followed by the game's release on Stadia the following month, and then the PlayStation 5 and Xbox Series X/S platforms in November 2020 with an enhanced version released for both consoles on December 8, 2020. The game was published by Activision until December 31, 2018,[3] when Bungie acquired the publishing rights to the franchise. It is the sequel to 2014's Destiny and its subsequent expansions. Set in a "mythic science fiction" world, the game features a multiplayer "shared-world" environment with elements of role-playing games. Like the original, activities in Destiny 2 are divided among player versus environment (PvE) and player versus player (PvP) game types. In addition to normal story missions, PvE features three-player "strikes" and dungeons and six-player raids. A free roam patrol mode is also available for each destination which feature public events as well as activities not available in the original. These activities have an emphasis on exploration of the destinations and interactions with non-player characters (NPCs); the original Destiny only featured NPCs in social spaces. PvP features objective-based modes, as well as traditional deathmatch game modes.
#dainghia25
▶ SUBSCRIBE MY CHANNEL : https://goo.gl/VPOrGK
▶ RENUMBER LIKE, SUBSCRIBE AND SHARE MY VIDEO!!!
▶ Fanpage Facebook : https://www.facebook.com/dainghia25gaming
▶ Facebook : https://www.facebook.com/dainghia25
elements of a story 在 19 Story Elements--Narrative ideas - Pinterest 的推薦與評價
Sep 17, 2013 - From plot to falling action--and everything in between!. See more ideas about story elements, teaching reading, reading classroom. ... <看更多>
elements of a story 在 The elements of a story | Reading | Khan Academy - YouTube 的推薦與評價
... <看更多>