📜 [專欄新文章] 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.
👏 歡迎轉載分享鼓掌
同時也有9部Youtube影片,追蹤數超過26萬的網紅เชื่อชัย,也在其Youtube影片中提到,เชื่อชัย SpokeDark : วันนี้พี่ชัยอยู่กับ 3 สาวจากทีมงานสโป๊คดาร์ค ที่จะมาแต่งหน้าให้ชมกันว่าใครจะมีฝีมือในการแต่งหน้ามากกว่ากัน ซึ่งทั้ง 3 คนต่างก็มีส...
「elegant drawing」的推薦目錄:
elegant drawing 在 Culture Trip Facebook 的最讚貼文
This hotel even has its own cinema room! And there are artworks by Virginia Woolf’s sister Vanessa Bell on the walls, cuddly armchairs in the drawing room and library, plus all the elegant boutique furnishings. No surprise this is one of the hotels we 💚
elegant drawing 在 Tracy L. Facebook 的最佳貼文
🪐 2021
Traveler’s -week.23
Flowering spot with a reading boy!
I love Drawing by Carol, elegant as always. They can fit with any other materials!
Reading boy is designed by pointdiary
#Tracy_2021journal
#travelersnotebook #travelersnotebooks #yohaku #yohaku_jp #journalinspirations #creativejournals #pehodesign #phavouriteco #phavourite #pointdiary #asteroidb610 #letteringinjournal #calligraphyletter #meowillustration #novebyvivient #travelersnotebookinserts #2021journal #手帳 #手帳生活 #小行星b610 #拼貼 #拼貼手帳 #旅人手帳 #拼貼練習 #拼貼日常 #喵大 #點點陳插畫事務所 #點點陳 #日常手帳
elegant drawing 在 เชื่อชัย Youtube 的最讚貼文
เชื่อชัย SpokeDark : วันนี้พี่ชัยอยู่กับ 3 สาวจากทีมงานสโป๊คดาร์ค ที่จะมาแต่งหน้าให้ชมกันว่าใครจะมีฝีมือในการแต่งหน้ามากกว่ากัน ซึ่งทั้ง 3 คนต่างก็มีสไตล์การแต่งหน้าเป็นของตัวเอง โดยเมื่อแต่งหน้าเสร็จแล้วพี่ชัยจะมาให้คำแนะนำรวมถึงเคล็ดลับต่าง ๆ ว่าแต่ละคนควรปรับในส่วนไหน เพื่อให้การแต่งหน้าออกมาสวยเป๊ะขึ้น
ไพรเมอร์ Laura Mercier Pure Canvas Primer Perfecting ราคา 1,750 บาท
คอนซีลเลอร์ Hourglass Vanish Airbrush Concealer ราคา 1,450 บาท
ไพรเมอร์ Benefit Cosmetics The Porefessional Face Primer ราคา 590 บาท
รองพื้น Estee Lauder Double Wear Stay In Place ราคา 2,000 บาท
รองพื้น Urban Decay Stay Naked Foundation ราคา 1,600 บาท
ครีมบลัช Fenty Beauty Cheeks Out Freestyle Cream Blush Rose Latte ราคา 850 บาท
รองพื้น L’Oreal Paris True Match Hya Foundation ราคา 499 บาท
แป้งฝุ่น Laura Mercier Translucent Loose Setting Powder ราคา 1,790 บาท
บลัชออน The Saem Saemmul Single Blusher ราคา 350 บาท
คอนซีลเลอร์ L’Oreal Paris Infallible More Than Concealer ราคา 329 บาท
ที่เขียนคิ้ว Kate Lasting Design Eyebrow W ราคา 425 บาท
ที่เขียนคิ้ว Browit Easy Drawing Brow Shadow ราคา 159 บาท
เจลใสปัดคิ้ว 4U2 Brow Coat ราคา 259 บาท
เฉดดิ้ง EGLIPS Slim Fit Shading 01 Ginger ราคา 165 บาท
ลิปสติก Make Up For Ever Rouge Artist Lipstick ราคา 770 บาท
อายแชโดว์ Sephora Collection Pro Warm Palette ราคา 2,250 บาท
อายแชโดว์ Etude House Play Color Eye Palette ราคา 1,300 บาท
อายแชโดว์ Jovina Desert Eye Palette ราคา 580 บาท
ที่เขียนคิ้ว Mille 6D Slim Brow Pencil Waterproof ราคา 295 บาท
ลิปสติก Maybelline Super Stay Matte Ink 270 ราคา 249 บาท
ลิปสติก Beauty Cottage Elegant Impressionist Semi-Matte Lipstick 18 ราคา 345 บาท
#แต่งหน้าง่ายๆ #everydaylook #แต่งหน้าไปทำงาน

