📜 [專欄新文章] 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.
👏 歡迎轉載分享鼓掌
同時也有89部Youtube影片,追蹤數超過15萬的網紅Gina music,也在其Youtube影片中提到,Don't forget to turn on the bell icon for future uploads 🔔✔️ 西洋音樂愛好者✨這裡不會有冗長的介紹文卻是個讓你挖歌的好地方😎 追蹤Gina music社群挖掘更多音樂🌹 facebook👉 https://www.facebook.com...
「so damn good」的推薦目錄:
- 關於so damn good 在 Taipei Ethereum Meetup Facebook 的最佳解答
- 關於so damn good 在 Facebook 的最佳解答
- 關於so damn good 在 Facebook 的最讚貼文
- 關於so damn good 在 Gina music Youtube 的精選貼文
- 關於so damn good 在 AnDyWuMUSICLAND Youtube 的精選貼文
- 關於so damn good 在 クレイユーキーズKureiYuki's Youtube 的最讚貼文
- 關於so damn good 在 Aleem - So Damn Good - (OFFICIAL VIDEO) - YouTube 的評價
- 關於so damn good 在 amal (aka wuvv) - so damn good - YouTube 的評價
- 關於so damn good 在 So Damn Good - Sture Zetterberg feat. Sigrid ... - YouTube 的評價
- 關於so damn good 在 Craig J Snider & Mark Picchiotti - So Damn Good (Feat. Katie ... 的評價
- 關於so damn good 在 Damn Good Productions | Sydney NSW | Facebook 的評價
so damn good 在 Facebook 的最佳解答
Chocolate banana omlet
チョコバナナ・オムレット
YouTube
https://youtu.be/yUGuKg-e4Q4
I made a homemade version of the chocolate banana omelet from the convenience store and it was gorgeous.
The fluffy dough, the soft cream, the crispy chocolate-coated bananas, it was just so damn good!
コンビニに売っていたチョコバナナオムレットを自家製で作ってゴージャス☆にしてみました。
ふわふわ生地に柔らかクリームでパリパリのチョコでコーティングしたバナナとの相性抜群でめっちゃ美味しかったです!
#Youtube #ASMR #foodie #instafood #dessertporn #スイーツ #yummy #foodpics #instafood #recipe #手作りお菓子 #チョコレート #chocolate #baking #sweets #chocolat #baker #bakery #homemade #omlet #オムレツ #オムレット #banana #バナナ #チョコバナナ #chocolatebanana #omelette #omlette #cake #chocobanana
so damn good 在 Facebook 的最讚貼文
One more day to the premiere of #ThisLandIsMine on @mediacorpch5 .
First 4 episodes already out on @mewatch.mediacorp and I binged all 4 eps at one go. And I am blown away by everything in the drama from the story to the casts performance to the beautiful shots and the directing.
I am so humbled to be able to work with people who are not only so damn good in the craft, but even greater as a human being.
Thank you @weiyufilms for this opportunity. 🙏
so damn good 在 Gina music Youtube 的精選貼文
Don't forget to turn on the bell icon for future uploads 🔔✔️
西洋音樂愛好者✨這裡不會有冗長的介紹文卻是個讓你挖歌的好地方😎
追蹤Gina music社群挖掘更多音樂🌹
facebook👉 https://www.facebook.com/Ginamusicland
instagram👉https://www.instagram.com/ginamusic_yujia/
spotify 歌單👉https://open.spotify.com/playlist/2EfPjFfdqN8NzUwj1XNoZC
🌺贊助GINA讓頻道走得更長久•̀.̫•́✧👉https://p.opay.tw/WSwM8
Donate and support my channel (PayPal) 👉https://paypal.me/ginamusic?locale.x=zh_TW
🌸本影片與 Secret Signals 合作宣傳🌸
想讓更多人認識你的聲音嗎?歡迎投稿😎
Submit your music 👉ginamusictaiwan@gmail.com
For business inquiries about copyright issues, photos and song submissions,
please contact👉 https://www.facebook.com/Ginamusicland
____________________________________________________
Social Media:
Watch the official video for "Yesterday" by Virginia To Vegas: https://www.youtube.com/watch?v=6WemTZcIe9c
👑Virginia To Vegas:
https://instagram.com/virginiatovegas
https://twitter.com/virginiatovegas
https://www.facebook.com/virginiatovegasofficial
____________________________________________________
Lyrics:
So
所以
Some say you can't get hurt by
有人曾說過 你不會被
What you don't know
你所不知道的東西傷害
That's when you and I hurt each other the most
傷人最深的反而是你我之間的感情
We bring the worst out of each other
我們迎來了最糟糕的情況
And I'm so tired waiting for destruction
我已經厭倦了暴風雨之前的冷戰
Every hour makes it harder
每一分每一秒都是如此難熬
We can't take this any further
我們不能再繼續這樣下去了
And I'm so tired waiting for destruction
我已經厭倦了暴風雨之前的冷戰
Yesterday
昨天
Ended it yesterday
昨天已然過去
So we could stay friends
我們仍然還是朋友
Til today
直到今天過後
Now we fucked up real great
我們之間結束的如此徹底
I don't want to do this no more
我不想再繼續這段感情了
Usually I never slam doors
通常我不會這麼乾脆離去
Nanana this can't wait
但我已不能再忍受了
Now we fucked up real great
我們結束的如此徹底
Wish we ended it yesterday
希望明天我們都能有個新的開始
So
所以
When life goes up and then down
生活總是伴隨著起起落落
Like you and I know
這一點你我早知道了
We had it so good in start but now we're just ghosts
一開始我們做得很好 現在我們卻搞砸了
Faded pictures and I’m just god damn tired being so nostalgic
這些褪色的照片讓我對往事感到厭倦
Every hour makes it harder
每一分每一秒都是如此難熬
We can't take this any further
我們不能再繼續這樣下去了
And I'm so tired waiting for destruction
我已經厭倦了暴風雨之前的冷戰
Yesterday
昨天
Ended it yesterday
昨天已然過去
So we could stay friends
我們仍然還是朋友
Til today
直到今天過後
Now we fucked up real great
我們之間結束的如此徹底
I don't want to do this no more
我不想再繼續這段感情了
Usually I never slam doors
通常我不會這麼乾脆離去
Nanana this can't wait
但我已不能再忍受了
Now we fucked up real great
我們結束的如此徹底
Wish we ended it yesterday
希望明天我們都能有個新的開始
Yesterday
往事已去
Yesterday
往事已去
Wish we ended it yesterday
希望明天我們都能有個新的開始
歌詞翻譯: Ginko
#Yesterday #VirginiaToVegas #Lyrics #西洋歌曲推薦 #英文歌

so damn good 在 AnDyWuMUSICLAND Youtube 的精選貼文
I've lost my mind... like a damn sociopath
#SOUR
__________________________________
FOLLOW ME:
▶ Instagram: @ADWmusicland https://instagram.com/adwmusicland/
▶ Facebook: @AnDyWuMUSICLAND https://facebook.com/AnDyWuMUSICLAND/
▶ Twitter: @AnDy_Wu_ https://twitter.com/AnDy_Wu_
/////////////////////////////////////////
▶ MY MERCH: https://teespring.com/stores/andywumusicland
▶ To get the exclusive DL link & the first info,
join this group on FB: https://bit.ly/2sikwQH
(Answer the questions so you can join the group)
/////////////////////////////////////////
I am AnDy Wu, addict to edit. I make Mashup, Remix & Megamix video when I'm inspired by every talented artist, and continue to create something inspiring.

so damn good 在 クレイユーキーズKureiYuki's Youtube 的最讚貼文
EKABO
Download & Streaming : https://big-up.style/6ryhl759QV
クレイユーキーズの9thシングル。クレイ勇輝、Kafu Sato、Martin(OAU)、杉本雄治(WEAVER)、
真船勝博が参加し、ボーカリストはファーストシングル以来再びDAZBEEを迎えた。
淡々と日々が過ぎて中、突然死んでしまう主人公と置いてかれてしまう彼女の話。
MV、ジャケットのアートワークはイラストレーター、アニメーション作家として活躍し、自主制作アニメーション「片道切符の夢」ではASIAGRAPH 2018年度 第2部門で最優秀賞を受賞したbanishment(@yokaibanish)が手がけた。
The 9th Release for the Kureiyuki's Band!!
"EKABO with DAZBEE"
This will be the second time we release a song together!
The story of a girl being left behind by her boyfriends sudden death?
As always, banishment has done all the artwork?
Follow クレイユーキーズ/KureiYuki's
https://twitter.com/kimakurei
https://www.instagram.com/kimaguren_kurei/?hl=ja/
https://open.spotify.com/playlist/6lhJ8y3bREsKv0hGjF1uGf?si=d03074ab50be42b4
Follow DAZBEE
https://www.youtube.com/user/Dazbeeee
https://twitter.com/nicodaZzz
作曲 Kafu Sato/クレイ勇輝
作詞 クレイ勇輝
編曲 クレイユーキーズ
Vocal:DAZBEE/クレイ勇輝
Chorus:Kafu Sato/杉本雄治(WEAVER)
Guitar:Kafu Sato
KeyBoard:杉本雄治(WEAVER)
Bass:真船勝博
Violin:Martin(OAU)
Programming:福島貴夫
Engineer:馬場毅
ArtWork:banishment(FLAT STUDIO)
『EKABO』
あれは確か よく晴れた日 風が強すぎて 家を出る時
勢い付けて 玄関の扉開けた 外に出ると 眩しすぎる日差しが
うん、いい日になりそうだ
こないだ彼女と喧嘩してさ 些細な事 どうでもいい事さって
そんな事言ってるから 怒られるんだろうね
駅までの道 ふと考える のらりくらり生きてきた
俺の人生きっと明日から変わるのさって 毎日言ってる
明日からきっとって
駅前の横断歩道 赤信号 隣に親子 母の手繋ぐ女の子
目が合う 手を振られる 微笑み返す 俺もいつか
携帯取り出して 彼女に連絡「こないだはごめん 今夜話そう」
見上げると 眩しい日差し 信号が変わって 歩き出す
振り返ると車の影 とっさに
夜空に浮かんで消えた あなたは勝手に星になった
悲しいはずなのに 泣けないのは まだ側にいる気がしてさ
When you feel like you can’t take anymore
When you lose all your fate HEY!
When you think it’s so FU**ED UP
When you can’t stand living another day
I FEEL THE SAME
When you can’t feel the love anymore
When you had just enough HEY!
When you think it’s SO DAMN WRONG
When you can’t stand living another day
I FEEL THE SAME
横断歩 人だかり それを見下ろす自分
何で見下ろしてるんだ?
あそこにいるのは俺 もしかして死んだ?
明日から変わるのさって言ってたばかりなのに
いくら何でもあっけなさすぎる
ってか彼女とも話せてないし
妹は結婚したばかり 親は?仕事は?全部中途半端
まだ何も始まってないのに 終わるのか?
そういえばとっさにかばった女の子 良かった無事か
一つぐらい胸を張れる事が出来てよかった
彼女にも一言謝りたかった くだらない事で喧嘩なんかしなきゃよかった
ずっと側にいるからねって 伝えたかった
もし最後に声が届くなら ごめんね どうか 幸せに
夜空を見上げたらいつでも あなたが見守ってくれてる
悲しいはずなのに そう思えば 大丈夫 歩いてゆける
When you feel like you can’t take anymore
When you lose all your fate HEY!
When you think it’s so FU**ED UP
When you can’t stand living another day
I FEEL THE SAME
When you can’t feel the love anymore
When you had just enough HEY!
When you think it’s SO DAMN WRONG
When you can’t stand living another day
I FEEL THE SAME
///////////////////////////////////////////////////////////////////////////
『EKABO』
One windy day, I put my weight on the door to leave
As I opened the door, the dazzling sunshine made me squint
Yeah, it's gonna be a good day
The other day I had a fight with my GF, not a big deal, she was just being picky
Well I guess she’s annoyed of me not taking it serious
Thoughts just bouncing around in my mind on the way to the station
Nothing big in my life, so ordinary, but my life will surely change from tomorrow
I'm sure from tomorrow
Crossroad in front of the station, Red light, a girl holding her mothers hand
eyes meet, she waves at me, I smile back, maybe someday I might become...
Take out my cell phone and text my GF "I'm sorry about the other day, lets talk tonight"
I look up to squint at the sunshine, lights change and I start to walk,
I Look back, shadow of a car heading for the little girl
You floated into the night sky and disappeared, leaving me behind you chose to become a star
I know I should be bursting out in to tears, but I still feel you right next to me
もう我慢できない時
もう何も信じられなくなった時
もう全て壊したくなった時
もう一日たりとも生きていたくないと思う日があるとして
安心して 一人じゃないから
もう愛に触れられなくなった時
もう大概にしろよと心で叫んだ時
全てが間違ってるはずなのに頷いた時
もう一日たりとも生きていたくないと思う日があるとして
安心して 一人じゃないから
Looking down at a cross road
Looking down? Is that me down there?
Sh*t, did I die?
I just was saying that my life is going to change from tomorrow
Did it end that easily?
I haven’t even talked to my GF yet,
My sister just got married and am I leaving behind my parents? How about my job?
Is it gonna end this easily, with nothing started yet?
Wait, what happened to the girl I tried to save, thank god she’s safe
I'm glad I have at least one thing to be proud about
I wanted to apologize to my Girlfriend about the fight we had
I wanted to tell you that I’ll always be there for you
If my voice will reach you for one last time
I want to tell you that I’m sorry and I wish for your happiness
When I look up in the night sky, I see you looking out for me
I know I should be bursting out in to tears, but I know you are still here with me
もう我慢できない時
もう何も信じられなくなった時
もう全て壊したくなった時
もう一日たりとも生きていたくないと思う日があるとして
安心して 一人じゃないから
もう愛に触れられなくなった時
もう大概にしろよと心で叫んだ時
全てが間違ってるはずなのに首を縦に振った時
もう一日たりとも生きていたくないと思う日があるとして
安心して 私が側にいるから
#クレイユーキーズ
#kureiyukis

so damn good 在 amal (aka wuvv) - so damn good - YouTube 的美食出口停車場

Stream on Spotify: https://open.spotify.com/track/4p01RCugPLqWGYpU14GSVk Come through for a chat on our Discord server: ... ... <看更多>
so damn good 在 So Damn Good - Sture Zetterberg feat. Sigrid ... - YouTube 的美食出口停車場

Track: So Damn GoodArtist: Sture Zetterberg feat. Sigrid Spangberg, Zakky ZMusic: http://www.epidemicsound.comBackground: https://www.pexels ... ... <看更多>
so damn good 在 Aleem - So Damn Good - (OFFICIAL VIDEO) - YouTube 的美食出口停車場
Buy/stream 'So Damn Good': https://www.fanlink.to/SoDamnGood© 2017 aMM Entertainment, LLCDirected by Steven Philip. ... <看更多>