📜 [專欄新文章] 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.
👏 歡迎轉載分享鼓掌
同時也有9部Youtube影片,追蹤數超過5萬的網紅Daphne Iking,也在其Youtube影片中提到,We all know someone who gives advice even when not asked. In life, or in our virtual space. They might not know whether you’re struggling with someth...
swap space 在 科技產業資訊室 Facebook 的最佳解答
DARPA提出Space-BACN新專案—可重新配置光通訊為衛星間互連鋪路
Space-BACN專案是在尋求開發一種體積小、重量輕、功耗低、成本低(Size, Weight, and Power, Cost;SWaP-C)的衛星間光通訊終端,易於整合並可在低軌道(LEO)的平台上運行。該專案涉及太空通訊、光衛星間鏈接、可重新配置數據機、模組化組件以及太空監測和控制。....
swap space 在 Tony Capatch 柯龍 Facebook 的精選貼文
Summer is around the corner! Don’t regret not preparing for the beach ahead of time!
暑假快來嘍!不要後悔自己沒有提早準備海邊的身材喔!⚠️中文部分都在下面圖片上⚠️
🔹1 on 1 personal trainer opening spot currently open🔹一對一教練有空位上課了
⚠️Currently have morning spots available only from 7:00am to 08:30am on Tuesday, Thursday and Saturday morning ⚠️禮拜二,四跟六現在都有空在早上07:00-08:30。有興趣密我一下我們看看時間能不能幫你調整一下
Only looking for serious people looking to change their physique. 我主要的是認真要訓練的人。這不是一個服務,這是一個教學。我不是為了你們舒服有人聊天過時間,我是為了你們目標為止需求的。
I won’t make everyone train like they’re getting ready for a contest, however, I will approach and personalize everyone’s personal goals specifically to their needs. Location is in Taipei city or New Taipei City不需要跟我一樣要準備比賽的態度一樣那麼硬。但你們需要了解這是需要中心,耐心,努力,認真的態度才能夠改變自己的體態。我會看著你們本人的需求做成你們課程內容
Clientele I will not be taking stated below: ⬇️
I handpick clients. Space is limited. If you’re mot serious about the commitment please do not message me! Thank you! 下面有寫我正在找的學生需求
🔹No unstable working time professionals who will swap time schedules
如果你時間不穩定的話,無法正常來上課,這個課程不適合你
🔹 No college kids, don’t need to hear about why you can’t come to class: midterms, money, part time job, studying, etc. 不要大學生,我不想一直聽到一些理由跟我說你們為什麼不能來上課,期中考,錢不夠,讀書準備考試。要負責任這些事情才可以處理生活其他部分。
🔹Don’t sign up if you’re afraid of being sore, tired or getting sweaty. This isn’t for me, it’s for you. Understand it’s tasking to change your body. 如果你怕酸痛,怕流汗,怕累,怕訓練到疲勞,這個課程不適合你。
🔹Don’t complain about which exercises, sets and or reps I tell you to do. If something is painful/discomfort, obviously I’ll change it, but I’m talking purely about arguing against the workouts because they’re hard. 不要抱怨跟我說那些運動動作太難,太累,不好做等等。本來改變不是簡單拿到的,一定會這樣。如果說你做到很不舒服因為關節痛,肌肉有問題或者遇到姿勢不對,一定要跟我說我才能幫你們改。
🔹No short term clientele: minimum 20 classes at a time ~ 2 or 3 classes per week at minimum. Anything less than that and you’re not getting benefit. 不要短期學生。至少要20堂課,一個禮拜必須要至少上2~3堂課才能有效果。少於2堂課你已經不用再來了。太少沒有用。
🔹If you’re unwilling to change diet, fix alcohol consumption or your sleep schedule to fit your goals, then this course isn’t for you. 如果不願意借酒,改變飲食習慣,睡眠,健康程度的話這也不適合你。你需要能夠想要把自己變好,有中心在健康想法範圍內才會有進步。要能夠接受這些改變才會變成更好。
🔹I don’t sell bullshit, I sell results. Tracking will be a thing. 我不是賣爛的教學。我賣的教學會有效果。記得我無法24/7跟你們本人在一起。時間陪我只有一次一個小時,其他時間必須要負責任,外面訓練完亂吃,亂喝,不認真做心肺鼓勵下去不能怪我說我什麼都不會教課因為你自己不認真不是我的問題。你們自己需要有負責任在課程之外時間控制自己。我會紀錄進步速度還有我們上課運動的內容計畫一下長期時間的訓練課程。
Leggo
swap space 在 Daphne Iking Youtube 的最讚貼文
We all know someone who gives advice even when not asked. In life, or in our virtual space.
They might not know whether you’re struggling with something. They might not know whether you are working on an issue. They might not know whether you want to hear their opinion.
They’ll talk anyway. They’ll tell you what to do anyway. They’ll shove answers right down your throat if they have to.
In this week's episode, we swap notes about people who love to #JustSharing. I'm glad we did this episode. It makes me more mindful in my conversation with others ... and more.
#SwappingNotes is an independent (read: unfunded) web show where Sheril A. Bustaman (Fluff) and I (Pons) talk candidly and truthfully about our experiences being wives, mothers, and women - among other things.
Let us know what you think k? Do comment below.
Thanks for watching and please do not forget to subscribe to my FB/YouTube/ IG page @daphneiking and @sherilabustaman.
This is also on podcast over Fat Bidin Media. (Thanks Zan!)
Thanks for watching and please do not forget to subscribe!
Also follow me on my other social media channels:
Instagram
https://www.instagram.com/daphneiking/
Facebook
https://www.facebook.com/daphneiking/
Twitter
https://twitter.com/DaphCLPT
If you also need my profile and showreel, please visit:
joelebosi.wix.com/bedifulstory
Thanks for watching and please do not forget to subscribe!
swap space 在 Dainghia25 Youtube 的精選貼文
New PES 2021 PS4 Option File by PES Universe. It includes fully licensed of Premier League
SkyBet Championship
LaLiga Santander
LaLiga SmartBank
Serie A TIM
FULL Bundesliga with created players, accurate faces & builds
Kits 2048 Px*
Highest Quality
*V1 is full 2048 so you’re gonna have to choose some things to not import as you won’t have all the space
*for PC it's save folder, replace it to \KONAMI\eFootball PES 2021 SEASON UPDATE\RANDOM NUMBER\
Download Link http://bit.ly/pesuniv2021
Credits to PESUniverse || Support them : https://www.pesuniverse.com
Tutotial
PES 2021 V1 – INSTALL – PS4
1. Download the option file & then navigate to the download destination (downloads or desktop folder usually but this despends on your PC)
2. When downloaded, right click on the file and choose ‘Extract to WEPES’ and the file will extract in a few seconds
3. Insert your USB key into your PC/MAC. Right click on the USB icon and select Format if needed (make sure it is set to FAT32)
4. Now return to the WEPES Folder (the one you just extracted) & right click on the WEPES folder & select ‘copy’ & then return to the USB folder
5. Open up the USB folder (double click to go to the USB root) and simply paste the WEPES folder (right click then select paste)
6. This will now copy over so wait a few minutes. Once complete you should have an open folder on your USB called WEPES
7. Now eject the USB from your PC/MAC & and insert it into your PS4. Follow all the instructions until you can go to Edit Mode.
8. When you first start PES 2021, there will be an import tutorial, just follow the intructions before you proceed with importing the Option File.
9. Once in Edit Mode, navigate to Import/Export and select Import Team.
10. Now select All files (PS4 square button) & select ‘Go to Detailed Settings’ and then press OK (DO NOT TICK ANY BOXES HERE)
11. This will import everything except Bundesliga Players so relax for 5-10 minutes while it does its thing. Once completed, return to the import screen
12. Now select all Bundesliga Teams (do not select Schalke, Bayern & Bayer Leverkusen) National Teams & Brazilian teams ONLY
13. Tick both boxes “Players” & “Overwriting images” & then Import by pressing OK. Return to the main Edit Menu
14. Select Import Competition, select All files (PS4 square button) & Go to Detailed Settings’ and then press OK (DO NOT TICK ANY BOXES HERE)
15. Return to main Edit Menu & go to competition structure, reduce the draw size for the Bundesliga to 18 and swap the teams across from other euros
Sometimes you might get an error, do not worry, simply follow the steps again & reimport
▶ Ủng Hộ Tớ (Donate) :
https://unghotoi.com/dainghia25
https://streamlabs.com/dainghia25
▶ SUBSCRIBE MY CHANNEL : https://goo.gl/VPOrGK
▶ RENUMBER LIKE, SUBSCRIBE AND SHARE MY VIDEO!!!
▶ Fanpage Facebook : https://www.facebook.com/dainghia25gaming
▶ Facebook : https://www.facebook.com/dainghia25
#dainghia25gaming #livestream #dainghia25
swap space 在 Eiscue King Youtube 的最佳貼文
#Wii #作業用BGM #ゲームBGM #WiiParty
勉強、車内BGMなどにお使い頂けます。
ヘッドフォン、イヤホン推奨。
0:00 Minigame Rules
0:16 Theme Song/Main Manu
2:03 Main Manu
4:35 Rankings
5:42 Globe Trot
8:14 Globa Trot Overtime
10:48 Swap Meet
12:26 Spin-Off
14:45 Balance Boat (Beginner)
16:32 Match-Up
18:45 Animal Tracker
22:21 Hide 'n' Hunt
25:12 Garden Gridlock
28:09 Minigame Battle
31:00 Shifty Gifts
32:55 Zombies Tag
34:35 Space Brawl
36:50 Rope Sling
39:10 Spotlight Fight
40:13 Back Attack
41:51 Roll to the Goal
43:52 Pop Coaster
43:12 Flycycle Team
47:28 Spring Ringers
Twitter @BeefBoss423