📜 [專欄新文章] 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.
👏 歡迎轉載分享鼓掌
同時也有14部Youtube影片,追蹤數超過71萬的網紅VOGUE Taiwan,也在其Youtube影片中提到,年薪會影響購物習慣?►► https://smarturl.it/ahizub 我們問了不同收入的女性:妳一年後的財務目標是什麼?找出誰希望在她們的儲蓄帳戶中增加更多的錢,誰希望從當前的投資中獲得更多。 #財務 #女人 #Vogue冷知識 【 其他熱門主題】 讓喜歡的事變生活!Good Job! ...
「financial goal」的推薦目錄:
- 關於financial goal 在 Taipei Ethereum Meetup Facebook 的最佳貼文
- 關於financial goal 在 Facebook 的精選貼文
- 關於financial goal 在 股榮 Facebook 的最佳貼文
- 關於financial goal 在 VOGUE Taiwan Youtube 的最佳解答
- 關於financial goal 在 Dan Lok Youtube 的精選貼文
- 關於financial goal 在 Dan Lok Youtube 的最讚貼文
- 關於financial goal 在 Simple steps to set financial goals and plan for the future 的評價
financial goal 在 Facebook 的精選貼文
Dear FAM, I received an email for help yesterday and we're trying to make ends meet for them. We've scrutinized all details and its urgency & are now working on them.
We are looking to provide provisions for 100 needy Orang Asli Families that are based in Raub, Pahang.
I'm reaching out to all of you for financial assistance. The goal is RM20,000. If you are able to lend a hand, please do. Details shared below
Arwind Kumar
Maybank
114067208613
Each set of provision will have:
1. Rice (10kg)
2. Bihun big pack
3. Oil (5kg)
4. Tea o (big pack)
5. Sugar
6. Oats (big) 1kg
7. Flour
8. Salt
9. Soup seasoning 250g
10. Milk powder 1.8kg
11. Baba’s Curry powder 250g
12. Baba’s meat powder 250g
13. Washing powder (big) 5kg
14. Toothpaste (big)
15. Shampoo (big)
16. Yellow Dhal (2kg)
17. Green dhal (2kg)
18. Chickpeas (2kg)
financial goal 在 股榮 Facebook 的最佳貼文
信儲局,唔怕。大致是炒美股網友的心聲。
‘’Jay Powell, the chair of the Federal Reserve, said the US central bank was ready to intervene if inflation spiralled out of control, but stressed that he expected price increases to ease later in the year.
“Inflation has increased notably and will likely remain elevated in coming months before moderating,” Powell said in prepared remarks released ahead of a hearing at the House financial services committee on Wednesday.‘’
He added that the Fed “would be prepared to adjust the stance of monetary policy as appropriate if we saw signs that the path of inflation or longer-term inflation expectations were moving materially and persistently beyond levels consistent with our goal”.
financial goal 在 VOGUE Taiwan Youtube 的最佳解答
年薪會影響購物習慣?►► https://smarturl.it/ahizub
我們問了不同收入的女性:妳一年後的財務目標是什麼?找出誰希望在她們的儲蓄帳戶中增加更多的錢,誰希望從當前的投資中獲得更多。
#財務 #女人 #Vogue冷知識
【 其他熱門主題】
讓喜歡的事變生活!Good Job! ► http://smarturl.it/r7si6s
芭蕾舞者們的血淚史 ► http://smarturl.it/uhot5l
唐綺陽12星座深入剖析 ► http://smarturl.it/in8eqp
美容編輯正芳隨你問 ► http://smarturl.it/zf5840
口音、服裝專家拆解經典電影 ► http://smarturl.it/zcbgmf
---------------------------------------------------------------
【追蹤 VOGUE TAIWAN】
★訂閱VOGUE TAIWAN Youtube:http://smarturl.it/xbtuuy
★VOGUE TAIWAN 官網:http://www.vogue.com.tw/live/
★VOGUE TAIWAN Facebook:https://www.facebook.com/VogueTW/
★VOGUE TAIWAN Instagram:https://www.instagram.com/voguetaiwan/
★VOGUE TAIWAN LINE:https://reurl.cc/V66qNn
★美人會不會 FB社團:http://hyperurl.co/rgfitl
▷ Make sure you subscribe to my channel and hit the notification bell, so you don’t miss any of my new videos → http://smarturl.it/xbtuuy
--------------------------------------------
※關於時尚,VOGUE說了算!自從1892年第一本VOGUE在美國出版以來,至今已有122年的歷史,始終被時尚專業人士所推崇,因此榮譽為Fashion Bible時尚聖經。
--------------------------------------------
※台灣VOGUE隸屬Condé Nast Interculture Group,相關國外影片皆由國外授權提供給台灣使用,台灣VOGUE秉持服務網友,讓更多中文語系觀眾可以看到國際影片跟中文字幕,所以在此頻道分享給大家,如果喜歡我們的頻道,請訂閱我們,我們將會持續努力帶來更多優質內容。
financial goal 在 Dan Lok Youtube 的精選貼文
Are You Still Giving People Their Time In Order To Help Them? Stop Wasting Your Time And Start Helping People In A Smarter Way. Sharpen Your Persuasion Skills To Impact More People Today: https://stopwastingtime.danlok.link
Wanting to help others is a worthwhile goal - and yet you can only help one person at a time. If you want to make a true impact in this world you need to stop wasting your time and find ways to automate your help. Watch this video for Dan Lok's top tips on how to stop wasting your time and do high-impact activities instead.
? SUBSCRIBE TO DAN'S YOUTUBE CHANNEL NOW ?
https://www.youtube.com/danlok?sub_confirmation=1
? UNLOCK A Better Version Of Yourself, Check Out My Shop: https://shop.danlok.link ?
Check out these Top Trending Playlists -
1.) Boss In The Bentley - https://www.youtube.com/playlist?list=PLEmTTOfet46OWsrbWGPnPW8mvDtjge_6-
2.) Sales Tips That Get People To Buy - https://www.youtube.com/watch?v=E6Csz_hvXzw&list=PLEmTTOfet46PvAsPpWByNgUWZ5dLJd_I4
3.) Dan Lok’s Best Secrets - https://www.youtube.com/watch?v=FZNmFJUuTRs&list=PLEmTTOfet46N3NIYsBQ9wku8UBNhtT9QQ
Dan Lok has been viewed more than 1.7+ billion times across social media for his expertise on how to achieve financial confidence. And is the author of over a dozen international bestselling books.
Dan has also been featured on FOX Business News, MSNBC, CBC, FORBES, Inc, Entrepreneur, and Business Insider.
In addition to his social media presence, Dan Lok is the founder of the Dan Lok Organization, which includes more than two dozen companies - and is a venture capitalist currently evaluating acquisitions in markets such as education, new media, and software.
Some of his companies include Closers.com, Copywriters.com, High Ticket Closers, High Income Copywriters and a dozen of other brands.
And as chairman of DRAGON 100, the world’s most exclusive advisory board, Dan Lok also seeks to provide capital to minority founders and budding entrepreneurs.
Dan Lok trains as hard in the Dojo as he negotiates in the boardroom. And thus has earned himself the name; The King of Closing.
If you want the no b.s. way to master your financial destiny, then learn from Dan. Subscribe to his channel now.
★☆★ CONNECT WITH DAN ON SOCIAL MEDIA ★☆★
YouTube: http://youtube.danlok.link
Dan Lok Blog: http://blog.danlok.link
Dan Lok Shop: https://shop.danlok.link
Facebook: http://facebook.danlok.link
Instagram: http://instagram.danlok.link
Linkedin: http://mylinkedin.danlok.link
Podcast: http://thedanlokshow.danlok.link
#DanLok #StopWastingTime #Motivation
Please understand that by watching Dan’s videos or enrolling in his programs does not mean you’ll get results close to what he’s been able to do (or do anything for that matter).
He’s been in business for over 20 years, and his results are not typical.
Most people who watch his videos or enroll in his programs get the “how-to” but never take action with the information. Dan is only sharing what has worked for him and his students.
Your results are dependent on many factors… including but not limited to your ability to work hard, commit yourself, and do whatever it takes.
Entering any business is going to involve a level of risk as well as massive commitment and action. If you're not willing to accept that, please DO NOT WATCH DAN’S VIDEOS OR SIGN UP FOR ONE OF HIS PROGRAMS.
This video is about STOP WASTING TIME.
https://youtu.be/OQtwa4M9alI
https://youtu.be/OQtwa4M9alI
financial goal 在 Dan Lok Youtube 的最讚貼文
So, you want to start an online business. But where to start? What should you sell? What else do you have to consider? In this video, Dan Lok shares the 2 things you can sell online, as well as the 3 questions you have to ask yourself before starting an online business.
Have Unique Capabilities, Looking For New Opportunities? Discover The Top Supplier Opportunities Here:
Alibaba March Expo: https://allsha.re/a/alibabaexpodan
Alibaba March Expo Trend Hunter: https://allsha.re/a/alibabaexpothdan
Alibaba March Expo Elite Partner: https://allsha.re/a/alibabaexpoepdan
For the buyers who are looking for products and high-quality suppliers that give them a competitive edge you can easily access it all in one place; a vetted group of global suppliers with innovative, new technologies and products in various categories. Aim to help you enhance your competitive edge and achieve your global business goal. Make sure to check in every month to see what new suppliers, products, and technologies in your target category have been added!
Also Check Out Alibaba.com Buyers Central YouTube Channel For Valuable Information: https://www.youtube.com/channel/UCSoIxtP6J6oNo_d1njSluxw?sub_confirmation=1
▬▬▬▬▬▬▬▬▬▬ Video Highlights ▬▬▬▬▬▬▬▬▬▬
0:00 - Intro - How To Start An Online Business
0:45 - 3 Most Important Questions To Ask Before Starting A Business
3:18 - How To Find Trending Products To Sell
▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬
? SUBSCRIBE TO DAN'S YOUTUBE CHANNEL NOW ?
https://www.youtube.com/danlok?sub_confirmation=1
? UNLOCK A Better Version Of Yourself, Check Out My Shop: https://shop.danlok.link ?
Check out these Top Trending Playlists -
1.) Boss In The Bentley - https://www.youtube.com/playlist?list=PLEmTTOfet46OWsrbWGPnPW8mvDtjge_6-
2.) Sales Tips That Get People To Buy - https://www.youtube.com/watch?v=E6Csz_hvXzw&list=PLEmTTOfet46PvAsPpWByNgUWZ5dLJd_I4
3.) Dan Lok’s Best Secrets - https://www.youtube.com/watch?v=FZNmFJUuTRs&list=PLEmTTOfet46N3NIYsBQ9wku8UBNhtT9QQ
Dan Lok has been viewed more than 1.7+ billion times across social media for his expertise on how to achieve financial confidence. And is the author of over a dozen international bestselling books.
Dan has also been featured on FOX Business News, MSNBC, CBC, FORBES, Inc, Entrepreneur, and Business Insider.
In addition to his social media presence, Dan Lok is the founder of the Dan Lok Organization, which includes more than two dozen companies - and is a venture capitalist currently evaluating acquisitions in markets such as education, new media, and software.
Some of his companies include Closers.com, Copywriters.com, High Ticket Closers, High Income Copywriters and a dozen of other brands.
And as chairman of DRAGON 100, the world’s most exclusive advisory board, Dan Lok also seeks to provide capital to minority founders and budding entrepreneurs.
Dan Lok trains as hard in the Dojo as he negotiates in the boardroom. And thus has earned himself the name; The King of Closing.
If you want the no b.s. way to master your financial destiny, then learn from Dan. Subscribe to his channel now.
★☆★ CONNECT WITH DAN ON SOCIAL MEDIA ★☆★
YouTube: http://youtube.danlok.link
Dan Lok Blog: http://blog.danlok.link
Dan Lok Shop: https://shop.danlok.link
Facebook: http://facebook.danlok.link
Instagram: http://instagram.danlok.link
Linkedin: http://mylinkedin.danlok.link
Podcast: http://thedanlokshow.danlok.link
#eCommerce #OnlineBusiness #Alibaba
Please understand that by watching Dan’s videos or enrolling in his programs does not mean you’ll get results close to what he’s been able to do (or do anything for that matter).
He’s been in business for over 20 years and his results are not typical.
Most people who watch his videos or enroll in his programs get the “how to” but never take action with the information. Dan is only sharing what has worked for him and his students.
Your results are dependent on many factors… including but not limited to your ability to work hard, commit yourself, and do whatever it takes.
Entering any business is going to involve a level of risk as well as massive commitment and action. If you're not willing to accept that, please DO NOT WATCH DAN’S VIDEOS OR SIGN UP FOR ONE OF HIS PROGRAMS.
This video is about How To Start An Online Business.
https://youtu.be/LQ_Dc1DNRt4
https://youtu.be/LQ_Dc1DNRt4
financial goal 在 Simple steps to set financial goals and plan for the future 的美食出口停車場
Financial decisions can be overwhelming, especially during a global pandemic. Bachelor of Commerce students outline some simple steps to ... ... <看更多>