📜 [專欄新文章] 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.
👏 歡迎轉載分享鼓掌
同時也有202部Youtube影片,追蹤數超過9萬的網紅Smart Travel,也在其Youtube影片中提到,#SmartTravel #娛樂八卦 #港姐複試 #香港恐怖歷史 #關禮傑大女 #當年今日 #風水師情騙 #網絡孽緣 #莫文蔚 #殺神4 #甄子丹 #梁朝偉 #莫文蔚辱華 #揭秘 #鍾麗緹 #香港首宗 #騎呢案件 #醜聞 #王菲 #謝霆鋒 #娛樂八卦 #懸疑片 #瘋傳 #有圖有真相 #甄妮 #甜妞...
「smart fun」的推薦目錄:
- 關於smart fun 在 Taipei Ethereum Meetup Facebook 的最佳解答
- 關於smart fun 在 BlenderBottle Facebook 的精選貼文
- 關於smart fun 在 charmmy3030 Facebook 的精選貼文
- 關於smart fun 在 Smart Travel Youtube 的最讚貼文
- 關於smart fun 在 Smart Travel Youtube 的最讚貼文
- 關於smart fun 在 Smart Travel Youtube 的精選貼文
- 關於smart fun 在 Smart Fun - Facebook 的評價
- 關於smart fun 在 聰明動Smart Fun - YouTube 的評價
smart fun 在 BlenderBottle Facebook 的精選貼文
Company Description
Trove Brands (formerly known as BlenderBottle) is a privately-held house of brands including BlenderBottle®, Owala™, Avana®, and Whiskware™. Our patented and best-selling products are designed to simplify and improve everyday life with leading-edge innovation, incomparable quality, and aspirational style.
A career at Trove Brands is not about punching the clock. It’s about embracing exciting and fast-paced opportunities that sharpen your skills, drive innovation, and play an integral role in growing our global reach. Your work will not only impact the company, it will impact the lives of millions of people around the world. When you step up to a career at Trove, you step up to cutting-edge excellence. You sign up for bold action and invigorating synergy. You agree to face—and break through—new challenges every single day.
Job Description
As a Warehouse Associate at Trove Brands, you will coordinate the receiving, preparation, and shipping of product. You’ll play an integral role in the efficiency of our inbound and outbound supply chain.
But that’s not all.
You’ll become part of the Trove Brands family, which means being a part of a fun, fast-paced, and team-focused work culture. We work hard, and we play just as hard. We have the facilities for it, too—like our state-of-the-art fitness center, yoga studio, basketball/pickleball/volleyball court, and golf simulator. We host fitness classes, team-building activities (think pickleball, volleyball, and dodgeball tournaments), wellness challenges, and more.
Once you’ve worked up an appetite working and working out, you’ll enjoy our onsite marketplace with subsidized food and drinks, monthly catered lunches, and company-wide birthday treats (and with a company of 180+ team members and growing, there are bound to be treats a few times each week.)
You’re sure to love the culture at Trove, where entrepreneurial thinking is encouraged and you and your colleagues share an eagerness to learn. Your hard work will be recognized and you’ll feel that your contributions matter. You’ll be surrounded by kind, creative, interesting people with a zest for life—which is perfect, since you’re one, too. At Trove, we’re big on creating lasting friendships and making work feel less like work and more like a great way to spend the day.
Career-wise, your role will be a starting point, with plenty of potential to learn and grow. We’ll support you with coaching, mentoring, personal development, cross training, and leadership opportunities. You’ll benefit from twice yearly pay increase reviews and structured career ladders. You’ll never be bored, because we have plenty to do and it’s certainly fast paced; you’ll also enjoy a reasonable work/life balance (unlike many warehouse jobs, our schedule is primarily M-F during standard business hours). We even offer some flexibility with student schedules.
Yes, you’ll find all that in an extremely clean, well-organized environment that’s flooded with natural light, and filled with team members dedicated to workplace safety.
Now that we’ve caught your attention, here’s a bit more about what this particular role entails.
As a Warehouse Associate, you’ll be expected to be a leader in all aspects of the Fulfillment Team's job duties. You’ll apply your relentless drive and strong work ethic to encourage solid production numbers from yourself, as well as from others. While every role at Trove Brands is critical to our successful functioning as a whole, your specific responsibilities will include:
• Direct the general fulfillment of orders by example
• Strategize inbound receiving procedures
• Lead varying warehouse team projects, ensuring maximum group efficiency
• Manage warehouse organization, general cleanliness, and safety procedures
• Verify outbound shipments and coordinate documents to guarantee vendor compliance
Qualifications
We’re looking for team members who are adept at contributing their personal expertise to a collaborative work environment. We want people who are ready, willing, and eager to jump into the working world, learn new skills and apply existing ones, and grow in their careers. For this role, we’re specifically looking for someone with the following skills and experience:
• General Warehousing experience
• Strong communication skills
• Enjoy working in a fast-paced environment, proactive and highly motivated
• Keen attention to detail
Additional Information
Our culture is passionate, entrepreneurial, and energetic. We value innovation through collaboration. And while we work smart and hard, we also connect and celebrate with equal gusto. We host team-building activities, athletic events, and seasonal celebrations to foster community and reward accomplishments. Bottom line? You’ll love it here.
Among the many benefits our team members enjoy are:
- Full indoor basketball/volleyball court
- Fully equipped fitness center and yoga studio
- Meditation/Nap Room
- And more!
smart fun 在 charmmy3030 Facebook 的精選貼文
Ning Ning having some colouring fun, one of her favourite activities at the moment. 🖍
@joshandcheriebooks recently launched their Colouroo Search and Colour Mats. Thanks for sending these over for Ning Ning to try it out!
I love sustainable products like this, reusable and friendly for our environment and safe for our little ones as it’s FDA-approved. It’s pretty fuss free too.
Simply wipe it off with wet wipes or wet tissue papers, works well on both the mat and on Ning Ning’s hands too. Other than colouring, which is a great activity for recognising colours and using their creativity with the mix and match of colours, I also like the search and count concept. What a smart idea!!💡
This Coloroo mat is also good on the go. Simply roll it out and we can use this as a mat and can keep Ning Ning occupied during dining out. No need screen time while eating 👏🏻
Go check them out at @joshandcheriebooks, they are currently having a launch promo till 3 Sep with 15% off all Colouroo mats. Don’t miss it, Ning Ning is already eyeing the Under The Sea series as she likes the jelly fish. 😆
#joshandcheriebooks #colouroo #coloringtime #kidsactivities #toddlersg #toddlerplay #sgchildren #sgkids #stayhomeactivities #letthembekids #siliconmat #colouringmat #coloringactivities #coloringfun
smart fun 在 Smart Travel Youtube 的最讚貼文
#SmartTravel #娛樂八卦 #港姐複試 #香港恐怖歷史 #關禮傑大女 #當年今日 #風水師情騙 #網絡孽緣 #莫文蔚 #殺神4 #甄子丹 #梁朝偉 #莫文蔚辱華 #揭秘 #鍾麗緹 #香港首宗 #騎呢案件 #醜聞 #王菲 #謝霆鋒 #娛樂八卦 #懸疑片 #瘋傳 #有圖有真相 #甄妮 #甜妞 #鍾鎮濤 #傅聲 #傅聲死亡靈異事件 #網友來電 #靈異經歷 #靈異事件 #轟動全港 #都市傳說 #香港新聞 #本地新聞 #真人真事 #陳振聰
【空姐爆料】系列, 專業人士、家庭主婦、OL、行政人員、男士、傳媒亦喜歡報導我的呢個 #SmartTravel, 可以滿足你 #娛樂、輕鬆、#剝花生 #旅遊資訊 #平吃買玩 #各地文化, 要睇梗係睇原汁原味, 你係咩人就會支持返咩嘅youtuber, 國際華人傳媒, 最喜歡報道Smart Travel
https://youtube.com/playlist?list=PLhKZNoNE4iEf-Rsl1fa8Um8aY2Yl86Q95
大家可以透過Payme, 支持下我, 打賞打賞鼓勵鼓勵:
https://payme.hsbc/smarttravel
?合作邀約請洽
gold7778@gmail.com
https://www.instagram.com/gold7778t/
成為這個頻道的會員並獲得獎勵:
https://www.youtube.com/channel/UCIuNPxqDGG08p3EqCwY0XIg/join
請用片右下角調4K睇片。
![post-title](https://i.ytimg.com/vi/04FqkAelx70/hqdefault.jpg)
smart fun 在 Smart Travel Youtube 的最讚貼文
#SmartTravel #娛樂八卦 #港姐複試 #香港恐怖歷史 #關禮傑大女 #當年今日 #風水師情騙 #網絡孽緣 #莫文蔚 #殺神4 #甄子丹 #梁朝偉 #莫文蔚辱華 #揭秘 #鍾麗緹 #香港首宗 #騎呢案件 #醜聞 #王菲 #謝霆鋒 #娛樂八卦 #懸疑片 #瘋傳 #有圖有真相 #甄妮 #甜妞 #鍾鎮濤 #傅聲 #傅聲死亡靈異事件 #網友來電 #靈異經歷 #靈異事件 #轟動全港 #都市傳說 #香港新聞 #本地新聞 #真人真事 #陳振聰
【空姐爆料】系列, 專業人士、家庭主婦、OL、行政人員、男士、傳媒亦喜歡報導我的呢個 #SmartTravel, 可以滿足你 #娛樂、輕鬆、#剝花生 #旅遊資訊 #平吃買玩 #各地文化, 要睇梗係睇原汁原味, 你係咩人就會支持返咩嘅youtuber, 國際華人傳媒, 最喜歡報道Smart Travel
https://youtube.com/playlist?list=PLhKZNoNE4iEf-Rsl1fa8Um8aY2Yl86Q95
大家可以透過Payme, 支持下我, 打賞打賞鼓勵鼓勵:
https://payme.hsbc/smarttravel
?合作邀約請洽
gold7778@gmail.com
https://www.instagram.com/gold7778t/
成為這個頻道的會員並獲得獎勵:
https://www.youtube.com/channel/UCIuNPxqDGG08p3EqCwY0XIg/join
請用片右下角調4K睇片。
![post-title](https://i.ytimg.com/vi/KJzhBbQbABg/hqdefault.jpg)
smart fun 在 Smart Travel Youtube 的精選貼文
#SmartTravel #香港恐怖歷史 #莫文蔚 #殺神4 #甄子丹 #梁朝偉 #莫文蔚辱華 #揭秘 #鍾麗緹 #香港首宗 #騎呢案件 #醜聞 #王菲 #謝霆鋒 #娛樂八卦 #懸疑片 #瘋傳 #有圖有真相 #甄妮 #甜妞 #鍾鎮濤 #傅聲 #傅聲死亡靈異事件 #網友來電 #靈異經歷 #靈異事件 #轟動全港 #都市傳說 #香港新聞 #本地新聞 #真人真事
【空姐爆料】系列, 專業人士、家庭主婦、OL、行政人員、男士、傳媒亦喜歡報導我的呢個 #SmartTravel, 可以滿足你 #娛樂、輕鬆、#剝花生 #旅遊資訊 #平吃買玩 #各地文化, 要睇梗係睇原汁原味, 你係咩人就會支持返咩嘅youtuber, 國際華人傳媒, 最喜歡報道Smart Travel
https://youtube.com/playlist?list=PLhKZNoNE4iEf-Rsl1fa8Um8aY2Yl86Q95
大家可以透過Payme, 支持下我, 打賞打賞鼓勵鼓勵:
https://payme.hsbc/smarttravel
?合作邀約請洽
gold7778@gmail.com
https://www.instagram.com/gold7778t/
成為這個頻道的會員並獲得獎勵:
https://www.youtube.com/channel/UCIuNPxqDGG08p3EqCwY0XIg/join
請用片右下角調4K睇片。
![post-title](https://i.ytimg.com/vi/udFxJWSJdpE/hqdefault.jpg)
smart fun 在 聰明動Smart Fun - YouTube 的推薦與評價
Smart Fun 幼兒體適能器材的專屬頻道器材全數於公司自行研發 喜歡的朋友記得按讚+訂閱哦 臉書Smart Fun IG smartfun_tw. ... <看更多>
smart fun 在 Smart Fun - Facebook 的推薦與評價
Smart Fun, 新北市. 1156 likes. 創新的器材~用的安心,玩的更開心。 ... <看更多>