📜 [專欄新文章] 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.
👏 歡迎轉載分享鼓掌
同時也有1105部Youtube影片,追蹤數超過13萬的網紅mocotarou / crochet,也在其Youtube影片中提到,こんにちは、ご覧頂きありがとうございます。下のレシピも参考にしてください。 ----------------------------------------- [使用した毛糸] ユザワヤ: フリーソック カラー:D47-07 1玉 下の楽天ルームに載せています。 [使用したかぎ針] ...
「explanation」的推薦目錄:
- 關於explanation 在 Taipei Ethereum Meetup Facebook 的最佳貼文
- 關於explanation 在 Facebook 的最佳貼文
- 關於explanation 在 Food of Hong Kong by Epicurushongkong Facebook 的精選貼文
- 關於explanation 在 mocotarou / crochet Youtube 的最佳貼文
- 關於explanation 在 mocotarou / crochet Youtube 的最佳解答
- 關於explanation 在 mocotarou / crochet Youtube 的最佳解答
explanation 在 Facebook 的最佳貼文
Family Twinning Up the Level 💯 😉 #welfietime! Who wore 👓 it better??
Checking out new glasses 👓 from @optical88sg at their new store in @northpointsg, north wing, lv1!
Their staff were super friendly and very patient in the explanation of the products and services thru out the process!
It was a delightful trip down for our regular check up too as their have a Children’s Myopia Centre! As much as I hope the boys never have to wear specs 🤓 hee, but they do looked so cute with the frames 🤦🏻♀️ looking even more liked their daddy now 😝
Apart from catering to the young and fashionistas, there’s also a progressive lens corner for the elderly - and now they are running a storewide promo of 20% off all glasses,
frames and even photochromic lens (anti-glare lens) inclusive of free eye check (normally it’s $20 per pax)! 👍🏻👍🏻👍🏻👍🏻👍🏻
explanation 在 Food of Hong Kong by Epicurushongkong Facebook 的精選貼文
🌟🌟 Hong Kong Sea Urchin & Egg Omelette Sandwich HKD $58 海膽煎蛋三文治. This is quite strong in the respective ingredient aromas here, no weird add ons to cover up the tastes, good!
🌟 Tofu Fa with Ginger 薑汁豆腐花 $12. Very smooth despite eating the cold version, with some natural soy beans taste too, which is rare in HK nowadays. Definitely up there in HK Top 3 in recent years. No need to add the red sugar, I just put some in for the photo contrast 📸
🌟🌟 Refrigerated Milk Tea 無冰凍奶茶 (1 glass) $15. It comes as either plain or with ginger juice, also available as whole bottles. Super strong yet smooth 👍🏻👍🏻
🌟 秘製咸檸茶 $20 Proprietary Salted Lemon Tea. Also super greatly balanced, natural tasting. Buy one for the hiking!
🤷🏻♂️ Sea Urchin Fried Rice 海膽炒飯 $118. Inevitably this won't be that amazing, but it does use local HK Sea Urchins, unlike the shops near central Sai Kung 西貢碼頭 which in recent years switched to US or Canadian urchins (unless u find the Urchin Boat parked outside, then order from it directly 🛶).
🌟 椒鹽魷魚 Fresh Local Calamari Salt & Pepper style $118 (not ordered this round). The version here carries a 'secret', but no one writes about it somehow. Their proprietary recipe carries some curry flavor 咖哩味, so it's actually a 咖哩椒鹽魷魚 but it's not recorded down officially 🤔 Not sure if I am even suppose to write this online but there u go?
_____
【Tap Mun 塔門 Island, Sai Kung, Hong Kong】is famous for eating these items plus more, it isn't new. But there are some catches that u need to write an explanation book of 📖. Since there are only 5 to 6 shops on the island selling any form of food, and 3 shops converged to sell similar items. But there are indeed differences:
📍新漢記海鮮酒家 = 唔係粉嶺客家菜嗰間 🤣 was always here, selling local Seafood dishes. But they also sell the above. U come for local prawns & squid cuttlefish, fishes, etc
📍新惠和 = *here, is considered the Best for overall recipes of the above, plus their drinks are equally thoughtful
📍新有記 = was originally only a store 士多. But later on they opened a new kitchen at back, then started copying food from the other 2 shops. It's not meant to be as good, but somehow their 鮮炸墨魚丸 is considered the best
explanation 在 mocotarou / crochet Youtube 的最佳貼文
こんにちは、ご覧頂きありがとうございます。下のレシピも参考にしてください。
-----------------------------------------
[使用した毛糸]
ユザワヤ:
フリーソック
カラー:D47-07
1玉
下の楽天ルームに載せています。
[使用したかぎ針]
6号(3.5㎜)
-------------------------------------
[チャプター]
00:00 毛糸の説明
02:09 編み始め
07:33 かたちに悩みます。
09:48 解いて糸をカット
16:06 長さを編みます。
17:26 糸始末
19:57 完成しました。
[レシピ]
・1段~10段:ダイアゴナルステッチで編みます。
・糸をカットして、編み始めの側から糸を繋げます。
繋げる所はお好みで決めて下さい。私は台形になるように繋ぎました。
・11段~:ダイアゴナルステッチで糸のある限り編みます。
[サイズ]
長辺162cm、短辺134cm、幅14cm
---------------- 本 ---------------
『カンタン&かわいい&すぐできる! かぎ針で編む モコタロウの編み小物』
ワニブックスさんより発売中です。
全国の書店、Amazon、楽天等でお買い求め頂けます。
Amazon
https://amzn.to/37JxgoJ
Kindle版
https://amzn.to/3zOOnBK
写真を大きくしたりできるので見やすいと思います。
紹介動画
https://youtu.be/b04l1xdfb0A
よろしければ見てみて下さい。
下の楽天ルームにも載せています。
-----------------------------------
[私の趣味の部屋]
https://room.rakuten.co.jp/room_7f8d1f716c/items
この楽天ルームに使った糸や気に入った物を載せています。
--------------- S N S --------------
[Instagram]
https://www.instagram.com/mocotarou10
完成した作品の画像をUPしています。
[Twitter]
https://twitter.com/mocotarou10
動画UPをお知らせします。
------------- サブチャンネル ----------
[mocotaのおうち]
https://www.youtube.com/channel/UCKowbiPymzaJ4s-AuORQGyg/
Vlogとか購入品紹介等
---------- チャンネル登録 ---------
[登録用リンク]
https://www.youtube.com/channel/UChtBfT4OJEGEfnYimkuX2mQ?sub_confirmation=1
最新動画等が見やすくなります。
ぜひチャンネル登録宜しくお願いします。
---------- 作品販売 ---------
メルカリ:https://www.mercari.com/jp/u/985022433/
※基本的には毎週土曜日に出品していますが
出品しなかったり、出品する日が前後することもあります。
よろしくお願いいたします。
-------- オンラインクラス -----------
your schoolはクリエイターさんのストーリーやスキル/価値観を狭く深く伝え、ユーザーのみなさんにより深く学ぶ機会や選択肢を提案するオンラインクラスのマーケットプレイスです。
HP : https://yourschool.jp/
YouTube : https://www.youtube.com/c/yourschool-youtube/videos
-------- オリジナルロゴグッズ --------
https://suzuri.jp/mocotarou10
--------------------------------------
[使用している道具など] ※Amazon Associate
かぎ針:チューリップ ETIMOかぎ針セット プレミアムゴールド TEG-001
https://amzn.to/2YNUerp
購入品紹介動画:https://youtu.be/eoUUb08wQ50
---------------------------------------------
Thank you for watching my videoes and for all your warm comments.
I think that my knitting videos showcase many parts of my own style,
which can be difficult to understand, but I will try to make the explanation as easy as possible.
I hope many people will enjoy knitting in the same way through my videoes.
I've been to a simple knitting class, but I usually go with my own flow.
I love handmade crafts, so in the past, I've been involved in Japanese-style dressmaking,
and acquired the qualification of a nationally-skilled craftsman and also have the qualification of a nailist as a hobby.
There seems to be no relation between Japanese-style dressing, nails, and knitting,
But I have gained different insights from those experiences, and I think that it leads to free knitting.
I will continue to enjoy knitting, and I hope for those who are watching would also make something incredible on their own someday.
[BBTV Partner]
https://www.bbtv.com/
-----------------------------------
#mocotarou
#モコタロウ
#かぎ針編み
#編み物
#Crochet
#マフラー編み方
explanation 在 mocotarou / crochet Youtube 的最佳解答
こんにちは、ご覧頂きありがとうございます。下のレシピも参考にしてください。
-----------------------------------------
[使用した毛糸]
DAISO:
フラッフィ
カラー:ライトグレー、チャコールグレー
各1玉
[使用したかぎ針]
10号(6㎜)
-------------------------------------
[チャプター]
00:00 毛糸の説明
00:52 編み始め
04:09 2段め
05:58 糸始末
07:29 完成しました。
[レシピ]
・2色引き揃えて
・作り目:くさり68目で始めてねじらないように引き抜き編みで繋げます。
・1段:長編み2目、くさり2目、2目飛ばして、長編み2目~の柄の繰り返し
・2段~22段:裏返し、裏返しで、前段の穴の中に長編み2目、くさり2目を繰り返し。
・お好きな段数を編んで下さい。私は2玉引き揃えで22段編めました。
[サイズ]
縦40cm、横24cm
---------------- 本 ---------------
『カンタン&かわいい&すぐできる! かぎ針で編む モコタロウの編み小物』
ワニブックスさんより発売中です。
全国の書店、Amazon、楽天等でお買い求め頂けます。
Amazon
https://amzn.to/37JxgoJ
Kindle版
https://amzn.to/3zOOnBK
写真を大きくしたりできるので見やすいと思います。
紹介動画
https://youtu.be/b04l1xdfb0A
よろしければ見てみて下さい。
下の楽天ルームにも載せています。
-----------------------------------
[私の趣味の部屋]
https://room.rakuten.co.jp/room_7f8d1f716c/items
この楽天ルームに使った糸や気に入った物を載せています。
--------------- S N S --------------
[Instagram]
https://www.instagram.com/mocotarou10
完成した作品の画像をUPしています。
[Twitter]
https://twitter.com/mocotarou10
動画UPをお知らせします。
------------- サブチャンネル ----------
[mocotaのおうち]
https://www.youtube.com/channel/UCKowbiPymzaJ4s-AuORQGyg/
Vlogとか購入品紹介等
---------- チャンネル登録 ---------
[登録用リンク]
https://www.youtube.com/channel/UChtBfT4OJEGEfnYimkuX2mQ?sub_confirmation=1
最新動画等が見やすくなります。
ぜひチャンネル登録宜しくお願いします。
---------- 作品販売 ---------
メルカリ:https://www.mercari.com/jp/u/985022433/
※基本的には毎週土曜日に出品していますが
出品しなかったり、出品する日が前後することもあります。
よろしくお願いいたします。
-------- オンラインクラス -----------
your schoolはクリエイターさんのストーリーやスキル/価値観を狭く深く伝え、ユーザーのみなさんにより深く学ぶ機会や選択肢を提案するオンラインクラスのマーケットプレイスです。
HP : https://yourschool.jp/
YouTube : https://www.youtube.com/c/yourschool-youtube/videos
-------- オリジナルロゴグッズ --------
https://suzuri.jp/mocotarou10
--------------------------------------
[使用している道具など] ※Amazon Associate
かぎ針:チューリップ ETIMOかぎ針セット プレミアムゴールド TEG-001
https://amzn.to/2YNUerp
購入品紹介動画:https://youtu.be/eoUUb08wQ50
---------------------------------------------
Thank you for watching my videoes and for all your warm comments.
I think that my knitting videos showcase many parts of my own style,
which can be difficult to understand, but I will try to make the explanation as easy as possible.
I hope many people will enjoy knitting in the same way through my videoes.
I've been to a simple knitting class, but I usually go with my own flow.
I love handmade crafts, so in the past, I've been involved in Japanese-style dressmaking,
and acquired the qualification of a nationally-skilled craftsman and also have the qualification of a nailist as a hobby.
There seems to be no relation between Japanese-style dressing, nails, and knitting,
But I have gained different insights from those experiences, and I think that it leads to free knitting.
I will continue to enjoy knitting, and I hope for those who are watching would also make something incredible on their own someday.
[BBTV Partner]
https://www.bbtv.com/
-----------------------------------
#mocotarou
#モコタロウ
#かぎ針編み
#編み物
#Crochet
#スヌード編み方
explanation 在 mocotarou / crochet Youtube 的最佳解答
こんにちは、ご覧頂きありがとうございます。
モコタロ本の作品で使用している毛糸は廃番になっている物もありますので
今販売されている糸で本のレシピを編んでみようと思います。
-----------------------------------------
[使用した毛糸]
DAISO:
メランジテイスト
カラー:
チャコールブラウン
3玉
オリーブグリーン
2玉
縦18cm、横34cm、マチ13.5cm
---------------- 本 ---------------
『カンタン&かわいい&すぐできる! かぎ針で編む モコタロウの編み小物』
ワニブックスさんより発売中です。
全国の書店、Amazon、楽天等でお買い求め頂けます。
Amazon
https://amzn.to/37JxgoJ
Kindle版
https://amzn.to/3zOOnBK
写真を大きくしたりできるので見やすいと思います。
紹介動画
https://youtu.be/b04l1xdfb0A
よろしければ見てみて下さい。
下の楽天ルームにも載せています。
-----------------------------------
[私の趣味の部屋]
https://room.rakuten.co.jp/room_7f8d1f716c/items
この楽天ルームに使った糸や気に入った物を載せています。
--------------- S N S --------------
[Instagram]
https://www.instagram.com/mocotarou10
完成した作品の画像をUPしています。
[Twitter]
https://twitter.com/mocotarou10
動画UPをお知らせします。
------------- サブチャンネル ----------
[mocotaのおうち]
https://www.youtube.com/channel/UCKowbiPymzaJ4s-AuORQGyg/
Vlogとか購入品紹介等
---------- チャンネル登録 ---------
[登録用リンク]
https://www.youtube.com/channel/UChtBfT4OJEGEfnYimkuX2mQ?sub_confirmation=1
最新動画等が見やすくなります。
ぜひチャンネル登録宜しくお願いします。
---------- 作品販売 ---------
メルカリ:https://www.mercari.com/jp/u/985022433/
※基本的には毎週土曜日に出品していますが
出品しなかったり、出品する日が前後することもあります。
よろしくお願いいたします。
-------- オンラインクラス -----------
your schoolはクリエイターさんのストーリーやスキル/価値観を狭く深く伝え、ユーザーのみなさんにより深く学ぶ機会や選択肢を提案するオンラインクラスのマーケットプレイスです。
HP : https://yourschool.jp/
YouTube : https://www.youtube.com/c/yourschool-youtube/videos
-------- オリジナルロゴグッズ --------
https://suzuri.jp/mocotarou10
--------------------------------------
[使用している道具など] ※Amazon Associate
かぎ針:チューリップ ETIMOかぎ針セット プレミアムゴールド TEG-001
https://amzn.to/2YNUerp
購入品紹介動画:https://youtu.be/eoUUb08wQ50
---------------------------------------------
Thank you for watching my videoes and for all your warm comments.
I think that my knitting videos showcase many parts of my own style,
which can be difficult to understand, but I will try to make the explanation as easy as possible.
I hope many people will enjoy knitting in the same way through my videoes.
I've been to a simple knitting class, but I usually go with my own flow.
I love handmade crafts, so in the past, I've been involved in Japanese-style dressmaking,
and acquired the qualification of a nationally-skilled craftsman and also have the qualification of a nailist as a hobby.
There seems to be no relation between Japanese-style dressing, nails, and knitting,
But I have gained different insights from those experiences, and I think that it leads to free knitting.
I will continue to enjoy knitting, and I hope for those who are watching would also make something incredible on their own someday.
[BBTV Partner]
https://www.bbtv.com/
-----------------------------------
#mocotarou
#モコタロウ
#かぎ針編み
#編み物
#Crochet
explanation 在 explanation - Yahoo奇摩字典搜尋結果 的相關結果
explanation · 查看更多. KK[͵ɛkspləˋneʃən]; DJ[͵ekspləˋneiʃən]. 美式. n. 說明,解釋[U][C][(+of/for)];辯解;辯明[U][C][(+of/for)][+(that)] ... ... <看更多>
explanation 在 explanation (【名詞】說明, 解釋)意思、用法及發音 - Engoo 的相關結果
"explanation" 例句. The teacher's explanation was very clear. 老師的解釋非常清楚。 They were unable to provide an explanation for the error. ... <看更多>
explanation 在 explanation中文(繁體)翻譯:劍橋詞典 的相關結果
Could you give me a quick explanation of how it works? 你可以向我簡要說明一下它的運作原理嗎? What was her explanation for why she was late ... ... <看更多>