📜 [專欄新文章] 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.
👏 歡迎轉載分享鼓掌
同時也有100部Youtube影片,追蹤數超過56萬的網紅kottaso cook【kottaso Recipe】,也在其Youtube影片中提到,◆こっタソ動物園チャンネル 新しいチャンネルです!こちらもおヒマな時にどぞ。 ⇒https://www.youtube.com/c/こっタソ動物園-kottasoanimals ご視聴ありがとうございます。 Thank you for watching I want to deliver deli...
「the number of the amount of」的推薦目錄:
- 關於the number of the amount of 在 Taipei Ethereum Meetup Facebook 的最佳解答
- 關於the number of the amount of 在 Facebook 的最佳貼文
- 關於the number of the amount of 在 Facebook 的精選貼文
- 關於the number of the amount of 在 kottaso cook【kottaso Recipe】 Youtube 的最讚貼文
- 關於the number of the amount of 在 Zermatt Neo Youtube 的精選貼文
- 關於the number of the amount of 在 Zermatt Neo Youtube 的最佳解答
the number of the amount of 在 Facebook 的最佳貼文
Let's celebrate International Coffee month with NESCAFÉ®. During this coffee month, NESCAFÉ® rewarding their loyal customers with amazing prizes. “Peraduan NESCAFÉ® – Vibe Kopi” WhatsApp contest, offering 324 prizes worth a total of RM290,000.00 to be won, including 18 x Honda Vario 150 Repsol! The contest will be held from 6 September – 7 November 2021.
Here is how to participate:
Step 1 : Purchase a minimum of RM6 worth of any participating NESCAFÉ® Can/Bottle/Cup products in a single original receipt from any participating outlets (in-store or online).
Step 2 : Write your full name and identification number on the front of the receipt and submit a CLEAR picture of the receipt and total amount to the WhatsApp number: 018-388 0070. The contest participation is accepted via WhatsApp only.
More information check out @Nestle.Malaysia
#NESCAFEVibeKopi #NESCAFECans #readytodrink #coffee @inkpr.my
the number of the amount of 在 Facebook 的精選貼文
Sukacita saya ingin maklumkan bahawa Johor akan menerima sebanyak 1.9 juta dos vaksin Covid-19 pada bulan September ini. Daripada jumlah dos vaksin ini, sebanyak 1.76 juta adalah vaksin Pfizer.
Dengan jumlah dos ini saya yakin seluruh Bangsa Johor akan menerima vaksin tidak lama lagi. Bersama-sama kita doakan kejayaan program vaksinasi Covid-19.
DYAM Mejar Jeneral Tunku Ismail Ibni Sultan Ibrahim, Tunku Mahkota Johor
———
I'm pleased to inform that Johor will receive 1.9 million doses of Covid-19 vaccine in September. From this total number of vaccine doses, 1.76 million are the Pfizer vaccine.
With this amount of doses, I'm confident the entire Bangsa Johor will be vaccinated very soon. Let's together pray for the success of the Covid-19 vaccination programme.
HRH Major General Tunku Ismail Ibni Sultan Ibrahim, Crown Prince of Johor
the number of the amount of 在 kottaso cook【kottaso Recipe】 Youtube 的最讚貼文
◆こっタソ動物園チャンネル
新しいチャンネルです!こちらもおヒマな時にどぞ。
⇒https://www.youtube.com/c/こっタソ動物園-kottasoanimals
ご視聴ありがとうございます。
Thank you for watching
I want to deliver delicious Japanese-food recipes to the world
【材料】
●もやし:2袋(400g)
●牛豚の合挽き肉:約300g(豚挽肉だけでもOK)
●コチュジャン:大さじ2.5(豆板醤でもOK)
●醤油:大さじ1
●砂糖:大さじ1(ラカントにすると更に糖質抑えられます)
●オイスターソース:大さじ1
●みりん:大さじ1
●お酒:大さじ1
●にんにく:小さじ1/2
●生姜:小さじ1/2
●ごま油
●塩コショウ少々
●最後にブラックペッパー
お好みで万能ねぎ、ラー油、韓国唐辛子、一味唐辛子
※グラム数を同じくらいにしてお肉や野菜を変更しても美味しいよ♪
※辛いのが苦手な方はコチュジャンの量を減らして普通の味噌を足してあげて下さい。
※もやし入れたら強火で2~3分くらいでOK(量が少なかったらもっと短くても大丈夫)
※もやしのひげ根は栄養があるので気にならない方はとらなくても大丈夫です。
-------------------------------------------------------
食べれば食べるほどハマる…悪魔的旨辛『悪魔の肉もやし』作りました。
これあると、ご飯、お酒、ラーメンが鬼すすみます🤤
糖質制限されている方は肉もやしだけでも十分お腹一杯になりますよ。
残ったタレをご飯にぶっかけて食べても最高に旨いよ♪
たった5分炒めるだけの超簡単なレシピになっているので
是非作ってみて下さい。
[Ingredients]
● Bean sprouts (400g): 2 bags
● Ground beef and pork: about 300g (ground pork alone is also OK)
● Gochujang (soybean paste): 2.5 tablespoons
● Soy sauce: 1 tablespoon
● Sugar: 1 tablespoon (you can use LACANTS to further reduce sugar content)
● Oyster sauce: 1 tablespoon
● Mirin: 1 tablespoon
● Sake: 1 tablespoon
● Garlic: 1/2 teaspoon
● Ginger: 1/2 teaspoon
● Sesame oil
● A pinch of salt and pepper
● Black pepper at the end
Optional: scallions, Ra-yu, Korean chili pepper, cayenne pepper powder
※ You can use the same number of grams and change the meat and vegetables.
※ If you don't like spicy food, you can reduce the amount of gochujang
and add regular miso.
※ After adding the bean sprouts, cook on high heat for about 2~3
minutes. (If the amount is less, you can make it shorter.)
※ The beard root of bean sprouts is nutritious, so you don't need to
remove it if you don't mind.
-------------------------------------------------------
The more you eat, the more you become addicted... I made a devilishly
delicious and spicy "Devil's Meat & Bean Sprout'."
It's a great way to enjoy rice, drinks, and ramen!
If you are on a carbohydrate restriction diet, this menu alone will be
enough to fill you up.
You can also pour the leftover sauce over rice and eat it ♪
This is a very simple recipe that only takes 5 minutes to fry, so
please try making it.
●Instagram
⇒https://www.instagram.com/kossarishuntaso/
●twitter
⇒https://twitter.com/kottaso_recipe
●連絡先
⇒kossarisyuntaso@gmail.com
#こっタソの自由気ままに #悪魔の肉もやし #無限もやしユッケ #もやしレシピ #ひき肉レシピ #BeanSprouts #豆芽 #JapaneseCuisine #DevilsSauce #HealthyMenu #LowCarbDiet #숙주 #저당질 #악마의양념 #和食 #低糖質おつまみ #糖質制限レシピ #ヤセ筋 #低糖質レシピ #ヘルシー #ダイエットレシピ #激痩せ #ロカボレシピ #dietfood #lowcarbdiet #dietrecipe #晩ごはんレシピ #ご飯泥棒 #おかず #極上レシピ #ワンパンレシピ #時短レシピ #おうちごはん #至福の料理 #ご飯のお供 #太らないレシピ #やみつきレシピ #酒のつまみ #簡単つまみ #こっタソレシピ #男飯レシピ #mukbang #먹방 #男子ごはん #HomeCooking #StayHome #大食い #男ウケ料理 #晩酌 #自炊 #酒の肴 #簡単レシピ #弁当 #作り置き #Bento #recipesfordinner #マツコの知らない世界 #WithMe #Eazyrecipe #モッパン #から揚げ #唯一無二の絶品レシピ #こっタソ動物園
the number of the amount of 在 Zermatt Neo Youtube 的精選貼文
For this video, we went down to a special kitchen to whip up a massive 7KG Collagen Ramen Challenge with the help of Chantalle Ng (@chantalleng)! Chantalle is the star of the Mediacorp drama My Star Bride, playing the titular role in the form of a Vietnamese bride. The collagen broth comes from her very own brand, Yuan Collagen, which she co-founded with her friend Minying. The collagen is chicken-based and is extremely high in protein (10g per 100ml) with half the number of calories of your average collagen broth. The noodles we used were also provided by Chantalle’s company, a type of homemade egg noodles.
After a quick cooking process and with the help of some pre-cooked ingredients, Chantalle assembled the final bowl of noodles. It consisted of 11 portions of noodles, char siew, eggs, pork dumplings, seaweed and fried chicken, topped up with a healthy amount of the Chicken Collagen broth. It came up to almost 7KG and even more broth was added towards the end of the challenge.
It was a rich, nutritious and hearty ramen meal that I did not struggle to complete. Naturally, it was different from your typical Japanese ramen broths – a lot more “chickeny” in flavour and much thicker. The pre-cooked items were decent.
The strength of such a broth base is its versatility. You could use it for any dish you can imagine that requires some form of liquid to be added, such as risotto or hotpots. The broth acts as a flavourful and nutritious base for you to develop your meal on. In a pinch, you could even use it to cook instant noodles!
You can see more of Chantalle in her upcoming drama, Live Your Dreams, airing in September!
Purchase Chantalle’s broth here: www.yuanfoods.com
Connect with us!
Facebook - https://www.facebook.com/zermattneofls
Instagram - http://instagram.com/zermattneo
http://instagram.com/teegongborpi
Use code ZERMATT for 58% off ALL Myprotein products.
For those that are interested in doing ZenyumClear™️ Aligners:
https://bit.ly/zermattneo-yt
Use code ZERMATT100 for special discount!
Hair Sponsor - Toliv Salon
5 Purvis Street, #01-03, Singapore
https://www.facebook.com/tolivboutique
the number of the amount of 在 Zermatt Neo Youtube 的最佳解答
For this episode, we headed back to Neo’s Kitchen to attempt a LEVEL 99 SPICY MALA WONTON CHALLENGE! EB Food is organising a timed wonton challenge with the launch of their new product, EB Shrimp Wonton with Mala Sauce. Eating the greatest number of EB wontons in 5 minutes will net you a cash prize of $2000, with further cash prizes for 2nd and 3rd place. Full details listed below:
The EB Shrimp Wonton with Mala Sauce came neatly packed in a pleasantly-enough designed box that really undersold the potency of the Mala sauce. They were simple to cook - boil the 12 wontons for 5 minutes, warm up the Mala sauce in hot water and mix them all together. The Mala sauce was a menacing shade of red glistening with Mala oil radiating that signature Mala aroma. The wontons themselves respectably plumped up considerably during cooking. Each had a whole shrimp in them. When mixed together, each wonton ended up adopting an even shade of red with small clumps of Mala sauce noticeable throughout.
I attempted this challenge with Mervin (there is a buddy requirement). From the number of wontons we prepared versus the number consumed, it was clear that we underestimated this challenge. We thought it would be a speed challenge, but it ended up being a spice challenge due to our low spice tolerance and the unexpected heat of the Mala sauce. Out of the 100+ wontons we cooked, we only ate 48 between us within the 5 minutes limit.
Note that our attempt does not count for the official challenge, so please do find a buddy (preferably someone who loves Mala) and win yourself $2000! The wontons are also Halal, so Muslim viewers can join as well!
Follow these easy steps to qualify for the challenge:
1. Like and follow @ebfood.sg on both their Facebook and Instagram accounts
2. Complete the T&C Google form before joining the challenge: https://forms.gle/phDZn6q3RZ77gaYS6
3. Film and upload your challenge video on both your Instagram accounts:
- Tag @ebfood.sg and your buddy's account
- Hashtag #EBFrozenFood #BeatMAloveforLA #malasg
- Indicate the total amount of Mala Wonton consumed
- Set both accounts public
4. Send the original video with 5 minutes duration to: marketing@ebfood.sg
*Your full video should include the process of pouring and mixing all the Mala sauce given in the packaging.*
Cash Prizes:
1st Prize: $2000
2nd Prize: $1000
3rd Prize: $500
Winners will be contacted by email on 23 June 2021.
Reminder: In order to qualify for the challenge, do read through all T&Cs and rules carefully from the Google form.
Connect with us!
Facebook - https://www.facebook.com/zermattneofls
Instagram - http://instagram.com/zermattneo
http://instagram.com/teegongborpi
Use code ZERMATT for 58% off ALL Myprotein products.
For those that are interested in doing ZenyumClear™️ Aligners:
https://bit.ly/zermattneo-yt
Use code ZERMATT100 for special discount!
Hair Sponsor - Toliv Salon
5 Purvis Street, #01-03, Singapore
https://www.facebook.com/tolivboutique