📜 [專欄新文章] 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.
👏 歡迎轉載分享鼓掌
同時也有76部Youtube影片,追蹤數超過5萬的網紅祝嫥嫥JONY,也在其Youtube影片中提到,145cm 34kg #小隻女穿搭#上學一週穿搭#daily Lookbook#summer lookbook 🏷️BRA TOP 0:00 MORE REAL 單肩運動款BRA TOP (楊丞琳限定款) 奶白 https://www.pazzo.com.tw/zh-cn/market/n/188...
「straightforward」的推薦目錄:
- 關於straightforward 在 Taipei Ethereum Meetup Facebook 的最佳貼文
- 關於straightforward 在 Facebook 的最讚貼文
- 關於straightforward 在 Victor Chau Yoga Facebook 的最佳解答
- 關於straightforward 在 祝嫥嫥JONY Youtube 的最讚貼文
- 關於straightforward 在 Mateusz Urbanowicz Youtube 的最佳解答
- 關於straightforward 在 capcomasia Youtube 的最佳貼文
- 關於straightforward 在 How to Be More Straightforward - YouTube 的評價
- 關於straightforward 在 Straightforward - Home | Facebook 的評價
- 關於straightforward 在 Straightforward Interior Design Twenty-First Century Style 的評價
straightforward 在 Facebook 的最讚貼文
Di tarik balik!
.
Disebabkan lambat ke call room dan selepas pertandingan dan lepas pecahkan rekod dunia barulah di protes oleh peserta lain.itulah situasi yg berlaku kpd abang ‘badang’ kita ni.
.
So kesannya kita kehilangan pingat emas dan sya pasti new world record pun tidak sah lah.ape perasaan @ziyadzolkefli and the whole team kan?
.
So, apakah lesson learn yg kita dpt? Dlm sukan komitment n disiplin sgtlah penting. Sya sebagai bekas atlet (pemain bola sepak) dan juga pernah mewakili negara. Disiplin n komitment amatlah penting.kita semua belum pasti apakah punca yg membuatkan @ziyadzolkefli lewat ke call room.tetapi undang2 pertandingan ni ‘buta’ n very straightforward. No excuse!
.
Persolannya, dimanakah pegawai atau team yg bersama @ziyadzolkefli ketika itu? Apa2 pun kita tggu jawapan rasmi dari kontijen Malaysia utk paralympic ni.
.
Tidak perlulah kita persalahkan pihak penganjur diatas penarikan balik pingat emas ni kerana jelas dan nyata yg kita melanggar undang2 pertandingan.
.
Bro @ziyadzolkefli ,tahniah sya ucapkan dan seluruh rakyat Malaysia bangga dgn awk, satu dunia tahu awk adalah pemegang rekod baru dunia. Jangan rasa down n keep it up.more to come bro! Pasti ade hikmah disebalik semua ni.
.
#paralympics
#ziyadzolkefli
#newworldrecord
straightforward 在 Victor Chau Yoga Facebook 的最佳解答
SIMPLE DOES IT.
If you think the most complicated problem requires the most complex solutions, think again. Sometimes the biggest challenges in life or yoga poses requires the simplest solution, alignment or tool. A #yogawheel here helps me achieve this #halflotus #hollowback #inversion. Without the wheel, this pose will be nearly impossible.
We often look for answers in all the wrong places, making things unnecessarily complicated. If you think you’re poor, you’d think making money will make you happy. Or if you’re a yoga teacher, you might think teaching the most challenging poses or having the most beautiful Instagram will make you a great yoga teacher.
Try to think of the most straightforward and simple things that you can do next time you face a challenge. If you feel stuck in a rut, take a deep breath, close your eyes, meditate a little. The answer you’re looking for can be super simple or next to you.
Got a similar experience you want to share? Let me know in comments below :)
straightforward 在 祝嫥嫥JONY Youtube 的最讚貼文
145cm 34kg
#小隻女穿搭#上學一週穿搭#daily Lookbook#summer lookbook
🏷️BRA TOP 0:00
MORE REAL 單肩運動款BRA TOP (楊丞琳限定款) 奶白
https://www.pazzo.com.tw/zh-cn/market/n/18800?c=42088
🏷️Look 1 0:07
羅紋緊身上衣(已下架,蝦皮上很多類似款)
排釦牛仔短褲(已下架,蝦皮上很多類似款)
韓國時尚復古斑馬紋漁夫帽
https://shp.ee/eq2ngjd
Coach 小雛菊包包(朋友送的)
Moz 瑞典穆勒拖鞋式餅乾鞋 鐵灰色 23號
https://www.moz.com.tw/products/moz-s...
🏷️Look 2 0:34
花邊短版針織上衣 綠
https://shp.ee/xdxudxh
喇吧牛仔黑褲
https://shp.ee/ijizkhh
金屬鯊魚夾(啞光銀)
https://shp.ee/b3qmbud
Coach 小雛菊包包(朋友送的)
Moz 瑞典穆勒拖鞋式餅乾鞋 鐵灰色 23號
https://www.moz.com.tw/products/moz-s...
🏷️Look 3 1:31
緊身辣妹露肚上衣 橘
https://shp.ee/9s8p69h
歐美厚磅抽繩縮口棉褲 灰
ttps://shp.ee/aj5hqdz
MORE REAL 時髦墨鏡 琥珀
https://www.pazzo.com.tw/market/n/183...
Adidas小包包(已下架)
Moz 瑞典穆勒拖鞋式餅乾鞋 鐵灰色 23號
https://www.moz.com.tw/products/moz-s...
🏷️Look 4 2:54
粉紅渲染口罩(9/20收單)
https://gbf.tw/t84bx
Bershka針織長袖上衣 灰(已下架,季節限定)
https://www.bershka.com/tw/women-c1010193132.html
落地牛仔長褲(已斷貨)
Coach 小雛菊包包(朋友送的)
Moz 瑞典穆勒拖鞋式餅乾鞋 鐵灰色 23號
https://www.moz.com.tw/products/moz-s...
🏷️Look 5 4:00
歐美綁帶圖騰肚兜式背心
https://shp.ee/qv2a72h
緊身牛仔破洞長褲(已下架)
金屬鯊魚夾(啞光銀)
https://shp.ee/b3qmbud
MORE REAL 時髦墨鏡 琥珀
https://www.pazzo.com.tw/market/n/183...
[樂一通] 率真崔弟鎖骨鍊 / LOONEY TUNES Straightforward Tweety Bird Necklace
https://www.bonnyread.com.tw/products/looneytunesstraightforwardtweetybirdnecklace
Moz 瑞典穆勒拖鞋式餅乾鞋 鐵灰色 23號
https://www.moz.com.tw/products/moz-s...
🏷️Look 6 5:08
Bershka 削肩肚兜背心 黑(已下架,季節限定)
https://www.bershka.com/tw/women-c1010193132.html
超大破洞牛仔褲 (五年前路邊隨便買的😂找不到)
[樂一通] 率真崔弟鎖骨鍊 / LOONEY TUNES Straightforward Tweety Bird Necklace
https://www.bonnyread.com.tw/products/looneytunesstraightforwardtweetybirdnecklace
Adidas小包包(已下架)
韓國時尚復古斑馬紋漁夫帽
https://shp.ee/eq2ngjd
Moz 瑞典穆勒拖鞋式餅乾鞋 鐵灰色 23號
https://www.moz.com.tw/products/moz-s...
🏷️Look 7 6:05
一字領針織上衣
https://www.belongto.co/
MORE REAL 顯瘦開岔長腿褲(美圖瘦瘦褲)黑
https://www.pazzo.com.tw/market/n/175...
[樂一通] 率真崔弟鎖骨鍊 / LOONEY TUNES Straightforward Tweety Bird Necklace
https://www.bonnyread.com.tw/products/looneytunesstraightforwardtweetybirdnecklace
Coach 小雛菊包包(朋友送的)
Klasse14 手錶
https://tw.klasse14.com
Moz 瑞典穆勒拖鞋式餅乾鞋 鐵灰色 23號
https://www.moz.com.tw/products/moz-s...
///////////////////////
⚠️重大事情宣布!!
每週禮拜五晚上六點上新片!
~記得開啟小鈴鐺!🔔
📷/ iPhone 11
🎬/ Final Cut Pro X
🎵/Music by 2KNato - Won't Accept It - https://thmatc.co/?l=0035A9A7
Music by Carter Vail - On/Off - https://thmatc.co/?l=1ED55E82
Music by FIREROSE - Fragile Handling - https://thmatc.co/?l=0406EAF6
📪/合作邀約:jony92523@gmail.com
🏷️My Instagram : jony92523
https://www.instagram.com/jony92523/
MORE REAL 單肩運動款BRA TOP (楊丞琳限定款) 奶白
https://www.pazzo.com.tw/zh-cn/market/n/18800?c=42088
🏷️Look 1 0:07
羅紋緊身上衣(已下架,蝦皮上很多類似款)
排釦牛仔短褲(已下架,蝦皮上很多類似款)
韓國時尚復古斑馬紋漁夫帽
https://shp.ee/eq2ngjd
Coach 小雛菊包包(朋友送的)
https://www.coach.com
Moz 瑞典穆勒拖鞋式餅乾鞋 鐵灰色 23號
https://www.moz.com.tw/products/moz-s...
🏷️Look 2 0:34
性感少女QQ花邊短版針織上衣 綠
https://shp.ee/xdxudxh
喇吧牛仔黑褲
https://shp.ee/ijizkhh
金屬鯊魚夾(啞光銀)
https://shp.ee/b3qmbud
Coach 小雛菊包包(朋友送的)
https://www.coach.com
Moz 瑞典穆勒拖鞋式餅乾鞋 鐵灰色 23號
https://www.moz.com.tw/products/moz-s...
🏷️Look 3 1:31
緊身辣妹露肚上衣 橘
https://shp.ee/9s8p69h
歐美厚磅抽繩縮口棉褲 灰
ttps://shp.ee/aj5hqdz
MORE REAL 時髦墨鏡 琥珀
https://www.pazzo.com.tw/market/n/183...
Adidas小包包(已下架)
Moz 瑞典穆勒拖鞋式餅乾鞋 鐵灰色 23號
https://www.moz.com.tw/products/moz-s...
🏷️Look 4 2:54
粉紅渲染口罩(9/20收單)
https://gbf.tw/t84bx
Bershka針織長袖上衣 灰(已下架,季節限定)
https://www.bershka.com/tw/women-c1010193132.html
落地牛仔長褲(已斷貨)
Coach 小雛菊包包(朋友送的)
https://www.coach.com
Moz 瑞典穆勒拖鞋式餅乾鞋 鐵灰色 23號
https://www.moz.com.tw/products/moz-s...
🏷️Look 5 4:00
歐美綁帶圖騰肚兜式背心
https://shp.ee/qv2a72h
緊身牛仔破洞長褲(已下架)
金屬鯊魚夾(啞光銀)
https://shp.ee/b3qmbud
MORE REAL 時髦墨鏡 琥珀
https://www.pazzo.com.tw/market/n/183...
[樂一通] 率真崔弟鎖骨鍊 / LOONEY TUNES Straightforward Tweety Bird Necklace
https://www.bonnyread.com.tw/products/looneytunesstraightforwardtweetybirdnecklace
Moz 瑞典穆勒拖鞋式餅乾鞋 鐵灰色 23號
https://www.moz.com.tw/products/moz-s...
🏷️Look 6 5:08
Bershka 削肩肚兜背心 黑(已下架,季節限定)
https://www.bershka.com/tw/women-c1010193132.html
超大破洞牛仔褲 (五年前路邊隨便買的😂找不到)
[樂一通] 率真崔弟鎖骨鍊 / LOONEY TUNES Straightforward Tweety Bird Necklace
https://www.bonnyread.com.tw/products/looneytunesstraightforwardtweetybirdnecklace
Adidas小包包(已下架)
韓國時尚復古斑馬紋漁夫帽
https://shp.ee/eq2ngjd
Moz 瑞典穆勒拖鞋式餅乾鞋 鐵灰色 23號
https://www.moz.com.tw/products/moz-s...
🏷️Look 7 6:05
一字領針織上衣
https://www.belongto.co/
MORE REAL 顯瘦開岔長腿褲(美圖瘦瘦褲)黑
https://www.pazzo.com.tw/market/n/175...
[樂一通] 率真崔弟鎖骨鍊 / LOONEY TUNES Straightforward Tweety Bird Necklace
https://www.bonnyread.com.tw/products/looneytunesstraightforwardtweetybirdnecklace
Coach 小雛菊包包(朋友送的)
https://www.coach.com
Klasse14 手錶
https://tw.klasse14.com
Moz 瑞典穆勒拖鞋式餅乾鞋 鐵灰色 23號
https://www.moz.com.tw/products/moz-s...
///////////////////////
📷/ iPhone 11
🎬/ Final Cut Pro X
🎵/Music by 2KNato - Won't Accept It - https://thmatc.co/?l=0035A9A7
Music by Carter Vail - On/Off - https://thmatc.co/?l=1ED55E82
Music by FIREROSE - Fragile Handling - https://thmatc.co/?l=0406EAF6
📪/合作邀約:jony92523@gmail.com
🏷️My Instagram : jony92523
https://www.instagram.com/jony92523/
straightforward 在 Mateusz Urbanowicz Youtube 的最佳解答
A Renault 4 for you! The third collaboration piece with @呉竹Kuretake painted using their Kuretake Transparent Watercolor Palette 12 Colors Set. I wanted to do something more straightforward for this one because it's also about the "Student-only Watercolor Art Competition," which Kuretake is holding during World Watercolors Month!
Be sure to check it out:
Kuretake Watercolor Art Competition page: https://www.special.kuretake.co.jp/wwm-competition
Tools:
- Kuretake Transparent Watercolor Palette 12 Colors Set
- Kuretake ZiG Mangaka pen 0.5mm
- Fabriano Venice Sketchbook
This is also my entry to the #worldwatercolormonth2021 ! I will not be doing all the prompts, but let' say that this piece is for the "faithful" prompt. This car certainly looks like it's faithful, alright.
When we were still living outside of Tokyo, near Enoshima, on our way to the supermarket, we would always walk by a shop that was fixing and restoring old (mostly European) cars! I took a lot of photos of very interesting vehicles there! When I want to paint something a bit different from my usual landscapes, I often go for the cars folder. ;)
Thanks to Kuretake for sending me these awesome tools to play with 👍
WWM official website: https://doodlewash.com/world-watercolor-month-july/
Kuretake + World Watercolor Month special page: https://www.kuretakezig.us/world-watercolor-month
#kuretakewwm2021
#kuretakewatercolors
#PR
Feel free to check out my other stuff:
Gumroad: https://gumroad.com/mateusz_urbanowicz
Patreon: https://www.patreon.com/mateuszurbanowicz
Website: http://mateuszurbanowicz.com
Blog: http://mattjabbar.tumblr.com
Twitter: https://twitter.com/gommatt
Instagram: https://www.instagram.com/mateusz_urbanowicz
straightforward 在 capcomasia Youtube 的最佳貼文
Ena
A Wyverian girl who knew your grandfather, Red.
Hoping to work together to uncover the truth behind recent environmental abnormalities, she entrusts you with a Rathalos egg supposedly containing a legendary monster fated to destroy the world. You embark on your journey together.
She is honest about her feelings.
https://www.monsterhunter.com/stories2/en-asia/character/character02.html
Kyle
A young Hunter in pursuit of the legendary Rathalos. He distrusts the way Riders live alongside monsters, and he is determined to capture Ratha. Since you are protecting a monster with catastrophic power, he sees you as an enemy. He is straightforward and has a strong sense of justice. His Palico is Tsukino and his weapon of choice is a bow.
https://www.monsterhunter.com/stories2/en-asia/character/character11.html
straightforward 在 Straightforward - Home | Facebook 的推薦與評價
Be sure to read through Straightforward's Terms and Conditions. 4. Once read and agreed upon, finally click “Place Order.” Q: Can I find your store in a mall ... ... <看更多>
straightforward 在 Straightforward Interior Design Twenty-First Century Style 的推薦與評價
Apr 25, 2018 - Read blog post about Straightforward Interior Design Twenty-First Century Style & check out the best design ideas! Click for more. ... <看更多>
straightforward 在 How to Be More Straightforward - YouTube 的推薦與評價
We prefer people who are 'straightforward': who are direct and unambiguous about their desires and ... ... <看更多>