elegant drawing 在 NutTy TLB Youtube 的最佳解答
- BASE/PRIMER
01:10 Bobbi Brown Vitamin Enriched Face Base
- FOUNDATION
01:50 L'Oreal Infallible 24H Fresh Wear Foundation สี 260 Golden Sun
02:17 Lancome Teint Idole Ultra Wear Foundation สี 050 Beige Ambre
- CONCEALER
03:21 NARS Radiant Creamy Concealer สี Medium1 Custard
03:49 L'Oreal Infallible Full Wear More Than Concealer สี 308 Vanilla
- POWDER
04:19 Chu Chu Kiss HD Loose Powder
05:05 Chanel Poudre Universelle Libre Natural Finish Loose Powder สี 30 Natural Translucent 2
05:45 Cute Press 1-2 Beautiful Airy Matte Foundation Powder สี 04 Medium Beige
- BLUSH BRONZER HIGHLIGHTER
06:23 Shiseido Minimalist Whipped Powder Blush สี 07 Setsuko
07:07 Supermom La Fleur Blush Palette
07:47 Browit Highlight and Contour Pro Palette
- EYEBROW
08:29 Cosluxe Slimbrow Pencil Triangular Tip สี Mocha, Espresso, Eveandboy
09:01 Cosluxe Brows Up Brow & Eye Bar
09:35 Browit Easy Drawing Brow Shadow สี Medium Brown
- EYELINER MASCARA
10:05 UZU by Flowfushi Eye Opening Liner สี Black
10:23 Chanel Stylo Yeux Waterproof Long-Lasting Eyeliner สี 951 Khaki Intense
10:51 Browit Professional Duo Mascara
11:12 Canmake Quick Lash Curler Mascara
- EYESHADOW
11:42 Canmake Lasting Multi Eyebase WP
12:06 Browit Eyemazing Shadow and Liner สี Drama Brown, Elegant Gold, Copper Crown, Bridal Pink Gold
12:48 Bobbi Brown Luxe Eye Shadow สี Heat Ray
13:16 Supermom Crush On You Eyeshadow Palette
13:51 Supermom Ma Cherie Collection
14:34 4U2 Look At Me Eyeshadow สี 03 Mad Brick I
- LIP
15:09 MAC Glow Play Lip Balm สี 454 Floral Coral
15:32 L'Oreal Brilliant Signature สี 302 Be Outstanding
15:53 4U2 I Heart You Moisture Cream Intense Heart Lipstick SPF25 PA+++ สี 93 Kiss Me Again, 94 Lost Without You
16:31 Supermom Lip Velvet Crayon สี RC12 Burnt Brick
17:17 Chapterone Beauty The Glamorous Soft Matte Lip Color สี On The Go
17:57 MAC Liptensity Lipstick สี Smoked Almond
18:38 Sasi Xoxo Liquid Lip สี 501 Brownie Nude
19:21 MAC Patent Paint Lip Lacquer สี 587 Laquered Up
19:57 Cute Press Feel this Kiss Watery Lip Stain สี 08 Hot Cocoa, 09 Milk Tea
- SETTING
20:50 MAC Fix+ Setting Spray กลิ่น Balance
- TOOLS
21:44 GINO McCRAY The Artist Eyelash Curler
22:21 Beauty Blender Shadeshifter Wave
22:51 Supermom Shizen Brush Set
23:56 Chiyoda Brush แปรง Blusher G99, แปรง Powder GS45
25:01 Chiyoda Clear Soap
25:50 Gentluca Oil & Sweat Blotter
----------
Disclaimer : This video Non-sponsored
Instagram : https://www.instagram.com/nuttytlb
Fanpage : http://facebook.com/nuttyladyboy
Blog : http://nuttyladyboy.blogspot.com/
Contact : [email protected]

elegant drawing 在 KARMAN Youtube 的最佳貼文
I invite you to embark on this relaxing journey where I transform myself into a more elegant version of me. The other night I did this makeup for a family dinner, I thought I am extra feminine that evening. Or is it just me? You tell me.
// MORE INFO //
PRODUCTS//
THINKBABY SPF 50
MAYBELLINE Instant Age Rewind Eraser (150 Neutralizer)
COTY Air Spun Loose Powder (Translucent)
ETUDE HOUSE Drawing Eyebrow (04 Gray)
H&M Pure Radiance Powder Blusher (Taupe Brown)
MILANI Baked Blush (01 Dolce Pink)
MILANI Strobelight Instant Glow Powder (01 Afterglow)
SHISEIDO Lash Curler
MAKEUP REVOLUTION Reloaded (Iconic Fever)
MILANI 17HR Matte Liquid Eyeliner (Black)
KATE Lash Maximizer (White)
HEROINE MAKE Advanced Film Long & Curl Mascara
REVLON Matte Balm (225 Sultry)
MILD BY NATURE Rose Petal Mist
BRUSHES//
REAL TECHNIQUES Setting Brush
REAL TECHNIQUES Deluxe Crease Brush
REAL TECHNIQUES Eyeshadow Brush
REAL TECHNIQUES Fan Brush
ZOEVA 230 Luxe Pencil
ZOEVA 227 Luxe Soft Definer
ZOEVA 231 Luxe Petit Crease
ESSENCE Eyeshadow Brush
REAL TECHNIQUES Accent Brush
MUSIC//
@Asthenic
TAKE IT SLOW [ Lofi - Jazz - Beats Mix ]
https://www.youtube.com/watch?v=7VJHiB2fl_s&t=67s
