📜 [專欄新文章] 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.
👏 歡迎轉載分享鼓掌
同時也有153部Youtube影片,追蹤數超過12萬的網紅ClumsyCynthia 黃可樂,也在其Youtube影片中提到,默默掙扎了很久之後還是拍出來了! 跟大家分享一下我平時最常用的精品包包們 :) 我大概是一兩年前開始注意精品 慢慢比較有能力可以負擔之後就開始掉入買包的深淵(嗯?) (大家也要斟酌經濟狀況 不要為了跟風而買唷!) 另外今天的場地是Creamwood, 地方超大超美QQ (直接美哭) https:...
「drawing medium」的推薦目錄:
- 關於drawing medium 在 Taipei Ethereum Meetup Facebook 的最讚貼文
- 關於drawing medium 在 CHOU YI Facebook 的最佳貼文
- 關於drawing medium 在 A Happy Mum Facebook 的最佳解答
- 關於drawing medium 在 ClumsyCynthia 黃可樂 Youtube 的最佳貼文
- 關於drawing medium 在 icepadie Youtube 的最讚貼文
- 關於drawing medium 在 Piyapeauty Makeup Youtube 的最讚貼文
- 關於drawing medium 在 Title:Hand Drawing Medium: Graphite This is a ... - Pinterest 的評價
- 關於drawing medium 在 Lecture – Drawing: Medium, Discourse, Object - YouTube 的評價
- 關於drawing medium 在 Botanical Drawing (Medium) - Facebook 的評價
drawing medium 在 CHOU YI Facebook 的最佳貼文
昨天上架,已經被秒殺掉一半了omg,好感謝,
每件都只有一件獨一無二,在這過程中我也玩得很開心,我一直
希望能將藝術融入生活之中,穿上他們自己也變成了行動藝術品,
還有少量手繪服飾進請把握💚
🎨 訂購連結:https://reurl.cc/rgeZNb
朋 丁 pon ding
-
/ 朋 丁 pon ding x 周依 CHOUYI 新作上架 /
⭐️➰《DRAWING WITH ME 跟我一起畫畫》SS21⭐️➰
💜ORIGINAL DRAWING CLOTHES 全手繪系列每款皆獨一無二!💚
愛因斯坦曾說「想像力比知識更重要」,而在周依的世界裡,倘若 A 代表人生的成功,那麼公式 A=X+Y+Z,X代表努力發想,Y代表盡情玩樂,Z則代表少說廢話。貫徹「LIFE IS CREATION 」的他持續將創作融入隨手可得的地方,這次我們日常著用的衣物成為周依自在揮灑的媒材,讓每件衣服成為獨一無二的創作,小小顛覆一下 KEITH HARING 過去將藝術藏在地鐵站,現在我們每個人都是可移動的藝術品。邀請大家穿上它,讓周依的玩樂美學陪您快樂度過每一天。
Albert Einstein famously said: “ Imagination is more important than knowledge. '' In Chou Yi’s equation, A = X + Y+ Z, A equals Success, X equals thinking hard, Y equals playing hard, and Z equals cutting the crap! In Life is Creation series, Chou Yi continues to blend her creation into every corner in daily life. Our daily wardrobe becomes her medium to paint freely, and it evolves into unique pieces of art. Extending the idea of Keith Haring to hide artworks in subway stations, Chou Yi turns everyone into mobile artworks! Her playing-around aesthetics invite you to wear on, and to accompany to enjoy every single day.
-
Artist|CHOU YI @chouyi
Photo|鄭弘敬 @teikoukei
Model|CHOU YI、那詡訢、HIPPO
Venue|朋丁 @pondingspace
Make up|張愛波 @applekid10wwww
drawing medium 在 A Happy Mum Facebook 的最佳解答
Woohoo! We are featured in The Sunday Times today!
The topic is on how to have cosy, creative celebrations amidst the pandemic and how staying home presents an opportunity for families to bond and get closer.
If you follow my stories, you will know that Ariel designed an "Animal Experience Studio" for the family to get together and enjoy. She came up with a series of games, including a classification game using our animal figurines, a tossing game where you try to throw the animals into containers of different sizes, an animal 'hunt' where she hid them around the house, a drawing game where she categorised the animals based on easy/medium/hard level, and a Bingo game where she surprised me by painstakingly drawing every card by hand for each of us.
We played this during the Father's Day weekend recently and it was so much fun for the whole family. She even prepared small prizes from her own stationery and a lovely "Thank You" speech to thank us for participating. Awww. So I think she is very thrilled to see it being mentioned in the papers today and to see a huge photo of all of us playing her game. Yup, even her self-designed poster is featured too. You totally deserve it, my dear!
She said she was inspired by my DIY Halloween party last year and the name was derived from our visit to Changi Experience Studio earlier this year. And you know what? The success of this initiative has propelled her to want to create even more party games and celebrations for us in the future. Yippee!
Big thanks also goes to the hubby and the siblings for joining in wholeheartedly and to the big sister for ensuring that the games flowed smoothly too. It is indeed true that celebrating indoors does not have to be mundane but instead, it can be intimate, creative and fun. I am just so happy and relieved that the kids share my sentiments too.
Thanks to Kamal from The Straits Times for interviewing us and even including my blog link in the article too! What a great way to end off the school holidays, which I wish could last longer so we could have more fun as a family.
Have a happy Sunday, everybody! ❤
#ahappymum #familytime #Creativity521 #stayhomecanbefun
drawing medium 在 ClumsyCynthia 黃可樂 Youtube 的最佳貼文
默默掙扎了很久之後還是拍出來了!
跟大家分享一下我平時最常用的精品包包們 :)
我大概是一兩年前開始注意精品
慢慢比較有能力可以負擔之後就開始掉入買包的深淵(嗯?)
(大家也要斟酌經濟狀況 不要為了跟風而買唷!)
另外今天的場地是Creamwood, 地方超大超美QQ (直接美哭)
https://www.instagram.com/creamwood.studio/
閨蜜拍照/商業拍攝都很適合唷
Bag #1: LOEWE Mini Puzzle Bag in Warm Desert
» 代購購入(我找的是 https://www.instagram.com/iffystore/)
» 這個拼色是季節性的,現在已經斷貨了應該,但他們家陸續都有出不同的拼色 大家可以注意一下 :)
Bag #2: Louis Vuitton Nano Noe (燒賣包)
» 香港專門店購入
» 這個碰到真的是運氣xd 有喜歡又剛好碰到的話可以直接買了(勸敗
Bag #3 Prada Re-edition 2005 Nylon Shoulder bag
» 代購購入(我找的是 https://www.instagram.com/iffystore/)
» 之前我記得有出很多種不同的顏色,但官網現在只剩下黑色~另外他也有出皮的版本也蠻好看的 大家可以都去背背看 :p
Bag #4 Celine Medium Folco Bag in Triomphe Canvas & Calfskin
» 代購購入(我找的是 https://www.instagram.com/iffystore/)
» 個人覺得是個蠻好的入門精品包,容量夠 又好搭 (而且CELINE的老花紋之後好像會越來越難買QQ)
Bag #5 Celine Nano Belt Bag in grained calfskin in light taupe
» 代購購入(我找的是 https://www.instagram.com/iffystore/)
» 這個包比較girly一點 我通常是有需要比較正式一點/見客戶的場合會用
Bag #6 Chloé Drew Bag (not sure)
» gifted (很久之間的一個合作)
Bag #7 Mini Flap Bag with top handle
» 香港專門店購入
0:00 Intro
1:05 LOEWE Puzzle Bag
3:20 LV Nano Noe
5:41 Prada Re-edition Nylon Bag
7:42 Celine Falco Bag
10:26 Celine Belt Bag
13:18 Chloe Drew Bag (?)
15:25 CHANEL Mini Flap Bag w/ top handle
18:25 Summary
▼ You can also find me here!
▴▴▴▴▴▴▴▴▴▴▴▴▴▴▴▴▴▴▴▴▴▴▴
» Instagram: https://bit.ly/2QRx52C
» Drawing Instagram: https://bit.ly/2xrpUY2
» Facebook: https://bit.ly/3bv7tQQ
» Second channel: https://bit.ly/2QPFNyj
» My Podcast: "Oh fudge!" https://linktr.ee/clumsycynthia
✂ - - - - - - - - - - - - - - - - - - - - - - - - - -
▼ 你可能會想知道... | You Might Be Curious…
» 咖啡機:Delonghi EC685.BK (自SOGO購入)
» 果汁機:Vitantonio (自HKTVMall購入)
» 睡衣:Uniqlo or Juuneedu http://juuneedu.com/ / 韓國代購 gn_korea or puc_korea
» 婚姻平權banner:from 禁獵女巫 on Pinkoi - https://bit.ly/353Ns3W
▼ What I use 拍攝相關
» 相機: Canon M50 or GoPro Hero 8
» 剪輯軟體: Final Cut Pro X
» 付費音樂網站: Artlist - http://bit.ly/2ky4ked (this is an affiliated link, 大家可以多獲得2個月的訂閱!)
» Ending Music: Eric Reprid, Basement - https://thmatc.co/?l=15C8AAFF
» LOGO設計:writehanded2.0 - https://bit.ly/2wLIObQ
» Music used:
Music by Grace Chiang - staying in on Sunday (it is well) - https://thmatc.co/?l=C8FA4EC7
song--dance by kyle-cox (Artlist)
▼ Disclaimer:
▴▴▴▴▴▴▴▴▴▴▴▴▴▴▴▴▴▴▴▴▴▴▴
**This is not a sponsored video
✂ - - - - - - - - - - - - - - - - - - - - - - - - - -
▼ Cynthia 私心推薦影片 | Recommended Videos
» 美國V.S.台灣工作經驗談:https://bit.ly/2HsCuWT
» 遠距日常:給男友的一週年驚喜!https://bit.ly/2JJB3IQ
» 畢業季!名校光環下的甘苦談 https://bit.ly/2LUh7zx
» 25件我在25歲學到的事 http://bit.ly/2WHCiut
» 香港崩潰一週VLOG http://bit.ly/2Q2VVe0
» 我的八坪香港公寓開箱 http://bit.ly/30g9kUM
» 一個人去香港迪士尼 http://bit.ly/32ZRRjx
» 加入香港芭蕾舞團?! http://bit.ly/2QwAW5J
▼ key words 關鍵字
▴▴▴▴▴▴▴▴▴▴▴▴▴▴▴▴▴▴▴▴▴▴▴
黃可樂 生活vlog 留學 美國留學 美國工作簽證
美國找工作 美國求職 H1B 找工作 實習 面試 美國簽證
Cynthia 台灣 美國留學生 遠距離 日本 大阪 台灣 情侶
柏克萊大學 加州大學 柏克萊分校 UC Berkeley 經濟系
畢業季 畢業生 校園 校園傳說 留學心得 class of 2018
vlog 旅遊 旅遊日記 旅遊筆記 Travel vlogs diary spotify
香港工作 香港生活 Hong Kong HK Weekly VLOG
drawing medium 在 icepadie Youtube 的最讚貼文
Product list
-SHU UEMURA (764) medium light beige
-CHARLOTTE TILLBURY Hollywood Flawless Filter (Medium)
-NANG-LA-WENG No.1-No.5 Bright Powder Supreme
-LANCOME Smooth Liquid Cushion Compact (150-IVOIRE-O)
-LAURA MERCIER Blush Color Infusion (Bellini) /(Passion Fruit)
-FENTY BEAUTY Diamond Bomb (Royal Icing)
-CHARLOTTE TILLBURY Filmstar Bronze &Glow Face Sculpt & Highlight (Medium-dark)
-4U2 Shimmer Blush (S75) - Kings & Queens
-COLORPOP Whatever Pressed Powder Palette
-CANMAKE Color Change Eyebrow (01)
-MAYBELLINE the falsies push up drama waterproof
-HAPPY SUNDAY Lipstick (Hot Cocoa)
-CANDY LAB Creampop The Velvet Lip Color Silky Smooth & Long Lasting (09 Anti-Social)
-RANxPOM VINIJ Drawing Slim Eyebrow (No.2)
-CHARLOTTE TILLBURY Eye Color Magic Duo Color (Copper Charge Matte&Metallic)
-CANMAKE Melty Luminous Rouge (T02)
Sponsored by แป้งนางละเวง
https://web.facebook.com/NanglawengThailand
♡
IG / FB : icepadie
www.icepadie.com
helloicepadie@gmail.com
drawing medium 在 Piyapeauty Makeup Youtube 的最讚貼文
ig : @piyapeauty
อย่าลืมกด Subscribe กันน้า
#Valentinemakeup
#Valentinelook
♥ Product ♥
ISISPHARMA - Sennsylia Cream 960฿
JULA’S HERB - DD Cream Water Melon SPF50 PA+++ 39฿
ETUDE - Double Lasting Serum Foundation N04 790฿
RAN - Loose Face Powder Ivory 390฿
PERIPERA - Pure Blushed Sunshine Cheek 01 320฿
ETUDE - Face Color Shading Medium Tight 210฿
BROW IT - Easy Drawing Brow Shadow 109฿
VER88 - Fast Dry Water Proof Liquid Eyeliner 149฿
NONGCHAT - Natural Signature 01 79฿
DOLLYWINK - Eyelash No21 545฿
COSLUXE - Lash Adhesive White 149฿
SEPHORA - Crayon Contour 12H 260฿
EXCEL - Long & Colored Lash Mascara LC03 750฿
INNNISFREE - My Highlighter1 249฿
ETUDE - Piglet Jelly Mousse Blusher RD301 425฿
NYX - Lingerie Push Up LIPLIPLS06 259฿
NYX - Lingerie Push Up LIPLIPLS19 259฿
4U2 - Love Me Harder2 34 199฿
NYX - Lingerie Gloss Clear 325฿
♥ F O L L O W M E ♥
✧ FB : https://www.facebook.com/peautydaily/
✧ IG : https://www.instagram.com/piyapeauty/
✧ TWITTER : https://twitter.com/piyapeauty
✧ YOUTUBE : https://www.youtube.com/c/PiyanuchChittinun
→ Work Contact ✧ E-mail : Piyapch@gmail.com
drawing medium 在 Lecture – Drawing: Medium, Discourse, Object - YouTube 的推薦與評價
Presented in conjunction with the exhibition Drawing : The Invention of a Modern Medium (January 21–May 7, 2017), this lecture considers the ... ... <看更多>
drawing medium 在 Botanical Drawing (Medium) - Facebook 的推薦與評價
Medium size botanical Cannabis/Hemp drawing. - Nameless - Cannabis Sativa - Common Hemp - Cannabineae Hennep - Histoire Naturelle. ... <看更多>
drawing medium 在 Title:Hand Drawing Medium: Graphite This is a ... - Pinterest 的推薦與評價
I used graphite as my medium. I used the graphite to add value. I also included highlights and dark values to add contrast. Title:Hand Drawing Medium: ... ... <看更多>