📜 [專欄新文章] 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.
👏 歡迎轉載分享鼓掌
同時也有277部Youtube影片,追蹤數超過60萬的網紅Tasty Japan,也在其Youtube影片中提到,見て楽しい、食べておいしいちらし寿司。 材料や飾り方次第で、いろんなスケボーがつくれちゃいます! お子さんと一緒に作っても楽しめますよ◎ いっぱい食べて、難しい技もメイク!! ぜひ作ってみてくださいね♪ スケボーちらし寿司 1人分 材料: ごはん 250g A酢 大さじ2 A砂糖 小さじ2 A塩...
「hand fan」的推薦目錄:
- 關於hand fan 在 Taipei Ethereum Meetup Facebook 的精選貼文
- 關於hand fan 在 Facebook 的最佳貼文
- 關於hand fan 在 Facebook 的最讚貼文
- 關於hand fan 在 Tasty Japan Youtube 的最佳解答
- 關於hand fan 在 Feng E Youtube 的最佳解答
- 關於hand fan 在 R!N /Gemie Youtube 的精選貼文
- 關於hand fan 在 Paper Plate Hand Fans - The Pinterested Parent 的評價
- 關於hand fan 在 PICZ - Filter017 x Mark&Draw 3 Way Portable Hand Fan -... 的評價
hand fan 在 Facebook 的最佳貼文
感謝大家熱烈支持,這週六的《鋼琴72變》開幕音樂會已完售!🙏
★ 12 位臺灣頂尖國際大獎鋼琴家X破天荒首度同台
★ 6架鋼琴共演X挑戰聽覺視覺極致感動!
★ 一場史無前例!最最瘋狂的音樂節開幕派對!
⠀⠀
⠀⠀
🎹 2021 TIMF《鋼琴72變》開幕音樂會
Piano Transformers: The Opening Concert
⠀⠀
👉 演出時間|09 / 25 (Sat.) 19:30
👉 演出地點|臺南文化中心演藝廳
👉 票價資訊|300、500、800、1,000、2,000
👉 節目資訊|https://reurl.cc/EZ8Wl0
👉 立即購票|bit.ly/破天荒鋼琴瘋狂派對
⠀⠀
⠀⠀
🎹 演出者 Performer (s)
12 位臺灣頂尖鋼琴家 / 鋼琴家 #沈妤霖、#張欽全、#黎國媛、#嚴俊傑、#范姜毅、#黃瑞蘭、#葉孟儒、#廖培鈞、#盧易之、#鍾曉青、#NikolaiSaratovsky、#林冠廷
⠀⠀
The 12 Virtuoso Pianists / Eva Yulin Shen、 Chin-Chuan Chang、Constance Lee、Chun-Chieh Yen、Yi Fan-Chiang、Yi-Chih Lu、Grace Chung、Jui-Lan Huang、Nikolai Saratovsky、Pei-Chun Liao、Andrei Yeh、Kuan-Ting Lin
⠀⠀
⠀⠀
🎹 曲目 Program
⠀⠀
・史克里亞賓 《寫給左手演奏的夜曲》 作品9 第二首
A. Scriabin: Nocturne for the left hand Op. 9 No. 2
・法佐‧赛依 《 給鋼琴獨奏的帕格尼尼爵士》
Fazıl Say 《Paganini Jazz》
・浦朗克《給四手聯彈的奏鳴曲 I. 前奏 II.鄉村 III. 終曲》
F. Poulenc:Sonata for piano four hands
・拉赫曼尼諾夫《給六手聯彈的圓舞曲與浪漫曲》
S. Rachmaninoff:Valse & Romance for six hands
・皮亞佐拉《自由的探戈》
A. Piazzolla: Libertango
・玫瑰人生
La Vie En Rose
・喬普林《散拍狂想曲》
S. Joplin《Rag Rhapsody》
・羅西尼《賽維爾理髮師幻想曲》
G. Rossini 《Barber of Seville Fantasie》
・聖桑《骷髏之舞》
C. Saint-Saëns 《Danse Macabre》
・杜卡斯《魔法師的學徒》
P. Dukas 《The Sorcerer's Apprentice》
・法雅《火之祭舞》
M. de Falla 《Ritual Fire Dance》
・羅西尼《威廉泰爾》序曲最終章《瑞士士兵進行曲》
G. Rossini 《Wilhelm Tell》
・林姆斯基‧高沙可夫《大黃蜂的飛行》
N. Rimsky-Korsakov《The Flight Of The Bumblebee》
・拉維涅克《加羅普進行曲》
A. Lavignac《Galop-marché》
hand fan 在 Facebook 的最讚貼文
感謝大家熱烈支持,這週六的《鋼琴72變》開幕音樂會已完售!🙏
★ 12 位臺灣頂尖國際大獎鋼琴家X破天荒首度同台
★ 6架鋼琴共演X挑戰聽覺視覺極致感動!
★ 一場史無前例!最最瘋狂的音樂節開幕派對!
⠀⠀
⠀⠀
🎹 2021 TIMF《鋼琴72變》開幕音樂會
Piano Transformers: The Opening Concert
⠀⠀
👉 演出時間|09 / 25 (Sat.) 19:30
👉 演出地點|臺南文化中心演藝廳
👉 票價資訊|300、500、800、1,000、2,000
👉 節目資訊|https://reurl.cc/EZ8Wl0
👉 立即購票|bit.ly/破天荒鋼琴瘋狂派對
⠀⠀
⠀⠀
🎹 演出者 Performer (s)
12 位臺灣頂尖鋼琴家 / 鋼琴家 #沈妤霖、#張欽全、#黎國媛、#嚴俊傑、#范姜毅、#黃瑞蘭、#葉孟儒、#廖培鈞、#盧易之、#鍾曉青、#NikolaiSaratovsky、#林冠廷
⠀⠀
The 12 Virtuoso Pianists / Eva Yulin Shen、 Chin-Chuan Chang、Constance Lee、Chun-Chieh Yen、Yi Fan-Chiang、Yi-Chih Lu、Grace Chung、Jui-Lan Huang、Nikolai Saratovsky、Pei-Chun Liao、Andrei Yeh、Kuan-Ting Lin
⠀⠀
⠀⠀
🎹 曲目 Program
⠀⠀
・史克里亞賓 《寫給左手演奏的夜曲》 作品9 第二首
A. Scriabin: Nocturne for the left hand Op. 9 No. 2
・法佐‧赛依 《 給鋼琴獨奏的帕格尼尼爵士》
Fazıl Say 《Paganini Jazz》
・浦朗克《給四手聯彈的奏鳴曲 I. 前奏 II.鄉村 III. 終曲》
F. Poulenc:Sonata for piano four hands
・拉赫曼尼諾夫《給六手聯彈的圓舞曲與浪漫曲》
S. Rachmaninoff:Valse & Romance for six hands
・皮亞佐拉《自由的探戈》
A. Piazzolla: Libertango
・玫瑰人生
La Vie En Rose
・喬普林《散拍狂想曲》
S. Joplin《Rag Rhapsody》
・羅西尼《賽維爾理髮師幻想曲》
G. Rossini 《Barber of Seville Fantasie》
・聖桑《骷髏之舞》
C. Saint-Saëns 《Danse Macabre》
・杜卡斯《魔法師的學徒》
P. Dukas 《The Sorcerer's Apprentice》
・法雅《火之祭舞》
M. de Falla 《Ritual Fire Dance》
・羅西尼《威廉泰爾》序曲最終章《瑞士士兵進行曲》
G. Rossini 《Wilhelm Tell》
・林姆斯基‧高沙可夫《大黃蜂的飛行》
N. Rimsky-Korsakov《The Flight Of The Bumblebee》
・拉維涅克《加羅普進行曲》
A. Lavignac《Galop-marché》
hand fan 在 Tasty Japan Youtube 的最佳解答
見て楽しい、食べておいしいちらし寿司。
材料や飾り方次第で、いろんなスケボーがつくれちゃいます!
お子さんと一緒に作っても楽しめますよ◎
いっぱい食べて、難しい技もメイク!!
ぜひ作ってみてくださいね♪
スケボーちらし寿司
1人分
材料:
ごはん 250g
A酢 大さじ2
A砂糖 小さじ2
A塩 小さじ½
白ごま 適量
卵 1/2個
塩 適量
サラダ油 小さじ1/2
しめ鯖 適量
ガリ 適量
とびこ 適量
鯛 適量
ちくわ(2センチ角) 2本
きゅうり(5ミリ細切り) 1/2本
紅しょうが 適量
金箔 適量
作り方:
1.ボウルにAを入れ、砂糖が溶けるまでよく混ぜ合わせる。
2.ごはんに(1)をしゃもじに伝わせながら回し入れ、全体をしゃもじで切るように混ぜ、ごまを入れて混ぜる。
3.うちわであおいで水気を飛ばし、冷ます。
4.フライパンにサラダ油をひき、溶き卵に塩を加え、フライパンに流し入れる。卵の表面が固まってきたら、フライパンに蓋をして火を消し、1分置く。
5.(4)を千切りにする。
6.酢飯を弁当箱に敷き詰める。
7.(5)、がり、とびっこ、鯛、しめさばをのせる。
8.紅しょうがでYUTOの文字を作ってのせる。
9.ちくわにきゅうりを通して飾る。
10.金箔を散らしたら、完成!
===
Skateboarding with Chirashi Sushi
Servings: 1
INGREDIENTS
250g steamed rice
A
2 tablespoons vinegar
2 teaspoons sugar
1/2 teaspoon salt
Some white sesame seeds
1/2 egg
Some salt
1/2 teaspoon vegetable oil
Some vinegared mackerel (shimesaba)
Some ginger pickles (gari)
Some tobiko
Some red snapper
2 sticks chikuwa fish cake (diced)
1/2 cucumber (cut into 5mm pieces)
Some red ginger pickles (benishoga)
Some edible gold leaf flakes
PREPARATION
1. Mix all A ingredients in a bowl. Stir until sugar is dissolved.
2. Pour (1) over the rice. Stir with a rice scooper (shamoji).
3. Using a hand fan, cool the rice.
4. Put sushi rice (3) in a bento box.
5. Place egg threads (kinshitamago), ginger pickles, tobiko, red snapper sashimi, and vinegared mackerel on the rice.
6. Write “YUTO” with red ginger pickles on top.
7. Decorate with chikuwa and cucumber pieces.
8. Sprinkle with edible gold leaf flakes on top.
9. Enjoy!
#TastyJapan
#レシピ
MUSIC
Licensed via Audio Network
hand fan 在 Feng E Youtube 的最佳解答
Covered by Feng E
Tuning: normal
Feng E’s tabs: https://www.musicnotes.com/sheet-music/artist/feng-e
Guitar: @ENYA MUSIC T05
https://www.enya-music.com
Amprefier: @Blackstar Amplification Studio 10 6L6
Mic: @sE Electronics RNR1
Amp simulator: @walrusaudioeffects ACS1 DARTFORD mode
Fuzz: Purple Haze Studio hand made fuzz face
If you want to support me to continue my music journey, this is it!
PayPal: mahua7714@gmail.com
Patreon: https://www.patreon.com/fenge
bitcoincash:
qqfvs2ssqrh0564jhaqz6rq0amuf5hcge5hctw6408
bitcion: 3G73ErqdZtyis1KuLRVdX2Dr8xzFg3sCsT
Thank you for your supporting.
Feng E’s first album:
💿CD-
誠品書店 https://reurl.cc/mdM17j
博客來 https://reurl.cc/1QvRzY
五大唱片 各門市
🎧online
applemusic https://apple.co/2q2Xtf9
Spotify https://spoti.fi/2Pw2tns
KKBOX https://kkbox.fm/Na49rk
MyMysic https://www.mymusic.net.tw/ux/w/album/show/1183827
friDay http://bit.ly/31Z8MSV
Feng E’s fan page
https://www.facebook.com/FengEOfficial
Feng E"s Instagram
https://instagram.com/fengeofficial?r=nametag
hand fan 在 R!N /Gemie Youtube 的精選貼文
【REVIVAL PROJECT】第2弾リリース楽曲
「Simple Love」
作詞 R!N(Gemie)
作曲 ライブP
世界中に愛が届きますように。
歌詞:
Simple love
[A]
When I’m feeling down and blue
You took my hand
it's simple love
No words need to say
[B]
I climb many mountains for a higher place
rain or shine, I don't look back
[C]
Now I know
A brand new step is now on my feet
I freely fly away
Whenever you are near
I’m not afraid 'cause your simple love
is here and never fades away...
2A
大切なものを守りたい
it's simple love, それだけなのに
傷つけては run and run and run away
帰りたい my sweet home,Let it go
Now I know
A brand new world is what I see
I freely fly away
Whenever you are near
I’m not afraid 'cause your simple love
is here and never fades away...
強がりでも伝えたい
from the bottom of my heart
感謝してるよ ありがとう
私が私でいること
[D]
It's hard to see each other now
but we should move on
someday we will find, the days we used to be
on this world
挫けそうなときなほど思い出して
Anywhere, Everywhere go
必ずそこにある Simple love
【ライブP】
Twitter:https://twitter.com/mrlive2
ニコニコ動画:https://www.nicovideo.jp/mylist/12089241
YouTube:https://www.youtube.com/channel/UCCo-eAtYUNAfHSjdtyMr6Ww
【R!N(Gemie)】
Fan Club:https://rin-music.fanpla.jp/NEW!★
Twitter:https://twitter.com/rin_gemie
Blog:https://ameblo.jp/risa8masato
GOODSHOP①:https://store.skiyaki.net/rinshop
GOODSHOP②:https://rinstoresbt.stores.jp/
HP:https://rin-gemie.amebaownd.com/ (お問い合わせもこちらから)
hand fan 在 Paper Plate Hand Fans - The Pinterested Parent 的推薦與評價
Painted Paper Plate Hand Fans. Great for Chinese Lunar New Year or Vietnamese Tet. *This post contains affiliate links*. I have been talking to ... ... <看更多>