📜 [專欄新文章] 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.
👏 歡迎轉載分享鼓掌
同時也有355部Youtube影片,追蹤數超過1萬的網紅AKaMiKz,也在其Youtube影片中提到,Code: Seed - Seihei no uta [Android/iOS] Turn-based, Gacha Size: 2.36 GB Links: QooApp Ver. : https://apps.qoo-app.com/en/app/16895 CODE: SEED Seihi ...
no numbers 在 Facebook 的最佳貼文
I was talking about vaccine deaths on a pro-vax post. And everyone kept calling me a liar and saying that "NO ONE has died" from a Covid Vax. Is American media so biased that Americans truly don't know that people have died from vaccine shots???
Covid deaths in the last 2 years and vaccine deaths in the last few months......are almost equal for Taiwan.
And I know you guys will respond with " Well just because they died after getting the vaccine doesn't mean the vaccine caused it!!?!?!"
But.....remember in America they were listing people who were dying of cancer as covid deaths if they tested positive post mortem. So BOTH numbers are probably a bit exaggerated.
no numbers 在 Facebook 的最讚貼文
How is my 4/5 months old baby @meregoround going to Primary school in just 3 months..? 😭😭😭 Time is really a.. Strange thing.
I had kept the kids home (away from school) everytime the numbers surge and i think Meredith is feeling the fatigue of that. This time round she tells me she will be extra careful and hope she can continue to go to school like her friends. She say she don't wanna miss any practice for her graduation skit and dance filming..
At first it was still a "sorry Meredith, i don't think so.." but later i realise.. She's no longer a baby. And Josh is also supportive of her request so.. She's right now in school..
I guess with enough time, we all get used to things. Good things, bad things. With time, good things become normal things and bad things..? They become normal things too.
Time is a strange but amazing thing.
At least i can say for sure, with time, my chunky unibrow baby here has turn into a 6 year old fine young lady who is very very sensible ❤️
Keep track of what time is doing for you.. And what it's doing to you 🖤
no numbers 在 AKaMiKz Youtube 的精選貼文
Code: Seed - Seihei no uta [Android/iOS] Turn-based, Gacha
Size: 2.36 GB
Links:
QooApp Ver. : https://apps.qoo-app.com/en/app/16895
CODE: SEED Seihi no Uta is an apocalypse themed 3D Anime Adventure RPG Card Collecting Game with unique creative Match 3 combat gameplay. In which players can build and upgrade numbers of facilities in campsite to fight against the invasion of zombies. Summon anime girls as seed fire soldiers and deploy them to front line to defend the peace of the safe zone. Unveil the scenes behind the truth of doomsday, save the fate of mankind, become one of the demon slayers of legendary epic seven, the unknown adventure awaits.
Game Features
Strategic Combat
On the basis of RPG turn-based combat, attack the enemy by matching 3 skill slots of a particular attribute to form skill set, along with combat strategies and tactical designs to complete different difficulty levels of challenge. To cast the skill according to the battlefield situation and skill effect is the key to the victory. Each Seed Fire soldier has her own unique attribute, effective combination of skill set can be more varied and effective to attack.
Character Growth
With over 100 unique anime girls as seed fire solders to collect, there’s virtually no limit to the number of different team combinations you can assemble. Players not only can improve the combat effectiveness, but also can cultivate the favorability of the seed fire soldiers. Each member of the team has their own unique story. With the improvement of their favorability, players can learn their unknown stories and interact with them, so that their feelings of love can be passed on to each other.
Construction
Work together to build a safe zone against zombies, clean up infected areas with the seed fire team, expand the safe zone, remove risk factors, improve the safety of the camp, and create the strongest safe zone.
Exploration
Each exploration will take a different route, and each choice will lead to a different event, including a swarm of zombies, and the possibility of harvesting some living materials. Each choice will determine the success or failure of the quest, but the ultimate goal is only one: to end the regions leaders and return home safely.
no numbers 在 Daphne Iking Youtube 的最佳解答
LIVE: Elyn Pow #YouHaveToGetToKnowMyNextGuest
Thanks Elyn Pow for sparing some time to talk about your Rawsome #PayItForward initiative and more!
Find out more over their Instagram : @itsrawsome
#Repost @itsrawsome
・・・
Almost 1 year of covid, and we were just thinking about ourselves. Whining about business, work, life, and stress - basically about everything. We totally forgot about the frontliners who have been working for 365 days nonstop almost, burning themselves down. Yesterday, I received a text at 6am from my close friend, asking me if we can help.
Last year in March we did a #PayItForwardWithRawsome, sending food to the frontliners and from there we managed to get our community to help and we even went to feed the urban poor for 6 months or maybe more together with @dapurjalanankl . And that was a year ago and it just seems like yesterday. In this battle of fighting hard times, I asked myself, what is my battle compared to theirs?
Because of Covid, we pivoted and diversified to #FrozenReadyToEat, and if it is not because of MCO, we wouldn’t have done this. Last year we contributed packed food and it wasn’t that ideal because it was perishable and cant be kept long and if it is left unattended it’s not fresh and might cause food poisoning and many, many more issues. So we learnt.
Here we are, again asking help from the community, this time we are sending frozen ready to eat to them because they have no time to cook, it can be kept in the freezer for a long period of time, convenient, just heating up, it is wholesome food and it’s affordable to contribute, RM6 per box. We are truly grateful, as I am writing we have collected 700 boxes on top of my own 500 boxes in less than 24 hours. I have nothing to say but thank you to all of you out there who are so kind, generous and big at heart. Just one IG story and we have managed to collect 1200 boxes and the numbers are still coming in.
Today I have started this initiative by sending 500 boxes in the morning and the doctors helped us distributed to 6 bases in Hospital Sg Buloh for the covid team. For those who think otherwise: Yes - if you think we are bringing in sales for ourselves, Yes - if you think it is a marketing scheme, Yes - if you think it’s a publicity stunt and Yes - we do make a little profit to cover our own team as we’re trying to survive. But for whatever the reason we have been constant. ?
❤️
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!
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
no numbers 在 童心看世界 Oliviababylove Youtube 的最讚貼文
#学日语 #日语初级 #记录学习日语
No. 5 日语学些什么 | 日语初级第五堂课内容分享 |我们学日语啦|说明处有视频内容| Learning Japanese Language |日本語 が 勉強 しましだ|这集很适合日本旅行用
下载今天学习内容PDF
https://drive.google.com/file/d/19bGc0V_PiZO_sRfvPiP6IODkxH3tac23/view?usp=sharing
新的生词 New Vocabulary
【问方向,地方,或者人物的所在处,ask for location or people】
ここ koko (这里, here/this place)
そこ soko (哪里, there,place near the listener)
あそこ asoko (那边, the place over there)
どこ doko (哪里, where/what place)
【比较有礼貌的说法,in a polite way】
こちら kochira (也等于koko 的意思:这里,here,this place)
そちら sochira (等于soko的意思:哪里, there,place near the listener)
あちら achira (等于asoko的意思:那边, the place over there)
どちらdochira (等于doko的意思: 哪里, where/what place)(抱歉视频中我念少了这句话)
【地方,物品, place and item】
きょうしつ Kyōshitsu (课室,classroom)
しょくどう Shokudō (食堂,canteen,dining hall)
じむしょ Jimusho (办公司,office)
かいぎしつ Kai gishitsu (会议室,meeting room, conference room)
うけつけ uketsuke (询问处,reception)
ロビー robī (大堂,lobby)
へや heya (房间,room)
トイレ toire (厕所,toilet)说法1
おてあらい otearai (厕所,toilet) 说法2
かいだん kaidan (楼梯,staircase)
エレベーター Erebētā (电梯,elevator)
エスカレーター Esukarētā (自动扶梯,escalator)
じどうはんばいき Jidō han bai ki(自动贩卖机,vending machine)
でんわ denwa (电话,phone)
おくに okuni (国家,counry)前面加 o お是比较有礼貌的方式
かいしゃ kaisha (公司,company)
うちuchi (屋子,house)
くつ kutsu (鞋子, shoe)
ネクタイ nekutai (领带,neck tie)
ワイン wain (酒,wine)
うりば uriba (卖场,柜台,deparment/counter)
ちか chika (地下层,basement)
かい kai 楼层说法1
がい gai 楼层说法2
なんがい nan gai 第几楼 which floor
【关于数目, About numbers】
~えん en (日元,yen)
いくらikura (多少钱,how much)
ひゃくhyaku (百,hundred)
せん sen (千,thousand)
まん man (万,ten thousand)
【对话用词, Conversation use】
すみません sumimasen (不好意思, excuse me)
どうも Dōmo (谢谢, Thanks )
いらっしゃいませ irasshaimase (欢迎你, Welcome)
を みせてください o misete kudasai (_ 请拿给我看, _ pls show me)
じゃ Ja
を ください o kudasai (_ 请给我, _ please give me)
【国家名字 Country Name】
イタリア itaria (意大利, italy)
スイス suisu (瑞士, Switzerland)
フランス furansu (法国, France)
ジャカルタ jakaruta (雅加达, Jakarta)
バンコク bankoku (曼谷, Bangkok)
ベルリン berurin (柏林, berlin)
しんおおさか Shin Ōsaka(新大阪车站, Osaka Station)
トイレはどこですか Toire wa doko desu ka
请问厕所在哪里
トイレはここです Toire wa koko desu
厕所在这里 (靠近我的地方)
トイレはそこです Toire wa soko desu
厕所在哪里 (靠近问话者的地方)
トイレはあそこです Toire wa asoko desu
厕所在哪里(离开问话者比较远的地方)
エレベーター はどこですか Erebētā wa doko desuka
电梯在哪里
【楼层,几楼,floor,which level】
(在日本的大楼是没有ground floor 或者lower ground, 只有basement,之后就是一楼开始,去旅行的时候可以注意一下哦)
一楼 いっかい ikkai (Level 1)
二楼にかい ni kai (Level 2)
三楼 さんがい san gai (Level 3)
四楼 よんかい yon kai (Level 4)
五楼 ごかい go kai (Level 5)
六楼 ろっかい rokkai (Level 6)
七楼 ななかい nana kai (Level 7)
八楼 はっかい hakkai (Level 8)
九楼 きゅうかい kyu kai (Level 9)
十楼 じゅうかい Jū kai (Level 10)
地下层一楼 ちかいっかい chika ikkai (Basement level 1)
地下层二楼 ちかにかい chika ni kai (Basement level 2)
第几楼 なんがい nan gai (Which floor)
注意:基本上只是三楼我们用Gai, 其他楼层都是用kai
くつうりば kutsu uriba
鞋子卖场 shoe deparment
くつうりばなんがいですか kutsu uriba wa nan gai desuka
请问鞋子的卖场在那一层Which level is the shoe deparment
くつうりばはにかいですkutsu uriba wa ni kai desu
鞋子卖场在二楼 shoe deparment is at level two
今天的学习到这里,辛苦了:)