📜 [專欄新文章] 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.
👏 歡迎轉載分享鼓掌
同時也有60部Youtube影片,追蹤數超過20萬的網紅FON KIRURU,也在其Youtube影片中提到,ขอขอบคุณเหล่านักพากย์มากๆเลยจ้า!!? ((Thanks to the voice actor!!?)) คุณ BasicBomb เพจสำหรับติดตาม : https://www.facebook.com/69BASICBOMB69/ คุณ JEFFY ...
「what can i draw」的推薦目錄:
- 關於what can i draw 在 Taipei Ethereum Meetup Facebook 的最佳貼文
- 關於what can i draw 在 Jessica Sow 卡卡 Facebook 的最讚貼文
- 關於what can i draw 在 Milton Goh Blog and Sermon Notes Facebook 的精選貼文
- 關於what can i draw 在 FON KIRURU Youtube 的最讚貼文
- 關於what can i draw 在 Yunny Hou Youtube 的最佳貼文
- 關於what can i draw 在 tonylamfood Youtube 的精選貼文
- 關於what can i draw 在 900+ Cool Things to Draw |Homesthetics ideas in 2022 的評價
- 關於what can i draw 在 How can i draw a barplot with 3 variables? - Stack Overflow 的評價
what can i draw 在 Jessica Sow 卡卡 Facebook 的最讚貼文
Checkout what I have with me today! The best noise cancelling bluetooth headphones from SONY! If you’re in the market for the best pair of Bluetooth headphones you can get, then yes, this Sony WH-1000XM4 is what you need.
I 'll be doing a live on Facebook at 9pm on 9 September (this coming Thursday) to share about my experience with the new headphones WH-1000XM4 and earbuds WF-1000XM4 from SONY. Join me in my live session, there will be a lucky draw session during my live too. See you all soon in my live session!
今天又有新玩意啦!当前最好的降噪无线耳机
想听听我分享我的使用体验的可以留守我9月9日的 Facebook live 分享噢,时间是晚上9点准,到时也会有一些幸运抽奖,不要错过啊,我们到时不见不散!
With Sony Centre Queensbay Mall
what can i draw 在 Milton Goh Blog and Sermon Notes Facebook 的精選貼文
Jesus Understands your Suffering
“For we don’t have a high priest who can’t be touched with the feeling of our infirmities, but one who has been in all points tempted like we are, yet without sin. Let us therefore draw near with boldness to the throne of grace, that we may receive mercy, and may find grace for help in time of need.” (Hebrews 4:15-16 WEB)
When going through hard times, some people like to say, “I understand what you are going through.” However, most of the time, they do not really know. They are just saying it to be nice and polite.
On the other hand, Jesus know what you are going through.
His head was pierced with a crown of thorns. He was stripped, humiliated, spat on, had His beard pulled, beaten with stripes, crucified, laden with the sins and sicknesses of the world, and burnt with the fiery wrath of God.
No other man will go through worse suffering than Jesus.
The God-Man Jesus knows what you are going through. He became a “man of sorrows” on the day of His crucifixion.
Jesus knows firsthand how difficult life can be on earth. That is one reason why you can confidently ask God for mercy and Grace in every situation.
Draw near to God’s throne—He will never rebuke you or cast you aside.
In your time of need, He will gladly provide the supply.
God is free to be good to you because Jesus paid for you to be made righteous through His shed blood!
Read all about the sufferings of Jesus in the four gospels, and see the powerful revelations within, as well as how what He went through purchased our redemption. These and more, in “Understand the Four Gospels Through the Lens of Grace”: https://bit.ly/understandeveryparable
what can i draw 在 FON KIRURU Youtube 的最讚貼文
ขอขอบคุณเหล่านักพากย์มากๆเลยจ้า!!?
((Thanks to the voice actor!!?))
คุณ BasicBomb
เพจสำหรับติดตาม : https://www.facebook.com/69BASICBOMB69/
คุณ JEFFY RUN OVER
เพจสำหรับติดตาม : https://www.facebook.com/adminJEFFY
คุณ Camuri
เพจสำหรับติดตาม : https://www.facebook.com/CaMuRibird
และคุณ Deadsoul Mos(นักพากย์เสียงประจำบัคแจ็คในไอเดน)??
-----------------------
สวัสดีเพื่อนๆทุกท่านจากทั่วโลกนะคะ อนิเมชั่นนี้เคยคุยเล่นๆกับน้อง Camuri ว่าอยากจะลองจับตัวละครของเราเองมาแต่งคอสเพลย์ดูบ้าง ตอนแรกจะวาดอย่างเดียวแต่ไปๆมาๆงั้นก็ทำเป็นอนิเมชั่นเลยละกัน จริงๆคิดจะให้ Pon แต่งเป็นมุซันในเรื่องดาบอสูตรนะคะ แต่ไปตัดสินใจขอแต่งเป็นดาร์คช็อกโก้แทน(จากเกมส์ cookie run kingdom) ส่วนคนอื่นๆเพื่อนๆหน้าจะพอดูออกแน่นอนค่ะว่าใครแต่งเป็นใครบ้าง ถ้าหากเพื่อนๆคิดอยากให้ Pon Rost Voning หรือต้าวมังกรkiruru ให้แต่งเป็นใครเดี๋ยวจะวาดมาลงเพจให้นะคะ 555555+ ???
และขอขอบคุณเพื่อนๆทุกท่านที่ติดตามผลงานของเรานะคะ ไว้เจอกันโปรเจคหน้านะคะ ???
---------------------------
Hello friends from all over the world. In this work I talked to my friend Camuri. I talked to him about how to cosplay for characters. But I feel that drawing is still not fun.
So I imagined making animations just for fun and to bring the characters to life with cosplay. And each of them will be dressed differently. I think the friends will see who they make up and from what games they are.
At first I wanted Pon to dress up as a muzan from Kimetsu No Yaiba, but I decided to make him a dark cocoa cookie in the cookie run kingdom game. If my friends want to see my characters Pon Rost Voning and kiruru in Cosplay. I will try to draw them on the page of course! LOLOLOL!???
And thank you to my friends for always following my work. See you next time in my project. ??
(If the translation is wrong, really sorry!)
-----------------------
Music used : Where I am From , Trancer
-----------------------
(สามารถติดตามผลงานภาพวาดหรืออื่นๆได้ที่นี่นะคะ)
You can follow up on other channels here.
► http://kiruru2592.deviantart.com/
► https://twitter.com/KiruruFon
► https://www.facebook.com/VoningAndKiruru/?view_public_for=1819356651678212
If something goes wrong, I'm sorry and Thank You!!
![post-title](https://i.ytimg.com/vi/o_VKmYvRiO8/hqdefault.jpg)
what can i draw 在 Yunny Hou Youtube 的最佳貼文
I have gotten a lot of the questions in the comments in my past Spark AR tutorials videos, so I decided to make 1 short tutorial that compiles the most frequently asked questions together to help you guys troubleshoot these common problems when creating your filter.
Frequently Asked Questions & Answers:
-----------------------------------------------------------------------------------------------------------------------
0:07 - Where is My Patch Editor?
0:20 - How to Download and Import FastColorLUT.arp?
Download FastColorLUT.arp: https://drive.google.com/file/d/1SoCBQTDLm8vrqk95WRHcAL33YkFNRZ1C/view?usp=sharing
0:35 - After I Connect My LUT Patch, it shows up Weird Rectangles. How to do resolve
0:58 - How to Add Screen Tap?
1:57 - Why does my texture/frame show up in different color
2:07 - How to have both LUT + Frame in the same filter
2:33 - How to Add Your Own Drawings?
(what is the size of the canvas I should draw on)
3:08 - How do I Change Eye Color?
3:27 - Can I import fonts? Where can I download and import Fonts?
4:04 - “Effect contains text not integrated into scene of effect"
How to get Static Text filter approved
4:24 - Where to Find Dust Textures? https://pinterest.com
-------------------------------------------------------------------------------------------------------------------------
* I speed up the video quite a bit so feel free to slow down the video to watch and follow
我收到很多關於濾鏡的問題留言在我之前的濾鏡教學影片下面,所以我做了一個簡短的Q&A來幫助你們解決在製作濾鏡時常會遇到的問題。如果有別的影片沒有講到的問題,在下面這隻影片下留言發問就可以了!
0:07 - 哪裡可以找到我的Patch Editor工作版面?
0:20 - 如何下載和導入FastColorLUT.arp?
點擊連結下載FastColorLUT.arp: https://drive.google.com/file/d/1SoCBQTDLm8vrqk95WRHcAL33YkFNRZ1C/view?usp=sharing
0:35 - 連結好LUT和Camera後出現很多奇怪的方塊,如何解決?
0:58 - 如何加入螢幕點擊
1:57 - 為什麼我導入的圖顯示出的顏色和原本的不一樣
2:07 - 如何共同有色調LUT和邊框在同一個濾鏡裡面?
2:33 - 如何添加自己手繪圖檔 (畫的版面大小是什麼?)
3:08 - 如何換眼睛顏色
3:27 - 如何導入字體,哪裡可以下載字體?
4:04 - 如何讓文字濾鏡通過審查?
4:24 - 哪裡可以找到灰塵圖檔? https://pinterest.com
Connect with Me!
♡ Instagram | @x.yunny.x
https://www.instagram.com/x.yunny.x/
♡ Instagram | @my.eatz
♡ Email | yunnyhou@gmail.com
Songs
Music by Mark Generous - Meganne - https://thmatc.co/?l=511D4060
Track: Last Night's Dream — Tryezz [Audio Library Release]
Music provided by Audio Library Plus
Watch: https://youtu.be/s-FBmZCBfiI
Free Download / Stream: https://alplus.io/last-nights-dream
What I use:
♡ Camera | Canon G7X Mark ii
♡ Doodles | SketchBook iPad App
♡ Editing | Final Cut Pro x Adobe Premiere Pro
![post-title](https://i.ytimg.com/vi/lQVgMazRGYA/hqdefault.jpg)
what can i draw 在 tonylamfood Youtube 的精選貼文
Time Lapse Adobe Illustrator - Bubble Milk Tea Painting Illustration & T-shirt Mock-up
This is my first painting on iPad illustrator. My skill may not be perfect but I still hope you can enjoy this time-lapse! Subscribe to my channel if you want to see more clips like this!
What I need is Boba Pearl Milk Tea:
https://www.redbubble.com/shop/ap/50634548?asc=u
Explore my full collection on Redbubble:
https://bit.ly/thefoodandfashion
––––––––––––––––––––––––––––––
Buy me a coffee! 5USD can support my work!
https://www.buymeacoffee.com/tonylamfood
Instagram/Facebook:
https://instagram.com/tonylamfood
https://facebook.com/tonylamfood
––––––––––––––––––––––––––––––
––––––––––––––––––––––––––––––
Track: Tropical Love — Vendredi [Audio Library Release]
Music provided by Audio Library Plus
Watch: https://youtu.be/8C-9VIKe-VQ
Free Download / Stream: https://alplus.io/tropical-love
––––––––––––––––––––––––––––––
![post-title](https://i.ytimg.com/vi/ZrMsIH7xj7A/hqdefault.jpg)
what can i draw 在 900+ Cool Things to Draw |Homesthetics ideas in 2022 的推薦與評價
Easy things to draw will also be featured, most of them including step by step tutorials for each… More. ·. 2,187 Pins. 1d. ... <看更多>