📜 [專欄新文章] 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.
👏 歡迎轉載分享鼓掌
同時也有240部Youtube影片,追蹤數超過2萬的網紅Laura Ribeiro,也在其Youtube影片中提到,Tshirt Link: https://lauraribeiro.stores.jp Subscribe & don't forget to LIKE this video to help my algorithm, thank you! ––––––––––––––––––––––––––––...
「a* algorithm」的推薦目錄:
- 關於a* algorithm 在 Taipei Ethereum Meetup Facebook 的精選貼文
- 關於a* algorithm 在 kaleidoscope1856 Facebook 的最讚貼文
- 關於a* algorithm 在 Engadget Facebook 的最讚貼文
- 關於a* algorithm 在 Laura Ribeiro Youtube 的最佳解答
- 關於a* algorithm 在 Laura Ribeiro Youtube 的精選貼文
- 關於a* algorithm 在 SLSMusic Youtube 的精選貼文
- 關於a* algorithm 在 Algorithm A vs Algorithm A*: What's the difference? 的評價
- 關於a* algorithm 在 PathFinding.js 的評價
- 關於a* algorithm 在 A* Algorithm for very large graphs, any thoughts on caching ... 的評價
a* algorithm 在 kaleidoscope1856 Facebook 的最讚貼文
Why Saving is Important?
🔖 🔖 🔖 🔖 🔖 🔖 🔖
In past few years Instagram algorithm became an elusive mystery. No matter how much you try to crack this, it becomes more and more difficult to get through.
Likes are a thing of the past now since the time Instagram started to hide likes. So it’s time to say goodbye to likes and hello to Super Likes, aka “SAVES”.
Why is it important?
Because, the more saves your posts get, the more people will see it. Instagram saves are a signal for how the Instagram algorithm works. Saves are one of the major key factors the algorithm uses to rank posts in a feed. It sees the number of saves as an indicator of quality of the content. The more likes, comments, and saves a post gets, the better the exposure.
So if you like my content please do save it as well. It takes nothing but one single tap in the bookmark icon to help a content creator grow. 🙂
These days I don’t only leave likes but I also save the post. Let’s help each other to grow. What say? 😁
🔖
🔖
🔖
🔖
🔖
🔖
🔖
🔖
🔖
#bangladeshitraveller #bangladeshiphotographer #bangladeshitravelblogger #earthfocus #bangladeshitravelgirl #canadiantraveller #travelsolo #girltravel #girltraveller #girlsthatwander #wandergirl #wanderful_places #beautifulparis #parisvibes #pariscityvision #paristourisme #paris_focus_on #parisiloveyou #parisgram #ilovetravelling #ilovetravel #livetotravel #instatravelgram #placestotravel #parismood #kaleidoscopic_journey #placesilove
a* algorithm 在 Engadget Facebook 的最讚貼文
The tool would allow you to list your favorite accounts.
a* algorithm 在 Laura Ribeiro Youtube 的最佳解答
Tshirt Link: https://lauraribeiro.stores.jp
Subscribe & don't forget to LIKE this video to help my algorithm, thank you!
––––––––––––––––––––––––––––––
Modeling in Japan: https://bit.ly/3toFc8r
My Japanese Apartment Series: https://bit.ly/3cJ3Muu
Tokyo Vlog Series: https://bit.ly/2YEe6Mj
Life in Japan Diaries: https://bit.ly/3oIAyyk
––––––––––––––––––––––––––––––
▹Instagram - http://instagram.com/lauraribeiro.x
––––––––––––––––––––––––––––––
Hey Lovessss, been loving this darker look lately, so decided to record a video that no one requested :P
Love Laura
––––––––––––––––––––––––––––––
●LISTEN TO MY MUSIC●
▹Spotify - https://spoti.fi/32gT32B
▹Soundcloud - https://soundcloud.com/lauraribeiro-x
––––––––––––––––––––––––––––––
Hey, I’m Laura Ribeiro. I am Brazilian-Portuguese, raised in London. I moved to Tokyo in 2014.
I work as a full-time model, and a singer-songwriter musician. My channel is based on lifestyle, beauty & fashion videos. I have always loved documenting everything, and being able to look back.
thanks for watching, don't forget to subscribe ♡
––––––––––––––––––––––––––––––
●MUSIC IN THIS VIDEO●
EpidemicSound.com
#TokyoVlog #Japan #makeup #grunge
a* algorithm 在 Laura Ribeiro Youtube 的精選貼文
It was a pretty exhasuting and fun week though!
Tshirts: www.lauraribeiro.stores.jp
Fun Remix song: http://fanlink.to/funtheremix
Subscribe & don't forget to LIKE this video to help my algorithm, thank you!
––––––––––––––––––––––––––––––
Modeling in Japan: https://bit.ly/3toFc8r
My Japanese Apartment Series: https://bit.ly/3cJ3Muu
Tokyo Vlog Series: https://bit.ly/2YEe6Mj
Life in Japan Diaries: https://bit.ly/3oIAyyk
––––––––––––––––––––––––––––––
▹Instagram - http://instagram.com/lauraribeiro.x
–––––––––––––––––––––––––––––
●LISTEN TO MY MUSIC●
▹Spotify - https://spoti.fi/32gT32B
▹Soundcloud - https://soundcloud.com/lauraribeiro-x
––––––––––––––––––––––––––––––
Hey, I’m Laura Ribeiro. I am Brazilian-Portuguese, raised in London. I moved to Tokyo in 2014.
I work as a full-time model, and a singer-songwriter musician. My channel is based on lifestyle, beauty & fashion videos. I have always loved documenting everything, and being able to look back.
thanks for watching, don't forget to subscribe ♡
––––––––––––––––––––––––––––––
●MUSIC IN THIS VIDEO●
#TokyoVlog #Japan
a* algorithm 在 SLSMusic Youtube 的精選貼文
【400,000 Subscribes Special】I played soundtracks from Studio Ghibli written by Joe Hisaihi in a music store located in Taipei. Thank you all for making this happened!
↓ More info down below ↓
💬SLSTalk
Finally, 400K Subscribers. It's been a long way! We're really sorry we couldn't celebrate by doing recital, concert or fans event due to the coronavirus issues. Still, we prepared this special video for you, hope you like it.
I've played them a lot at live streaming, but I rarely do videos for Studio Ghibli Animations. Not because I don't like it, it's just because there were too many covers already on YouTube. So I think this time it's a good opportunity to make it a medley with a different style of video, adding some words I'd like to say to you, hope you like this video.
As many of you might know, maybe it's the change of time, or change of the algorithm, change of YouTube, musicians on YouTube lives much harder than 4 or 5 years ago. We all have to find another way out to keep living. So in the past few month we've been working on streaming platforms, digital albums, and now is the Patreon. It would be really helpful that fans support us with those platforms IF you're able and willing to.
And just to be clear, I won't quit doing music videos even if it keep going worse, because doing these things including performing, recording and editing is one of my personal interest, that's why I started all this in the first place, and that's something never change.
Once again, thanks for all the supporters around the world. We couldn't have done it without you. I don't know how far we can go, but as long as there's audience waiting for me, the music would never stop. No matter what way you choose to support us, we truly appreciate it from the bottom of our hearts.
2021.07.23
SLS
🟧Support us on Patreon and Get Rewards!
► https://www.patreon.com/slsmusic
🎁Get MP3, Sheet Music, Exclusive Contents
📖Sheet Music
🎼https://slsmusic.gumroad.com/l/uRVPP
🎼https://www.mymusicsheet.com/slsmusic/40936
✨Synthesia Video
Patreon► https://www.patreon.com/posts/54018633
YT Member► https://youtu.be/xQYLQQ7sJ_I
🎥 Cinematographer: 建中
https://www.instagram.com/billwang1129/
🎥 Assistant: Claire
🎧Find SLSMusic on Spotify, iTunes, Apple Music, Amazon, Deezer and more
All► https://li.sten.to/slsmusic
Spotify► http://bit.ly/SLSMusicSpotify
iTunes► http://bit.ly/SLSiTunes
🎤Social Media
Website: https://www.slsmusic.net
Instagram: https://www.instagram.com/slsmusictw
Twitter: https://twitter.com/slsmusictw
Facebook: https://www.facebook.com/slsmusictt
🥁DONATION
PayPal► https://www.paypal.me/SLSMusic
歐付寶► https://www.bit.ly/DonateSLS
Special Thanks to【Kinstar 金聲樂器】
https://www.kinstar.com.tw/
🙏THANKS YOU FOR SUPPORTING SLSMusic
🔵Patreon "Grand Piano"
Kater of Glencoe、Lyra Mao、かず K・、阿夜、清艵宮、Mikael Mazareth
🟢Patreon "Piano"
Deemo Harlos、LitGrass Chou、Judy Tseng、風和日麗
🔴YouTube Sponser
交替的白晝與黑夜・阿夜・Chia-Chi Chang・清艵宮・Kater
⏰Song List:
0:16 Merry-Go-Round of Life/人生のメリーゴーランド
1:36 Reprise/ふたたび
2:23 One Summer Day/あの夏へ
3:41 Carrying You/君をのせて
5:06 The Legend of Wind / 風の伝説
7:12 A Town with an Ocean View/海の見える街
■──────────────────■
#ghibli #piano #joehisaishi
a* algorithm 在 PathFinding.js 的推薦與評價
Choose an algorithm from the right-hand panel. Click Start Search in the lower-right corner to start the animation. Select Algorithm. A*. Heuristic. ... <看更多>
a* algorithm 在 A* Algorithm for very large graphs, any thoughts on caching ... 的推薦與評價
... <看更多>
a* algorithm 在 Algorithm A vs Algorithm A*: What's the difference? 的推薦與評價
Both A and A* algorithm use a best-first search to find the least cost path from a start state to a goal state. Best-first search applies a ... ... <看更多>