📜 [專欄新文章] 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.
👏 歡迎轉載分享鼓掌
同時也有186部Youtube影片,追蹤數超過304萬的網紅MosoGourmet 妄想グルメ,也在其Youtube影片中提到,@リンネル チャンネル リンネル 11月号増刊 特別付録のオサムグッズのシリコーンケーキ型を使ってスノースキン月餅を作ってみました。見た目はスノースキン感は弱いですが、月餅🥮の型がなくても、シリコン型で作れたのがポイント。伸びのよい柔らかな餅皮とホワイトチョコのミルキー感がとっても合います。包みやす...
「a is equal to 1」的推薦目錄:
- 關於a is equal to 1 在 Taipei Ethereum Meetup Facebook 的最讚貼文
- 關於a is equal to 1 在 Facebook 的最讚貼文
- 關於a is equal to 1 在 Facebook 的最佳解答
- 關於a is equal to 1 在 MosoGourmet 妄想グルメ Youtube 的最佳貼文
- 關於a is equal to 1 在 MosoGourmet 妄想グルメ Youtube 的最讚貼文
- 關於a is equal to 1 在 糖餃子Sweet Dumpling Youtube 的最佳解答
- 關於a is equal to 1 在 Grade 1 Math 5.9, Equal and not equal - YouTube 的評價
- 關於a is equal to 1 在 What Are Equal Numbers? | Mathematics Grade 1 | Periwinkle 的評價
- 關於a is equal to 1 在 Why is n divided by n equal to 1? - Math Stack Exchange 的評價
- 關於a is equal to 1 在 Sum of ten 0.1 floats is not equal to 1 [duplicate] - Stack Overflow 的評價
a is equal to 1 在 Facebook 的最讚貼文
Thank you Spotify for letting me be a part of #spotifyequal campaign! To see myself smiling big on the screen in time square is just something I couldn’t even imagine. I’m so pumped my face can’t even stop smiling. 🥰
Equal Playlist:
https://open.spotify.com/playlist/37i9dQZF1DX8oGHu3SOP0B?si=d7612409fd684336
a is equal to 1 在 Facebook 的最佳解答
Happy Malaysia Day! So much emotions to unpack today while I reveal these pieces. These three new artworks were created from soil gathered from East and West Malaysia.
I've been working on this project since Nov 2020, when Alvin Teoh, son of Malaysian war veteran, Major Andrew, contacted me asking if I’d want to create artworks to be shown in a documentary about Malaysian war veterans. One of my missions as an artist is to tell stories, especially meaningful ones about history, culture and heritage, so of course I said yes.
From the start, we knew that soil would be the main material to symbolise land that was fought for. Admittedly, there was a lot I didn't know about that the war and the vets - about the pain and reality of war, how it affected their families and lives, and their deep love for the country. I got to meet two vets in person before lockdown, and the rest I met through Zoom. I was also deeply touched by how there were so many Malaysians of various backgrounds who fought for our country - of all races, beliefs, backgrounds, and of Malaysians from East and West Malaysia. Swipe to see a sneaky screenshot I took of them.
As a Sabahan (East Malaysian), I hope these artworks and this documentary will also present East Malaysians as an equal to the West. That is the symbolism of gathering soil from both East and West Malaysia. The documentary will be shown tonight on Astro at 9pm (GMT + 8 ) on Channel 100. Happy Malaysia Day. ❤
///
Project credits:
Artist: Red Hong Yi
Fabricator: Huak Huak (Chuah Chong Yong, Foo Chee wee, Cheong Siew wei, Arman Simanjuntak)
Red’s art team: Chee Chung Leong (project lead), Waichun Yan, Esmond Sit, Kaiyi Wong, Kashinie Subramaniam, Shir Yee Sun, Shen Phang Lim, HuiQi Chan.
Videography: Chong Kern Wei
Photography: Aaron Wong, Annice Lyn
Production by Naga DDB and Mojo Films.
Apprentices supported under the @cendanamalaysia Apprenticeship Programme in Collaboration with Studio Red Hong Yi
///
a is equal to 1 在 MosoGourmet 妄想グルメ Youtube 的最佳貼文
@リンネル チャンネル リンネル 11月号増刊 特別付録のオサムグッズのシリコーンケーキ型を使ってスノースキン月餅を作ってみました。見た目はスノースキン感は弱いですが、月餅🥮の型がなくても、シリコン型で作れたのがポイント。伸びのよい柔らかな餅皮とホワイトチョコのミルキー感がとっても合います。包みやすい餅皮なので同量の餡でも包みやすいです。型離れのポイントは打ち粉。片栗粉を型や餅皮の側面に多めに振ってください。くっつかずに作業できます。型に餅が貼り付き、1回、失敗してしまいました。
昔から大好きだったオサムグッズ。付録でシリコン型が手に入るなんていい時代なんだ。
*レシピ*(およそ64mlの型 6個分)
ホワイトチョコ餡を作ります
1.ホワイトチョコ 42gを溶かす。
2.白あん 150gを入れ混ぜる。
3.6等分にする。
4.お好みにパウダーで着色する。
今回、かぼちゃパウダー・紫芋パウダー・いちごパウダー 各2g、バタフライピーパウダー・抹茶 各1gで着色しています。もちろんそのままでもOKです。
5.ラップで丸く包み、冷蔵庫または冷凍庫で冷やしておく。
餅皮を作ります。
6.耐熱ボウルに白玉粉 24g、水 96gを入れ粒がなくなるまで混ぜる。
7.加糖練乳 24g、サラダオイル 24gと上新粉 24g、薄力粉 8g、上白糖 24gをあわせてフルイ入れ、泡立て器で混ぜる。
8.ふんわりラップをして、600wの電子レンジで50秒加熱し泡立て器で混ぜる。
9.その後、20秒加熱を3回繰り返し、その都度、泡立て器で混ぜる。
10.更に20秒加熱を3回繰り返し、その都度、今度はゴムベラで混ぜる。
11.更に今度はラップをしないで、1分30秒加熱し混ぜないでそのまま粗熱を取る。
12.片栗粉を広げたバットなどに(11)を6等分する。
13.ラップの間に(12)を伸ばす。
14.(5)を包む。
15.シリコン型に押し込む。
16.冷蔵庫で冷やす。
17.型から取り出す。
18.でけた。かわいいうまい。オサムグッズかわいい。永遠だな。
I made snow skin mooncakes using the silicone cake mold of OSAMU GOODS. It doesn't look like snow skin, but the key is that it can be made with a silicone mold even if you don't have a mooncake 🥮 mold.The milky texture of the white chocolate goes well with the soft and stretchy rice cake skin. Since it is a rice cake skin that is easy to wrap, it is easy to wrap even the same amount of bean paste. The key to mold release is flour. Sprinkle more potato starch on the sides of the mold and the rice cake skin. You can work without sticking. Mochi stuck to the mold and I failed once. I've always loved OSAMU GOODS. It's a good time to get a OSAMU GOODS silicone mold in a magazine freebie.
* Recipe * (for 6 molds of about 64 ml)
Make white chocolate bean paste.
1.Melt 42g of white chocolate.
2.Mix in 150g of white bean paste.
3.Divide into 6 equal parts.
4.Color with powder as desired. This time, I used 2g each of pumpkin powder, purple sweet potato powder, and strawberry powder, and 1g each of butterfly pea powder and matcha. Of course, you can leave them as they are.
5.Wrap in plastic wrap and chill in the refrigerator or freezer.
Make mochi skin.
6.Put 24g of Shiratamako and 96g of water in a heat-resistant bowl and mix until there are no grains.
7.Add 24g of sweetened condensed milk, 24g of salad oil, 24g of Joshinko, 8g of cake flour, and 24g of white sugar, and mix with a whisk.
8.Wrap it gently, heat it in a 600w microwave oven for 50 seconds, and mix it with a whisk.
9.Repeat heating for 20 seconds 3 times, mixing with a whisk each time.
10.Repeat heating for another 20 seconds three times, each time mixing with a rubber spatula.
11.Furthermore, without wrapping this time, heat for 1 minute and 30 seconds and remove the heat as it is without mixing.
12.Divide (11) into 6 equal parts on a tray with potato starch spread.
13.Spread (12) between sheets of plastic wrap.
14.Wrap (5).
15.Press into the silicon mold.
16.Chill in the refrigerator.
17.Remove from the mold.
18.It's done. Cute and delicious. OSAMU GOODS are eternal.
#SnowSkinMooncakes #recipe #月餅 #作り方 #オサムグッズ #リンネル #雑誌付録
![post-title](https://i.ytimg.com/vi/d64B6VmWtvU/hqdefault.jpg)
a is equal to 1 在 MosoGourmet 妄想グルメ Youtube 的最讚貼文
9月21日は十五夜です。陽キャ顔の3Dうさぎさんとお月見はいかがですか?
*レシピ*(5ぴょん分)
1.耐熱ボウルに上新粉 100g、砂糖 40gを入れ混ぜる。
2.混ぜながら、ぬるま湯を少しずつ入れ、耳たぶくらいの固さにする。今回70g弱加えました。
3.ふんわりラップをして、600wの電子レンジで1分40秒加熱。白っぽいところが残っていたらザッと混ぜ、様子を見ながら加熱をする。今回、20秒追加加熱しました。
4.水で濡らしたすりこぎなどの棒で滑らかになるまでつく。
5.触れるくらいまで冷めたら、水で濡らした手で50回ほどこねる。
6.餅を5等分(1個 40g)にし、楕円に伸ばす。
7.耳になる部分を折り、切り込みを入れる。
8.お好みの餡を薄く塗る。今回はさつまいもの塩バター餡にしました。お餅が甘いので無くても大丈夫です。
9.餡を包む。切り込み部分の端が気持ち隠れるまで巻き込むとよいです。
10.海苔で顔を付ける。
11.でけた。
えらくポップなウサギさんになっちゃったけど、お月見を楽しみましょう。
September 21st is the full moon in Japan. How about moon viewing with a 3D origami rabbit with a cheerful character face?
* Recipe * (for 5 rabbits)
1.In a heatproof bowl, mix 100g of Joshinko and 40g of sugar. ( Joshinko : top-grade rice flour made from non-glutinous rice. )
2.While mixing, add lukewarm water little by little to make it as hard as an earlobe. I added a little less than 70g this time.
3.Cover with plastic wrap softly and heat it in a 600w microwave for 1 minute and 40 seconds.If any whitish areas remain, mix them briefly and heat while watching the situation. This time, it was additionally heated for 20 seconds.
4.Use a stick such as a wet pestle to pound the mixture until it becomes smooth.
5.When it is cool enough to touch, knead it with wet hands about 50 times.
6.Divide the rice cake into five equal portions (40g each) and roll out into an oval.
7.Fold the part that will be the ears and make a notch.
8.Spread a thin layer of your favorite bean paste. This time, I used sweet potato salt butter bean paste.The rice cake is sweet, so you can do without it.
9.Wrap the bean paste. It's best to roll it in until the end of the notch is hidden.
10.Put a face on it with nori (seaweed).
11.It's done.
It turned out to be a very poppy rabbit, but let's enjoy Otsukimi.
#月見 #餅 #うさぎ #Mochi #Rabbit #viewingthemoon
![post-title](https://i.ytimg.com/vi/gu3Ljmtyn6I/hqdefault.jpg)
a is equal to 1 在 糖餃子Sweet Dumpling Youtube 的最佳解答
Hello friends! Today we're going to share with you how to make New York Levain Bakery style chocolate chip walnut cookies.
Chocolate chip cookies are a timeless classic, an unparalleled snack. No one can resist the comfort of a chocolate chip cookie. Like many of you, we’ve searched far for the perfect chocolate chip cookie recipe. And finally we’re so happy to find a perfect one. It's a copycat version of a very famous New York City bakery “Levain Bakery”. But the taste is amazing, and the size is really big, 6 oz each, but we modify the size to 4 oz each, the size is perfect.
Levain bakery style chocolate chip cookies are really delicious, they are golden brown on the outside, and soft gooey and rich center inside. It’s super simple to make and tastes perfect every time. if you love walnuts and chocolate, then this is a cookie for you. Hopefully you guys will like it.
📍 Please follow me on Instagram: https://www.instagram.com/sweetdumplingofficial/
📍 Welcome to follow me on FB: https://www.facebook.com/sweet.dumpling.studio
----------
How to make Levain Style Chocolate Chip Walnut Cookie
Here is the Levain Style Chocolate Chip Walnut Cookie Recipe
☞ Yields: 6 four-ounce cookies or 4 six-ounce cookies
✎ Ingredients
COLD unsalted butter 112g, cut into small cubes
granulated sugar 50g
brown sugar 75g
cake flour 70g
all-purpose flour 105g
large egg 1
baking powder 2g
baking soda 2g
salt 2g
walnut 82g
64% chocolate chip 150g
✎ Instructions
1. Sift the cake flour, all-purpose flour, baking soda, baking powder together, and add in salt, mix well and set aside.
2. Break the walnuts into two equal parts with your fingers.
3. Beat the egg and set aside.
4. In a large mixing bowl, cream together cold cubed butter, brown sugar, granulated sugar and egg on low speed and until mixed well.
5. Add all the dry ingredients in, including cake flour, all-purpose flour, baking soda, baking powder, beat on low speed until the wet and dry ingredients are all mixed together. Scraping down the sides of the bowl if necessary.
6. Simply fold in the chocolate chips and walnuts into the bowl, and mix until just combined to avoid over mixing.
7. For best results, refrigerate the dough for 15 minutes before forming the cookie dough. Cover plastic wrap to avoid dryness.
8. Divide the dough into 6 equal pieces about 4oz (113g) each. Roughly shape the cookie dough into loosely shaped balls.
9. Cover with plastic wrap and refrigerate the cookie doughs for 45 minutes.
10. Preheat the oven to 220°C, and bake for 12-14 minutes. Bake 3 cookies at one time.
11. Once baked. Let cool on the baking sheet for 30 minutes before serving.
-----------------------------------------------------------------------
Chapter:
00:00 opening
00:35 Ingredients
01:27 preparation
03:47 how to make cookie dough
07:14 cookie dough weight and shape
08:44 oven setting and baking
09:43 best ever chocolate chip cookies
-----------------------------------------------------------------------
#ChocolateChipCookie
#LevainBakery
#easyrecipes
![post-title](https://i.ytimg.com/vi/YnJNPn5zgMk/hqdefault.jpg)
a is equal to 1 在 Why is n divided by n equal to 1? - Math Stack Exchange 的推薦與評價
ab is, by definition, the solution of the equation bx=a. Thus nn is the solution to the equation nx=n. Assuming n≠0, this equation has the unique solution ... ... <看更多>
a is equal to 1 在 Grade 1 Math 5.9, Equal and not equal - YouTube 的推薦與評價
... <看更多>