📜 [專欄新文章] 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.
👏 歡迎轉載分享鼓掌
同時也有19部Youtube影片,追蹤數超過9,750的網紅Dainghia25,也在其Youtube影片中提到,Ratchet & Clank : Rift Apart The Tales of History All Spybot Showcase Spybots are a bit similar to Gold Bolts, except there's only ever one in ...
「up for grabs」的推薦目錄:
- 關於up for grabs 在 Taipei Ethereum Meetup Facebook 的精選貼文
- 關於up for grabs 在 Facebook 的最佳貼文
- 關於up for grabs 在 Facebook 的最佳解答
- 關於up for grabs 在 Dainghia25 Youtube 的最讚貼文
- 關於up for grabs 在 National Football News Youtube 的最佳解答
- 關於up for grabs 在 てぬキッチン/Tenu Kitchen Youtube 的精選貼文
- 關於up for grabs 在 英文成語up for grabs 是甚麼意思? 1大家爭著搶。 However the... 的評價
- 關於up for grabs 在 Everything is up for grabs - English Stack Exchange 的評價
- 關於up for grabs 在 up-for-grabs.net - GitHub 的評價
- 關於up for grabs 在 Up for grabs Meaning - YouTube 的評價
up for grabs 在 Facebook 的最佳貼文
Annyeong ! 馬來西亞唯獨全部韓國入口美容美妝美髮正品 我們的粉丝特别优惠從RM5一個產品起跳‼️ @onlykorea_asia
BTS fans ! Limited Editions are up for grabs ! Products from RM5 hurry up !
Discounts, Free Gifts and free deliveries by using code LENGYEIN / LENGSEAN
🎁送出200份总值RM60,000的赠品🎁
🎁送出200份总值RM60,000的赠品🎁
🎁送出200份总值RM60,000的赠品🎁
DISCOUNT/FREE GIFTS/PROMO CODE : LENGYEIN
DISCOUNT/FREE GIFTS/PROMO CODE : LENGSEAN
联系以下号码索取优惠🔻🔻🔻
WhatsApp : +60 17 211 7804
WhatsApp : +60 17 211 7940
🛒Lazada : OnlyKorea
🛒Shopee : OnlyKorea_Official
🛒Facebook : OnlyKorea Malaysia
🛒Instagram : Onlykorea_asia
欢迎光临我们的门市➡️➡️➡️
📍OnlyKorea Sunway Pyramid
📍OnlyKorea Aeon Tebrau City
DISCOUNT/FREE GIFTS/PROMO CODE : LENGYEIN
DISCOUNT/FREE GIFTS/PROMO CODE : LENGSEAN
#BTSOfficial #OnlyKoreaMalaysia #OnlyKoreaAsia #OnlyKorea #BTS #VTxBTS #BT21 #LineFriends #Skincare #Makeup #Beauty
up for grabs 在 Facebook 的最佳解答
Let’s join the OMG (Oh Munchy’s Goodness) Scan, Play & Win contest. You might be one of the lucky 30 winners to score a Nintendo Switch! 🤩
How to join:
1) Log on to www.munchys30.com
2) Register via your Facebook and start playing!
3) Collect as many points as possible by catching the biscuits that come down the production line during game-play.
4) The more you play and the higher you score, the higher your chance of winning!
The #OMG30 Scan, Play & Win contest runs from 1st September to 31st October 2021, with 30 units of Nintendo Switch up for grabs. Don’t miss out! Winners will be announced weekly. 🎁
#OhMunchysGoodness
#munchysmy
up for grabs 在 Dainghia25 Youtube 的最讚貼文
Ratchet & Clank : Rift Apart The Tales of History All Spybot Showcase
Spybots are a bit similar to Gold Bolts, except there's only ever one in any given level (with one exception: Zurkie's). You'll need to collect all 10 of them to unlock a super secret and super powerful weapon, but you can also listen to them in the Collectibles menu to get some lore and backstory on each world.
Ratchet and Rivet are working for the resistance against the Emperor. It's through this narrative that they constantly meet Ms. Zurkon, who sells you the various weapons you use in the game. She also asks you to go and rescue her ten Spybots, who are hidden in various hard to reach areas of the map. There are ten Spybots in total, spread across the nine planets - that's one to a planet each, with two up for grabs at Scarstu Debris Field, AKA Zurkie's.
Once you have a full selection, Ms. Zurkon will reward you with a legendary Ratchet & Clank weapon - the RYNO 8. If you want to rip this universe a new one, you'll need all ten Spybots on hand.
▶ 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

