📜 [專欄新文章] 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.
👏 歡迎轉載分享鼓掌
同時也有6部Youtube影片,追蹤數超過21萬的網紅Ghib Ojisan,也在其Youtube影片中提到,Did you know there is a Japanese izakaya restaurant specialising in maguro (tuna)? The place is called Kuro Maguro, located at Tanjong Pagar and Sunte...
「more cost efficient」的推薦目錄:
- 關於more cost efficient 在 Taipei Ethereum Meetup Facebook 的最佳解答
- 關於more cost efficient 在 Engadget Facebook 的最佳解答
- 關於more cost efficient 在 eCloudvalley Facebook 的最佳解答
- 關於more cost efficient 在 Ghib Ojisan Youtube 的最佳解答
- 關於more cost efficient 在 Ghib Ojisan Youtube 的最佳貼文
- 關於more cost efficient 在 一二三渡辺 Youtube 的最讚貼文
more cost efficient 在 Engadget Facebook 的最佳解答
The automaker hopes to start using the process by the mid-2020s.
more cost efficient 在 eCloudvalley Facebook 的最佳解答
Data AI/ML experts from eCloudvalley include AWS Big Data Specialty and Machine Learning Specialty certified engineers and data scientists. We look forward to assisting enterprises in internal optimization and development by building the platform, designing the scheme, and training the AI model to suit each customer's needs.
Founded in 2011, Red Dot Payment is a trusted online payment company that provides premium payment solutions and expertise to the brightest merchants across the Asia Pacific. Since the primary goal of the online payment process is to assist customers in making online transactions easier, the speed of transaction data will have a positive impact on customer satisfaction.
With the Data AI/ML solutions of eCloudvalley, Red Dot has significantly reduced the transaction conversion time by approximately 75% and saved about 98.23% of the cost. Not only have they achieved an efficient and secure payment process, but this allows Red Dot and its customers to monitor transactions via real-time dashboards.
Learn more about the project on Red Dot, please clink in follow 👉 https://www.ecloudvalley.com/red-dot-payment/
more cost efficient 在 Ghib Ojisan Youtube 的最佳解答
Did you know there is a Japanese izakaya restaurant specialising in maguro (tuna)? The place is called Kuro Maguro, located at Tanjong Pagar and Suntec City. I visited the Tanjong Pagar outlet, right outside the MRT. Despite the great location, I don't know why but I've always missed it. Kuro Maguro has been doing maguro business for over 50 years, and you can try truly unique tuna dishes here. Join me as I devour into the delicious world of tuna.
Thank you KING OF TIME for sponsoring this video! If you are looking for a reliable & cost-efficient attendance management system, definitely check it out. Claim your 30 day free trial from the link below!
https://huubap.com/kot/
For more info about the restaurant, check out Kuro Maguro's Facebook page:
https://www.facebook.com/KUROMAGUROMD/
* Claim 50% off "Grilled Maguro Rib (Usual price 29.8++)" by saying KING OF TIME upon ordering. Offer valid on weekdays only, until 30th April 2021.
Follow me on social medias!
?Instagram https://www.instagram.com/ghibli_ojisan/
?Twitter https://twitter.com/ghibli_ojisan
?Subscribe: http://urx3.nu/HTUJ
?Watch - Perhaps the Best Meal I had in Singapore:https://youtu.be/d46br1oiYaE
?Merch Links(アパレル):
SE Asia | https://ghib-ojisan.secure-decoration.com/shop/category/T-Shirt?c=2731898
Japan | https://suzuri.jp/ghib-ojisan
USA & EU | https://teespring.com/stores/ghib-ojisan
Business Enquiries
✉️[email protected]
You are welcome to send fan mails but I may not be able to respond to all of them. But I immensely appreciate your support. Thank you!
#Singapore #KuroMaguro #KINGOFTIME
more cost efficient 在 Ghib Ojisan Youtube 的最佳貼文
Did you know there is a new food place not really known among local Singaporeans? It's called Kamome Bakery, located at Novena. Opened in November 2019, this bakery/cafe serves authentic Japanese breads. I tried all of their signature menus out and introduced what I liked the most.
Thank you KING OF TIME for sponsoring this video! If you are looking for a reliable & cost-efficient attendance management system, definitely check it out. Claim your 30 day free trial from the link below!
https://huubap.com/kot/
I am hosting KING OF TIME's YouTube channel! The 1st video is uploaded so check it out: https://youtu.be/lEfgtmokt34
You can claim your FREE 6 piece gyoza limited to first 50 sets. Watch the video for more info!
Check out Kamome Bakery here:
https://www.facebook.com/pages/category/Cafe/Kamome-Bakery-102858964498977/
Follow me on social medias!
?Instagram https://www.instagram.com/ghibli_ojisan/
?Twitter https://twitter.com/ghibli_ojisan
?Subscribe: http://urx3.nu/HTUJ
?Watch - Funniest Video I’ve Made:https://youtu.be/qmqJ5A4DaOI
?Merch Links(アパレル):
SE Asia | https://ghib-ojisan.secure-decoration.com/shop/category/T-Shirt?c=2731898
USA & EU | https://teespring.com/stores/ghib-ojisan
Japan | https://suzuri.jp/ghib-ojisan
Business Enquiries
✉️[email protected]
You are welcome to send fan mails but I may not be able to respond to all of them. But I immensely appreciate your support. Thank you!
#Singapore #KamomeBakery #Novena
more cost efficient 在 一二三渡辺 Youtube 的最讚貼文
倉庫の整理・・・できません、
The arrangement of the warehouse ・・・ It is not possible to do.
Model name of bicycle (small leisure motorcycle) with motor to which Honda Motor Co., Ltd. is doing manufacturing sales monkey (MONKEY). The form of the model put on the market by Kon soon will be AB27. It is called generally fourMINI with the gorilla etc. of the sisters car.
Model name of motorcycle that YAMAHA MOTOR was manufacturing Yamaha Motor Co., Ltd. and GT (GT). The alias is a mini tray. GT50 of displacement 50cc and GT80 of 80cc were manufactured as a series model.
KSR-II
KSR-II was put on the market in 1990. KSR-I, and the body and the engine (The displacement is 79cc) are common, and basically cars only for getting on of one person.
At first, it became a sale end in 2001 though it kept being put on the market after KSR-I previously became a sales termination, and pioneering gradually existence of Minimotard it and an efficient engine received revaluation, and it became a popular unusually late, model as a motorcycle because exhaust emissions regulations had made the use of two stroke engine difficult though popularity was not fragrant because of the displacement class. As a result, Kawasaki Heavy Industries abolished two stroke engine of a car Japan and domestic-oriented and on the market for the first time (The game vehicle is excluded) in four domestic manufacturers.
Moreover, because two stroke engine that vigour is good for a light body is installed, it has the combat power that can make inroads into the high rank in gymkhana.
Yamaha Motor Co., Ltd. Passol is an electric scooter that began putting on the market in the scooter and 2002 when YAMAHA MOTOR began putting on the market in 1977. Both become bicycles with the motor in the displacement division.
HONDA puts the leisure motorcycle and Rordopal based on the bicycle on the market in 1976. The sales offensive was strengthened with TV commercial as the weapon that appointed a drastic low price and Sophia Loren. The scooter that Yamaha Motor Co., Ltd. prepared as the opposition model is Passol.
It designs the commodity of the priority, and Slustepp etc. to be able to get on by arranging installing a smooth step side and the foot have been achieved more friendly though the woman wears a skirt ..under the concept that it is possible to get on... In TV commercial, eight various herbs Kaoru who had a popular image was appointed and it tied to the smash hit.
Significance of existence of Passol
The simplification of the manufacturing process by busy of making of parts and a unit a plastic material greatly contributed also to the reduction of car heavy cost, and the mechanism and the style became prototypes of the scooter made in Japan thereafter. It is not possible that there were about five time price difference in the rival in Japan though the existence of the Vespa that the Itariapiageo Co. manufactures was the same kind of scooter.
The power performance was welcomed at maximum speed with 45 km/h by range of customers practical that neither an excessive performance nor an expensive body were demanded about the catalog data though was poor.