📜 [專欄新文章] 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.
👏 歡迎轉載分享鼓掌
同時也有447部Youtube影片,追蹤數超過209萬的網紅RADWIMPS,也在其Youtube影片中提到,▼「SUMMER DAZE」listen now https://soundcloud.com/radwimps_official/summerdaze -------------------- 昨年2020年、各音楽フェスは軒並み中止に。2021年に大きな期待を寄せて迎えてはみたものの、...
art is fun 在 Facebook 的最佳解答
My interpretation of TIME TIMEPieces project theme ‘Building A Better Future’ is expressed through a little girl character where she looks toward a future with the option to begin her adventure with either Fiat Money or Crypto.
This little girl is from Borneo, and the mountain in the background is Mount Kinabalu, the highest mountain in Borneo. Lush forests surround the mountain, and the land is rich and healthy. The banknote in the centre reflects a changing perception of currencies and their role in our time. This banknote is issued by Memebank, a parody central bank that pokes fun at fiat currencies with crypto meme culture. Hidden in this banknote are “easter eggs” such as morse codes, a very pixelated “decentralised” text, and even smaller pixelated icons.
This NFT represents my aspiration and hope for a future where little girls are empowered to choose their adventures and determine their own choices - a world that celebrates nature, technology, art and the human race (little icons within the banknote representing these four elements through icons of a rocket, a cat, a kite and a human). This piece is also a special tribute to little girls from Borneo and Southeast Asia. 💚
Find out more at NFT.time.com! @time
I can’t thank the TIME team enough for this incredible opportunity, and also for my team who worked on this project with me!
art is fun 在 Lemon Film Facebook 的最佳解答
Art-Zoo Wonder Gardens is a colourful, fun outdoor trail – perfect for family outings!
art is fun 在 RADWIMPS Youtube 的最佳貼文
▼「SUMMER DAZE」listen now
https://soundcloud.com/radwimps_official/summerdaze
--------------------
昨年2020年、各音楽フェスは軒並み中止に。2021年に大きな期待を寄せて迎えてはみたものの、明るい兆しが一向に見えてこなかった今年の春頃。友人の訓ちゃん(野村訓市)とこんな話になった。
「なんだかまた鬱屈した夏が来そうだね。せめて聴いている間は気持ちが晴れて、どこまでも駆けていけそうな、踊り続けられるような夏のアンセムを作ろうよ。この夏の眩惑を一曲に閉じこめよう。」
そこからこのSUMMER DAZEは出発しました。
夏が近づくにつれアレンジも徐々に決まっていき、友人たちに聴かせると皆一様に喜んで踊り出すのでした。そして映像を作ろうと盛り上がり、一人、また一人と参加したいと言ってくれるクリエイターが増え、学生の自主制作のようにワイワイと映像制作も進んでいきました。皆がそれぞれの仕事を終えた夜中に打ち合わせやロケハンを繰り返し、撮影をしていきました。音源作り、Tシャツ作り、ムービー制作、ジャケット撮影のすべてを自分たちだけで行ったのは初めてのことでした。
この音源と映像は僕たちから、共に2021年夏を生きるすべての同士たちへのプレゼントです。無料でSoundCloud、YouTubeにアップします。この夏の好きなシーンで聴いてもらえると嬉しいです。
忙しい合間を縫ってやりたいと賛同し参加してくれたYOSHIROTTEN、カメラマンの川上くん、映像まわりを寝ずにやってくれた笠井くん、夜中の街を全速力で走ってくれたNANAMI、そして訓ちゃん、改めてありがとう。
皆さんの夏が輝きますように。
洋次郎
--------------------
In 2020, various music festivals got cancelled. I welcomed 2021 with hope but even around Spring time, there was no good news. That’s when my friend Kun-chan (Kunichi Nomura) and I had this conversation.
“I feel like this summer is going to be another depressing one. So let’s write a summer anthem that we can clear our minds and feel like we can keep running and dancing forever at least while we listen to that song. Let’s capture all the dazzlement of Summer in this song!”
That is how SUMMER DAZE started.
As Summer approached, arrangement came into shape and when I played it to my friends, they all started dancing with joy. When we decided to create a video to accompany the song, more and more creators wanted to take part and we ended up working on it like a bunch of students having fun making a homemade video together. We gathered late at night after work to hold meetings, go location hunting and shoot the video. It was the first time for me to write music, make T-shirt, shoot a video and cover photos all on our own.
This song and the video are a gift from us to all our comrades living their lives in the Summer of 2021. We will post them on SoundCloud and YouTube free of charge. I hope you will enjoy the song at your favorite time and place this summer.
Special thanks to YOSHIROTTEN, Kawakami-kun for all the awesome photos, Kasai-kun for your sleepless nights working on the video, NANAMI who ran around the midnight city in full-speed and last but not least, Kun-chan. I know you guys are all really busy but thank you for taking time to be part of the project.
I wish you all a very bright and happy Summer!
Yojiro
--------------------
<SUMMER DAZE Official Music Video>
Creative Director : Kunichi Nomura
Art Director : YOSHIROTTEN
Movie Director・Editor : Yusuke Kasai
Director of Photography : Tomoyuki Kawakami
1st AC : Kohei Shimazu
Camera Assistant : Kenta Adachi
Colorist : Masahiro Ishiyama
Hair & Make-up : Taro Yoshida
Production Manager : Yoko Watanabe
Producer : Ryuta Nagano
Special Thanks : Shinji Torigoe / Yusuke Oguro / DOSCOI TANAKA
Production : YAR inc. / SANA inc.
CAST:NANAMI KEYES(TOMORROW TOKYO)
Supported by :VANS JAPAN
--------------------
Official web:https://radwimps.jp/
Twitter:https://twitter.com/RADWIMPS
Instagram:https://www.instagram.com/radwimps_jp/
Facebook:https://www.facebook.com/radwimps.official/
art is fun 在 Mateusz Urbanowicz Youtube 的最讚貼文
The first collaboration piece with @呉竹Kuretake painted using their ZiG Historic Art brush-pens set inspired by Claude Monet! This was an exciting challenge to try - painting something with only the six pens and the included brush pen. I drew the lines with Kuretake's Mangaka felt tip pens.
Tools:
- Kuretake "Historic Art" ZiG brush-pens set Claude Monet.
- Kuretake ZiG Mangaka 0.3 0.5 0.8 fet tip pens.
- Fabriano Venezia Drawing book.
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 first one, which is "reflection."
I had a lot of fun trying out the brush pens, but this time I used them more like I would do with regular watercolors - mixing them on ceramic plates. This experiment got me excited about using the more convenient 48 colors set without mixing or diluting the inks. That should be a nice challenge too! There will be a making video of this piece later on my YouTube channel!
Thanks to Kuretake for sending me these awesome tools to ply with 👍
- Kuretake x WWM site (Japanese): https://www.kuretakezig.us/world-watercolor-month
- Kuretake x WWM site (English): https://www.kuretakezig.us/world-watercolor-month-en
- WWM official website: https://doodlewash.com/world-watercolor-month-july/
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
art is fun 在 BritneyTOKYO Youtube 的最讚貼文
Easy and Fun nail tutorials💅🏼✨ Perfect design this summer 2021 ❤️❤️❤️
First time I though nail polishes from fashion brand are not for pro. Omg !Trust me! Those are very pigmented and dry so fast! Now It’ in my daily kit!
簡単ネイルアート💅🏼💅🏼💅🏼💕セルフネイルにお勧め!
ZARAから発売されたネイルポリッシュ!発色が良く、乾くのも早いのでセルフネイラーにもお勧め!