📜 [專欄新文章] 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.
👏 歡迎轉載分享鼓掌
同時也有72部Youtube影片,追蹤數超過2萬的網紅Faiz Najib Official ファイズ,也在其Youtube影片中提到,From the bottom of my heart, I’m so happy and grateful for all of the love, truly I can’t thank you enough. A lot of things have been happening to me...
「in a short period of time」的推薦目錄:
- 關於in a short period of time 在 Taipei Ethereum Meetup Facebook 的最讚貼文
- 關於in a short period of time 在 IELTS Nguyễn Huyền Facebook 的最讚貼文
- 關於in a short period of time 在 外交部 Ministry of Foreign Affairs, ROC(Taiwan) Facebook 的最佳貼文
- 關於in a short period of time 在 Faiz Najib Official ファイズ Youtube 的最佳貼文
- 關於in a short period of time 在 kottaso cook【kottaso Recipe】 Youtube 的最佳解答
- 關於in a short period of time 在 Linora Low Youtube 的最佳貼文
- 關於in a short period of time 在 "Within a short time" vs "within a short period of time" - English ... 的評價
in a short period of time 在 IELTS Nguyễn Huyền Facebook 的最讚貼文
TỪ VỰNG IELTS - CHỦ ĐỀ THROWAWAY SOCIETY
🎯PHẦN TỪ VỰNG
- throwaway society: xã hội mà trong đó người ta sử dụng đồ đạc trong một thời gian ngắn sau đó vứt chúng đi, mua thứ đồ mới
vpurchase the latest version of things: mua phiên bản mới nhất
- encourage somebody to do something: khuyến khích ai đó làm gì
- to be in good condition and perfectly functional: trong tình trạng tốt và các chức năng hoạt động tốt
- overconsumption = excessive consumption: việc tiêu thụ quá mức
- overproduction = excessive production: việc sản xuất quá mức
- long-lived products = durable products = products that are made to last for a long period of time: những sản phẩm có tuổi thọ dài
- short-lived products = non-durable products = products that are made to last for a short period of time: những sản phẩm có tuổi thọ ngắn
- repurchase = buy again: mua lại
- repeat customers: những khách hàng sẽ mua hàng lại ở cửa hàng họ đã mua
- make a dent in your finance: làm giảm số tiền bạn đang có
- higher profit margins for manufacturers: lợi nhuận biên lớn hơn cho các nhà sản xuất
- tempt customers into buying the latest, novelty items: thu hút khách hàng mua những sản phẩm mới nhất
- disposable products: những sản phẩm dùng 1 lần rồi vứt đi
- solid waste generation rates: tỷ lệ thải ra chất thải rắn
- environmental degradation: sự suy khóa môi trường
- contaminate soil and water: làm ô nhiễm đất và nước
- increase consumer spending: tăng chi tiêu của khách hàng
- bad spending habits: thói quen tiêu xài xấu
- leftover food: đồ ăn thừa
- a new version with more features: phiên bản mới với nhiều tính năng hơn
- have a negative/detrimental/harmful effect on: có ảnh hưởng có hại lên...
- buy things that you do not really need: mua những thứ mà bạn không thực sự cần
- a waste of money: một sự lãng phí tiền của
- buy new things to relieve stress or anxiety: mua đồ mới để giải tỏa căng thẳng và lo âu
- overspend = spend beyond one's income: chi tiêu quá mức
- huge amounts of toxic waste: 1 lượng khổng lồ chất thải
- to be discharged into the environment: bị thải ra môi trường
- encourage people to reuse and recycle more: khuyến khích người dân tái chế và tái sử dụng nhiều hơn.
- get into serious debt: bị mắc nợ nghiêm trọng
🎯PHẦN BÀI MẪU
These days people in some countries are living in a “throwaway” society which means people use things in a short time then throw them away. What are its causes and what impacts can it have?
Dịch đề: Ngày nay người dân ở một số quốc gia đang sống trong một “xã hội bỏ đi” nghĩa là người ta sử dụng đồ đạc trong một thời gian ngắn sau đó vứt chúng đi. Nguyên nhân và ảnh hưởng mà xã hội này gây ra?
The topic of “throwaway society” has been discussed in recent years. In this society, people tend to throw away their old items regardless of whether or not they still work and purchase the latest version of things. This essay will look at some primary reasons for this phenomenon and the adverse impacts that it could have on individuals and the environment.
There are several causes of the throwaway society and I think advertising could be the first culprit. Advertisements encourage people to purchase goods and services that they do not really need by delivering a message that possessing the latest version of an item could improve a person’s self-image, confidence and even social status. For example, many of today’s teenagers spend nearly $1,500 buying iPhone X to show that they are wealthy and fashionable even though their old phones are still in good condition and perfectly functional. Another cause is mass production of non-durable goods which are often used once and thrown away. These products are much cheaper and more convenient than durable ones, hence, attract a large number of customers.
Individuals living in the throwaway society could suffer a great deal. They could easily get into serious debt if they get into the habit of buying the latest, novelty items. Many teens are being burdened with thousands of dollars in credit card debt for their unnecessary purchases, which could lead to depression and anxiety. Environmental degradation is another problem facing the throwaway society. Due to excessive production of disposable goods, huge amounts of hazardous waste are being discharged into the environment, which directly contaminates soil and water.
In conclusion, there are various factors leading to the advent of our throwaway society and increasing consumer debt and environmental damage are the two major problems which result from this society.
(299 words, written by Nguyen Huyen)
PHẦN VÍ DỤ: https://ielts-nguyenhuyen.com/tu-vung-ielts-chu-de-throwaway-society-dich-tu-chi-tiet/
#ieltsnguyenhuyen
in a short period of time 在 外交部 Ministry of Foreign Affairs, ROC(Taiwan) Facebook 的最佳貼文
敬 自由 / 蔡焜霖
71年前,1950年的9月10日,蔡焜霖先生被逮捕了。
理由是高中二年級時參加過讀書會,而罪名是「1949年5月參加叛亂組織並曾為叛徒散發傳單」。
.
整整10年後,1960年的9月10日,他才回歸自由身。
此後,他人生的任務就是讓世人知道,當年那些年輕人是清白的。
.
71年後,外交部在今年聯合國推案影片《敬 自由》中,我們留下了蔡焜霖前輩的影像與口白
.
『所有的歷史都有黑暗
但不是所有的國家都願意面對
要繼續前進
我們首先必須正確地認識自己
我們有全世界最長最長的戒嚴時期
如今,我們過去所經歷的遺憾
能夠成為未來人們活得更自由的一小部分基礎
這是我們這個國家的勇氣』
.
如果聯合國的重要任務之一是要讓國家尊重人民的權利,台灣的夥伴價值值得聯合國重視。
-
在此感謝
蔡焜霖先生
國家人權博物館-白色恐怖景美紀念園區
.
To Freedom / Tshua Khun Lim
Mr. Tshua Khun Lim was arrested on September 10, 1950.
The reason for his arrest was the “crime” of attending a study group in his second year of senior high school. Accused of attending an insurgent organization in May of 1949 and having once distributed leaflets inciting rebellion, Tshua was imprisoned for ten years before regaining his freedom on September 10, 1960.
Since his release, his mission in life has been to clear the names of all those that were falsely imprisoned at that time.
71 years later, he has been featured in MOFA's UNGA short film "To Freedom" and speaks his own truth saying:
"All histories have their darkness, but not every country is willing to face up to it. To move forward we must first recognize our true selves. Ours was the longest period of martial law in the world. Today, all those sorrows we experienced in the past are built into a modest foundation for more freedoms in the future. This is where our country’s courage lies."
If the UN states part of its mission as encouraging countries around the world to respect the rights of their people, Taiwan's vision of global partnership can serve as a valuable reference.
#UNGA76
#HearTaiwan
#WorkingTogether
#FreedomForAll
#UNGlobalGoals
#TaiwanCanHelp
#RespectTheRightsOfPeople
in a short period of time 在 Faiz Najib Official ファイズ Youtube 的最佳貼文
From the bottom of my heart, I’m so happy and grateful for all of the love, truly I can’t thank you enough.
A lot of things have been happening to me these past few months, whether it’s good or bad, I’ve learned to be grateful for the little things and learned to change my perspective towards things in a different way.
Throughout my life so far, at this age I’ve met a lot of amazing people from different walks of life and I’m forever grateful that I get to learn a thing or two from these amazingly wonderful people, even though it is for a short period of time, I’m happy to have stumbled upon them truly.
Despite whatever that we’re currently going through, I got the opportunity to spend my quarantine with my family and that doesn’t happen often. For 3 years, I’ve been wanting to have a proper Ice Cream Cake for my birthday but never really got the chance to get it but Alhamdulilah 2021, finally got it! Thanks Kak, Sabrina, Abah and Mama. Infact I’d call my friends virtually via Zoom Calls & Google Meet, we’d call & talk, laugh till it’s 4/5AM in the morning, I missed all of them truly
I even got the opportunity to spend my birthday with some of the #FAIZIES which I didn’t expect it to happen at all, they really did surprised me and it means the world to be receiving that, Thanks guys. It’s a memory that I’ll remember always and forever. You guys made my day truly, I love all of you.
As I grow, I believe that we’ll never stop learning as we live and as we grow we will keep meeting new obstacles in life that’ll make us wonder and think. Furthermore, I believe that from these obstacles that we’ve all went through, it’ll mold us into better & stronger individuals, as we grow. Moving on, Letting go of things that it is beyond our control
17th June 2021 12AM ||
I am beyond grateful for everything that has happened, Alhamdulilah. I’m so happy to be celebrating my 19th birthday with all of you, to many more InsyaAllah. I’ll keep striving and try to be better & better, I love all of you wholeheartedly x.
~ FAIZ NAJIB || #Officially19 #誕生日
in a short period of time 在 kottaso cook【kottaso Recipe】 Youtube 的最佳解答
◆こっタソ動物園チャンネル
新しいチャンネルです!こちらもおヒマな時にどぞ。
⇒https://www.youtube.com/c/こっタソ動物園-kottasoanimals
ご視聴ありがとうございます。
Thank you for watching
I want to deliver delicious Japanese-food recipes to the world
【材料】(保存期間:冷蔵で約4日)
●キュウリ:2本
●茄子:2本
●みょうが:3本
●カブ:5個
●オクラ:2パック
●赤パプリカ:1個
●黄パプリカ:1個
●大葉:10枚
●醤油:100ml
●めんつゆ:50ml(白だしでもOK)
●みりん:100ml
●お酒:150ml
●鶏ガラスープの素:大さじ1/2
●豆板醤:大さじ1/2(コチュジャンでもOK)
●酢:大さじ2
●塩こんぶ:大さじ1/2
●干し椎茸:2個
●生姜
●炒りごま:お好み量
●唐辛子:お好み量
※野菜はお好みで旬の物を入れてあげてね
※豆板醤の辛みが苦手な方は赤味噌同量+にんにく少々
※色んな物にかけて食べられるよう味は濃いめにしてあります。
そのまま食べたい方はお好みに合わせて味を薄めてあげたり、野菜の量を増やしてね
-------------------------------------------------------
今回は父が亡くなる前に家族を想って遺してくれた
僕にとっては宝物みたいなご馳走レシピから
『超やべぇ野菜漬け』を作らせて頂きました。
小さい頃の僕にでも簡単に作れるよう
難しい行程は全部省いて美味しく出来るように
父ちゃんが考えてくれたものです。
色んな出汁が良い感じにあわさっていて
とても深みのある味わいに仕上がってます。
今回は思い入れの強いレシピだったので撮影するかどうか悩んだんですが
お客様の美味しい笑顔を見るのが本当に大好きな父ちゃんだったので
コロナで大変な世の中ですが、このレシピで少しでも多くのご家庭の食卓で笑顔が作れたら
父ちゃんも天国で喜んでくれると思い動画にさせて頂きました。
今回動画で合わせている素麺はもちろん、うどんやご飯、豆腐、鶏肉や豚肉、サラダなどなど
合わせられるものは無限大です。
漬け時間が短くても野菜のシャキシャキ食感が楽しくて美味しいですし
半日後には味が染みて、これまた最高に美味しいです。
どちらも是非試してみて欲しいです。
本当に簡単なので是非作ってみて下さい。
【Ingredients】 (Preservation period: about 4 days refrigerated)
● Cucumber: 2
● Eggplants: 2
● Myoga: 3
● Turnip: 5
● Okra: 2 packages
● Red Paprika: 1
● Yellow Paprika: 1
● Shiso leaves: 10
● Soy sauce: 100ml
● Men-tsuyu (white soup stock can be used): 50ml
● Mirin: 100ml
● Sake: 150ml
● Chicken soup stock: 1/2 tablespoon
● Dou ban jiang (gochujang is also OK): 1/2 tablespoon
● Vinegar: 2 tablespoons
● Salted kelp: 1/2 tablespoon
● Dried shiitake mushrooms: 2
● Ginger
● Roasted sesame seeds: as you like
● Chili pepper: as you like
※ Add whatever vegetables are in season to your liking.
※ If you don't like the spiciness of Dou ban jiang, use the same
amount of red miso + a little garlic
※ If you prefer to eat it as it is, you can dilute the flavor or
increase the amount of vegetables according to your taste.
-------------------------------------------------------
This time, I made "Amazingly Yummy Pickled Vegetables" from a treasured
recipe that my father left for my family before he passed away.
In order to make it easy even for me as a child to make, My father's
idea was to make it tasty without all the difficult steps.
The sauce has a good combination of various dashi and has a very deep flavor.
I had a hard time deciding whether or not to publish this recipe
because I had such strong feelings about it.
My father really loved to see the smiles on the faces of his
customers, so I decided to make a video because I thought he would be
happy in heaven if I could bring smiles to the faces of as many
families as possible with this recipe in a world that's in trouble
with Corona.
This recipe can be used not only with somen noodles, but also with
udon noodles, rice, tofu, chicken, pork, salads, etc.
There are no limits to what you can eat with it.
Even if the marinating time is short, the crunchy texture of the
vegetables is fun and delicious, and after half a day, the flavors
have soaked in and it tastes great.
I hope you will try both of them.
It's really easy to make, so please give it a try!
●Instagram
⇒https://www.instagram.com/kossarishuntaso/
●twitter
⇒https://twitter.com/kottaso_recipe
●連絡先
⇒kossarisyuntaso@gmail.com
#こっタソの自由気ままに #漬けるだけ #超やべぇ野菜漬け #やみつき野菜 #Perilla #Cucumber #JapaneseGinger #Eggplant #okra #turnip #JapanesePickles #青椒 #피망 #GreenPepper #PorkRecipe #和食 #低糖質おつまみ #糖質制限レシピ #ヤセ筋 #低糖質レシピ #ヘルシー #ダイエットレシピ #激痩せ #糖質制限レシピ #ロカボレシピ #dietfood #lowcarbdiet #dietrecipe #晩ごはんレシピ #ご飯泥棒 #おかず #極上レシピ #ワンパンレシピ #時短レシピ #おうちごはん #至福の料理 #ご飯のお供 #太らないレシピ #やみつきレシピ #酒のつまみ #簡単つまみ #こっタソレシピ #男飯レシピ #mukbang #먹방 #男子ごはん #HomeCooking #StayHome #大食い #男ウケ料理 #晩酌 #自炊 #酒の肴 #簡単レシピ #弁当 #作り置き #常備菜 #Bento #recipesfordinner #マツコの知らない世界 #WithMe #Eazyrecipe #モッパン #から揚げ #唯一無二の絶品レシピ #こっタソ動物園
in a short period of time 在 Linora Low Youtube 的最佳貼文
Subscribe to my channel : http://youtube.com/linoralow
Bit of a throwback video to the earlier part os 2021. This was my first time ever going to Glamz at Genting which is a popular instagrammable spot just before Genting.
I had a fabulous time with my peeps from @Koafitnessmy and it was a great time to just get away from the concrete lifestyle. It was only a night but I definitely would come back for a longer period to stay.
Find out more about Glamz here : https://glamz.com.my/stay-with-us
Join my KOA tribe for workout sessions here: https://koafitnessmy.com/
You can find me here
Website: http://www.linoralow.com
Facebook:http://facebook.com/linoralow
Instagram: http://instagram.com/linoralow
Twitter: http://twitter.com/linoralow
Tiktok: http://tiktok.com/@linoralow
in a short period of time 在 "Within a short time" vs "within a short period of time" - English ... 的推薦與評價
Both sentence fragments: within a short time ... and. within a short period of time ... are sensewise, equivalent and idiomatic. ... <看更多>