📜 [專欄新文章] 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.
👏 歡迎轉載分享鼓掌
同時也有35部Youtube影片,追蹤數超過76萬的網紅えっちゃんねる/悦子,也在其Youtube影片中提到,こんにちは!えっちゃんです♪ 今回はクジ引きスライムをやってみたんだけど、思っていたものとは違うとんでもスライムが出来上がったw #slime #スライム #音フェチ ▽えっちゃんのSNS Twitter:https://twitter.com/ecchan_bom2 Instagram:ht...
「random drawing」的推薦目錄:
- 關於random drawing 在 Taipei Ethereum Meetup Facebook 的精選貼文
- 關於random drawing 在 InkSundae Facebook 的最佳解答
- 關於random drawing 在 Valerie Fong 方詩揚 Facebook 的最讚貼文
- 關於random drawing 在 えっちゃんねる/悦子 Youtube 的最佳貼文
- 關於random drawing 在 Mateusz Urbanowicz Youtube 的最佳解答
- 關於random drawing 在 Brenda Tan Youtube 的最佳解答
- 關於random drawing 在 60 random sketch ideas | drawings, art drawings ... - Pinterest 的評價
- 關於random drawing 在 Random Drawing Generator Challenge - YouTube 的評價
- 關於random drawing 在 Tattoo Culture Bridgend - Random drawing I just finished ... 的評價
- 關於random drawing 在 Randomly Generate Winners For Your Facebook Contest 的評價
- 關於random drawing 在 Drawing random paths in TikZ - LaTeX Stack Exchange 的評價
- 關於random drawing 在 canvas-sketch-util/random.md at master - GitHub 的評價
random drawing 在 InkSundae Facebook 的最佳解答
兩款托特包已經上架了
出外採買可以帶著,錢包、電話、酒精、口罩
雖然只是10分鐘的路程,但也要讓自己漂亮的出門 ❤️
官網 inksundae.com [宅家優惠活動]
滿NT500:
🌟台灣免運費
🌟贈送 1 個《灰灰幼稚園》胸章(隨機出貨,不累贈)
在家安心買😄
*優惠至 6/28
*疫情期間減少外出,每星期二、五出貨,敬請見諒
*寄送可用郵寄及全家取貨
Two tote bags are available at online shop now.
You may bring it along when you shop for groceries, with your purse, phone, alcohol and mask.
Maybe it’s a 10mins walk only. It’s great to make yourself look good. ❤️
inksundae.com [Stay Home Special]
Special Offer for purchase more than NT500:
🌟Free shipping in Taiwan
🌟 Get a free "Grey Kindergarten" badge. (Random, not accumulative)
Stay Home. Stay Safe! 😄
*Offer ends on 28 June
*Order will be posted on every Tue and Fri. Thank you for understanding.
*Delivery is available for post and FamilyMart pickup.
#inksundae #stayhome
#art #artist #instaartist #illustrationartists #artistsoninstagram #illustration #illustrator #illustratorsoninstagram #editorialillustration #editorial #drawing #イラスト #イラストレーター #일러스트 #插畫
random drawing 在 Valerie Fong 方詩揚 Facebook 的最讚貼文
Decided to do a little drawing on a random afternoon 🌈🖍 🌄, what do you think 🙈?
random drawing 在 えっちゃんねる/悦子 Youtube 的最佳貼文
こんにちは!えっちゃんです♪
今回はクジ引きスライムをやってみたんだけど、思っていたものとは違うとんでもスライムが出来上がったw
#slime #スライム #音フェチ
▽えっちゃんのSNS
Twitter:https://twitter.com/ecchan_bom2
Instagram:http://urx.blue/E0Sp
サブチャンネル:https://www.youtube.com/channel/UClqYauN21JCrxWF6J3STDgw
▽編集者O-LuHAくんのSNS
Twitter:https://twitter.com/o_luha
素材提供:PIXTA
============================================
チャンネル登録はこちら!
▼ ▼ ▼ ▼ ▼
https://www.youtube.com/c/ecchan
============================================
ボンボンTV はこちら!
▼ ▼ ▼ ▼ ▼
https://www.youtube.com/channel/UC6VSFaHYbR-bhNer7DXxGNQ
=====================================================
ファンレターなどの送り先はこちら!
〒106-6137 東京都港区六本木 6-10-1 六本木ヒルズ森タワー 37階
えっちゃんねる/悦子宛
(O-LuHA君あては名前をえっちゃんねる/O-LuHAくん宛で!)
random drawing 在 Mateusz Urbanowicz Youtube 的最佳解答
I was painting a lot of illustrations with color inks recently and thus ended up with many colorful test sheets. Instead of throwing them out I used them to have some fun drawing random characters!
Tools:
- Palomino BLACKWING pencil
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
random drawing 在 Brenda Tan Youtube 的最佳解答
» WHAT WAS THAT AGAIN?
☛ SHOPBACK
Say Yes! to Black Friday/Cyber Monday Sales 24 Nov - 27 Nov with up to 80% off + up to 20% Epic Cashback!
Shop Black Friday: https://www.shopback.sg/black-friday-sales
Sign up and get $10!: https://www.shopback.sg/brendatan
☛ JORD GIVEAWAY
1. Subscribe to my channel. Those who aren't will not be eligible to win!
2. Enter here: https://www.jordwatches.com/g/yt101616ig
Ends on 3 Dec 17, open internationally
Grand Prize: $180 store credit - Free Shipping - Free Sizing
(All Gift Codes will expire on 12/17/17)
GOOD LUCK!
☛ PROMO CODES
Shopee: BRENDAXSHOPEE!
Enjoy $7 off your first order! Enter code at checkout. Valid for one-time use and not for Miscellaneous, Tickets & Vouchers Category.
LookFantastic: LFBRENDA
20% off, and 23% off Cyber Weekend!
☛ FASHION
Snake Necklaces: https://shopee.sg/Flat-Blade-Snake-Collar-Choker-Necklace-Chain-Women-Jewelry-Accessories-Gift-i.16174997.366150897
Mother of Pearl Set: https://shopee.sg/Mother-of-Pearl-Set-(Pearl-Crystals-from-Swarovski®)-i.15599627.129807463
Black bag: https://shopee.sg/Back-to-Basics-ToteBag-i.1174119.3076590
White bag: https://shopee.sg/Ready-Stock-Canvas-Shoulder-Bags-Bag-Handbag-Satchel-Purse-Tote-i.18316510.278421982
☛ MUSIC
UE Roll
Creative SB Roar 2
Earphones: https://shopee.sg/?BlackFriday?SALE-?A-JAYS-FIVE-WINDOW-EARPHONE-earpiece-A-JAYS-FIVE-a-jays-5-i.34664819.484690888
☛ MAKEUP
Ink Velvet: https://shopee.sg/PERIPERA-Airy-Ink-Velvet-(NO.6-~-10-New-Color)-i.10678993.223467940
Brushes: https://shopee.sg/15PCS-Makeup-Brushes-with-Bag-i.10063876.111346751
Korres Best of Beauty set
☛ SKINCARE
Use code 'LFBRENDA' for 20% off, and 23% off Cyber Weekend!
Omorovicza mask: http://tidd.ly/69685c57
Caudalie set: http://tidd.ly/1f7f5c59
Grow Gorgeous Hair Growth Serum
(BTW if you shop on the main site (.com) on black friday, there's free shipping to Singapore and the main site carries more brands too lol)
☛ ART
Washi Tape: https://shopee.sg/10x-Washi-Tape-Set-Masking-Scrapbook-Decor-Paper-Adhesive-Sticker-DIY-Colors-i.16174997.184802386
Drawing Pens: https://shopee.sg/9pcs-Set-Liner-Drawing-Ink-Pens-Brush-Art-Supplies-i.11241526.468622667
Stickers: https://shopee.sg/LP-35pcs-Rick-And-Morty-Car-Sticker-Random-Character-Sticker-Random-Design-Car-i.27641435.388688608
Tablet: https://shopee.sg/Huion-H420-USB-Writing-Art-Drawing-Graphics-Board-Tablet-4x2.3-inch-Digital-Pen-i.4147463.15359436
☛ FOOD
Ramen:
https://shopee.sg/Instant-Chongqing-Hot-Sour-Glass-Noodle-i.17152354.351180623
https://shopee.sg/Japan-NISSIN-UFO-Yakisoba-Dry-Noodles!-Each-105-128gm-i.913300.316913648
https://shopee.sg/Mala-Ramen-Noodle-hot-spicy-beef-rib-seafood-instant-noodles-sets-i.19517813.478169905
https://shopee.sg/Marutai-Ramen-i.22065553.267412855
» WHAT'S THAT I'M WEARING?
☛ Top: Thrifted
This video is sponsored by Shopee (thank you!) All other products that were sent to me were mentioned in the video. All opinions are honest.
-
Hi, I'm Brenda! I'm 21 and I hail from Singapore. I post all sorts of videos every week! If you like my videos and want to see more, please hit the subscribe button to catch my videos hot off the press! Your support keeps me motivated to produce better content (and to post more frequently). Feel free to click the thumbs up and leave a comment down below of what you'd like to see next. I read every single comment (seriously, I do) and will try my best to respond! :-) Thank you once again for watching my videos, have a blissful day! x
» DON'T BE A STRANGER
☞ Blog - http://wordweed.blogspot.sg
☞ Instagram - http://instagram.com/wordweed
☞ Twitter - http://twitter.com/wordweed
☞ Facebook - fb.me/thewordweed
☞ Snapchat - wtfisair
☞ Ask.fm - http://ask.fm/wtfisair
» BUSINESS INQUIRIES/OPPORTUNITIES
✎ wordweed@gmail.com
▻ I edit with Final Cut Pro X/Adobe Premiere Pro ◅
☺ Music by: FKJ & birocratic
random drawing 在 Random Drawing Generator Challenge - YouTube 的推薦與評價
Caldwell, Nathan, Jacob and Julia make drawings based on randomly generated suggestions on this ... Random Drawing Generator Challenge. ... <看更多>
random drawing 在 Tattoo Culture Bridgend - Random drawing I just finished ... 的推薦與評價
Random drawing I just finished #homer #homersimpson #thesimpsons #simpsons #tattoo #tattoodesign #alternativeart #art #pencildrawing #sketch #sketching. ... <看更多>
random drawing 在 60 random sketch ideas | drawings, art drawings ... - Pinterest 的推薦與評價
Oct 4, 2017 - Explore Garett Goody's board "random sketch ideas" on Pinterest. See more ideas about drawings, art drawings, drawing sketches. ... <看更多>