up for grabs 在 National Football News Youtube 的最佳解答
Speak for Yourself | Wiley reacts to NFC East is still up for grabs with Cowboys win over Eagles

up for grabs 在 てぬキッチン/Tenu Kitchen Youtube 的精選貼文
〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓
\お陰様で再度重版していただき6万5千部に!本当に本当にありがとうございます!/
『世界一ラクチンなのに超美味しい!魔法のてぬきごはん』
↓
https://www.amazon.co.jp/dp/4847099621
ただいま重版記念フェアを開催していただいております!対象店舗で『魔法のてぬきごはん』をご購入いただいた方に〝ミニまな板〟をプレゼント。詳細や対象店舗などはこちらからご覧ください。
↓
https://www.wani.co.jp/event.php?id=6914?key=1100
\15万部突破!!お菓子レシピ本大賞♪/
『材料2つから作れる!魔法のてぬきおやつ』
↓
https://www.amazon.co.jp/dp/484709879X/
Amazon、その他ネット書店、全国の本屋さんで販売していただいております!
ぜひチェックしていただけると嬉しいです♪
〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓
▽〝チーズタッカルビ風湯豆腐〟の詳しいレシピはこちらのブログから♪
『てぬキッチンのブログ』⇒ https://www.tenukitchen.com/entry/2020/12/23/234820
▽twitterもやっているので、もし『てぬキッチン』のレシピをお試し頂いたら、#てぬキッチン をつけて投稿してもらえると嬉しいです♪
『てぬキッチンのtwitter』⇒ https://twitter.com/tenu_kitchen
【チーズタッカルビ風湯豆腐】
今日は、寒い日に超オススメの『チーズタッカルビ風湯豆腐』を作りました!
チーズタッカルビの甘辛いコチュジャンの味付けでお肉なしでお豆腐で、しかもレンジでチンだけで簡単に作りました!これ糖質オフでめちゃ旨!!
コチュジャンで止まらない美味しさでチーズが合う!速攻温まるので今の時期にぜひぜひお試しいただきたい一品です♪
〈材料〉一人分
絹豆腐 150g
☆キムチ 30g
☆コチュジャン 小さじ1
☆醤油 小さじ1
☆ごま油 小さじ1/2
ピザ用チーズ 2つかみ
▽チャンネル登録はこちらから♪
⇒http://www.youtube.com/channel/UC1HZhN0HjriRUhqH7wGyRQg?sub_confirmation=1
【Cheese Dak-galbi style tofu】
Today, I made the highly recommended "Cheese Dak-galbi style tofu" on a cold day!
Cheese Dak-galbi seasoned with sweet and spicy gochujang, tofu without meat, and easily made with just chin in the microwave! This is messed up with sugar off! !!
Cheese goes well with the deliciousness that doesn't stop at Gochujang! It warms up quickly, so this is a must-try item at this time of year ♪
〈INGREDIENT〉For1
Silk tofu 150g
☆ Kimchi 30g
☆ Gochujang 1 teaspoon
☆ 1 teaspoon of soy sauce
☆ 1/2 teaspoon of sesame oil
2 grabs of cheese for pizza
▽Subscribe to my channel♪
⇒http://www.youtube.com/channel/UC1HZhN0HjriRUhqH7wGyRQg?sub_confirmation=1
◎お仕事の依頼等はこちらまで→tenukitchen_tenukin@yahoo.co.jp
------------------------------------------------------------------------------
楽曲提供:フリーBGM DOVA-SYNDROME by http://dova-s.jp/
効果音素材:ポケットサウンド – https://pocket-se.info/
--------------------------------------------------------------------------

up for grabs 在 Everything is up for grabs - English Stack Exchange 的推薦與評價
http://idioms.thefreedictionary.com/up+for+grabs. referring to the link above "up for grabs "is an idiom means:. ... <看更多>
up for grabs 在 up-for-grabs.net - GitHub 的推薦與評價
GitHub - up-for-grabs/up-for-grabs.net: This is a list of projects which have curated tasks specifically for new contributors. These issues are a great way ... ... <看更多>
up for grabs 在 英文成語up for grabs 是甚麼意思? 1大家爭著搶。 However the... 的推薦與評價
英文成語up for grabs 是甚麼意思? 1大家爭著搶。 However the case evolves, it's clear that Russia's political future is up for grabs. ... <看更多>