📜 [專欄新文章] 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.
👏 歡迎轉載分享鼓掌
同時也有16部Youtube影片,追蹤數超過177萬的網紅Ru's Piano Ru味春捲,也在其Youtube影片中提到,Final Fantasy VII「Tifa's Theme」Ru's Piano Cover | Tifa Short Hair ver.❤️ 🤍Join RuRu's Membership to support me create music videos ➜ https://www.youtu...
「source of images」的推薦目錄:
- 關於source of images 在 Taipei Ethereum Meetup Facebook 的最佳貼文
- 關於source of images 在 Might Electronic 邁特電子 Facebook 的最佳解答
- 關於source of images 在 IELTS Fighter - Chiến binh IELTS Facebook 的最佳貼文
- 關於source of images 在 Ru's Piano Ru味春捲 Youtube 的最讚貼文
- 關於source of images 在 ウマヅラビデオ Youtube 的精選貼文
- 關於source of images 在 PoGoTips Youtube 的最讚貼文
source of images 在 Might Electronic 邁特電子 Facebook 的最佳解答
📢 Mighty Tech🚩
🔑 Using AI to predict patients with #Alzheimer's disease👥
Fujifilm Holdings Corporation uses AI to resolve brain images and genetic information of patients with mild cognitive impairment. Currently, it can predict the development of mild cognitive impairment from mild cognitive impairment to Alzheimer with a maximum accuracy of 85% 💪🏼
📌Source 👉 http://bit.ly/3kLepyV
--------------------
📢邁特新知🚩
🔑 運用 #AI 預測 #阿茲海默症 患者👥
日商富士軟片公司運用 #人工智慧,可解析輕度認知障礙患者的 #腦部圖像 及 #基因資訊,目前最高能以 85% 準確率預測從輕度認知障礙發展至阿茲海默症的患者💪🏼
📌更多資訊看這裡 👉 http://bit.ly/3kLepyV
source of images 在 IELTS Fighter - Chiến binh IELTS Facebook 的最佳貼文
- Luyện đọc đầu ngày: ALEXANDER HENDERSON (1831-1913)
Born in Scotland, Henderson emigrated to Canada in 1855 and became a well-known landscape photographer.
Alexander Henderson was born in Scotland in 1831 and was the son of a successful merchant. His grandfather, also called Alexander, had founded the family business, and later became the first chairman of the National Bank of Scotland. The family had extensive landholdings in Scotland. Besides its residence in Edinburgh, it owned Press Estate, 650 acres of farmland about 35 miles southeast of the city. The family often stayed at Press Castle, the large mansion on the northern edge of the property, and Alexander spent much of his childhood in the area, playing on the beach near Eyemouth or fishing in the streams nearby.
Even after he went to school at Murcheston Academy on the outskirts of Edinburgh, Henderson returned to Press at weekends. In 1849 he began a three-year apprenticeship to become an accountant. Although he never liked the prospect of a business career, he stayed with it to please his family. In October 1855, however, he emigrated to Canada with his wife Agnes Elder Robertson and they settled in Montreal.
Henderson learned photography in Montreal around the year 1857 and quickly took it up as a serious amateur. He became a personal friend and colleague of the Scottish-Canadian photographer William Notman. The two men made a photographic excursion to Niagara Falls in 1860 and they cooperated on experiments with magnesium flares as a source of artificial light in 1865. They belonged to the same societies and were among the founding members of the Art Association of Montreal. Henderson acted as chairman of the association's first meeting, which was held in Notman's studio on 11 January 1860.
In spite of their friendship, their styles of photography were quite different. While Notman's landscapes were noted for their bold realism, Henderson for the first 20 years of his career produced romantic images, showing the strong influence of the British landscape tradition. His artistic and technical progress was rapid and in 1865 he published his first major collection of landscape photographs. The publication had limited circulation (only seven copies have ever been found), and was called Canadian Views and Studies. The contents of each copy vary significantly and have proved a useful source for evaluating Henderson's early work.
In 1866, he gave up his business to open a photographic studio, advertising himself as a portrait and landscape photographer. From about 1870 he dropped portraiture to specialize in landscape photography and other views. His numerous photographs of city life revealed in street scenes, houses, and markets are alive with human activity, and although his favourite subject was landscape he usually composed his scenes around such human pursuits as farming the land, cutting ice on a river, or sailing down a woodland stream. There was sufficient demand for these types of scenes and others he took depicting the lumber trade, steamboats and waterfalls to enable him to make a living. There was little competing hobby or amateur photography before the late 1880s because of the time-consuming techniques involved and the weight of the equipment. People wanted to buy photographs as souvenirs of a trip or as gifts, and catering to this market, Henderson had stock photographs on display at his studio for mounting, framing, or inclusion in albums.
Henderson frequently exhibited his photographs in Montreal and abroad, in London, Edinburgh, Dublin, Paris, New York, and Philadelphia. He met with greater success in 1877 and 1878 in New York when he won first prizes in the exhibition held by E and HT Anthony and Company for landscapes using the Lambertype process. In 1878 his work won second prize at the world exhibition in Paris.
In the 1870s and 1880s Henderson travelled widely throughout Quebec and Ontario, in Canada, documenting the major cities of the two provinces and many of the villages in Quebec. He was especially fond of the wilderness and often travelled by canoe on the Blanche, du Lievre, and other noted eastern rivers. He went on several occasions to the Maritimes and in 1872 he sailed by yacht along the lower north shore of the St Lawrence River. That same year, while in the lower St Lawrence River region, he took some photographs of the construction of the Intercolonial Railway. This undertaking led in 1875 to a commission from the railway to record the principal structures along the almost-completed line connecting Montreal to Halifax. Commissions from other railways followed. In 1876 he photographed bridges on the Quebec, Montreal, Ottawa and Occidental Railway between Montreal and Ottawa. In 1885 he went west along the Canadian Pacific Railway (CPR) as far as Rogers Pass in British Columbia, where he took photographs of the mountains and the progress of construction.
In 1892 Henderson accepted a full-time position with the CPR as manager of a photographic department which he was to set up and administer. His duties included spending four months in the field each year. That summer he made his second trip west, photographing extensively along the railway line as far as Victoria. He continued in this post until 1897, when he retired completely from photography.
When Henderson died in 1913, his huge collection of glass negatives was stored in the basement of his house. Today collections of his work are held at the National Archives of Canada, Ottawa, and the McCord Museum of Canadian History, Montreal.
Extensive (adj): rộng
Outskirts (n): ngoại ô
Apprenticeship (n): thời gian học nghề
Excursion (n): chuyến du ngoạn
Artificial (adj): nhân tạo
Influence (n) /ˈɪnfluəns/ : sự ảnh hưởng
Artistic (adj) /ɑːˈtɪstɪk/ : đẹp
Rapid (adj) /ˈræpɪd/ : nhanh chóng
Significantly (adv) /sɪɡˈnɪfɪkəntli/ : đáng kể
Specialize in (v) /ˈspeʃəlaɪz//ɪn/ : chuyên
Numerous (adj)/ˈnjuːmərəs/ : nhiều
Sufficient (adj) /səˈfɪʃnt/ : đủ
Demand (n)/dɪˈmɑːnd/ : nhu cầu
Exhibition (n) /ˌeksɪˈbɪʃn/: triển lãm
Wilderness (n) /ˈwɪldənəs/ : vùng hoang vu
Commission (n) /kəˈmɪʃn/ : nhiệm vụ
Administer (v) /ədˈmɪnɪstə(r)/: điều hành
Huge (adj) /hjuːdʒ/ : to lớn
Các bạn cùng tham khảo bài đọc này nhé! Trích từ Cambridge IELTS14 - giải chi tiết, có ai chưa có bản này không?
source of images 在 Ru's Piano Ru味春捲 Youtube 的最讚貼文
Final Fantasy VII「Tifa's Theme」Ru's Piano Cover | Tifa Short Hair ver.❤️
🤍Join RuRu's Membership to support me create music videos
➜ https://www.youtube.com/c/RusPiano/join
🎼「Tifa's Theme」Sheet Music Link
▶https://gum.co/tQTcq
▶https://www.mymusicsheet.com/ruspiano/24029
Piano Arranged and Performed by RuRu
- FB Page: https://www.facebook.com/ruruspiano
- Instagram: https://www.instagram.com/ruruspiano
Images Source:
ST: https://twitter.com/strawderryst
Ria: https://twitter.com/ria_neearts
Please subscribe if you want to see more of my piano covers ♡٩(ˊᗜˋ*)و
🎹Ru's Piano Sheet Music Website
▶https://www.mymusicsheet.com/ruspiano
▶https://gumroad.com/ruspiano
🎹Get Piano Sheets and WAV Files for Each Month
▶Join Youtube Memberships: https://www.youtube.com/c/RusPiano/join
▶Patreon: https://www.patreon.com/rusmusic
🔊RuRu's 2nd Digital Album - Nostalgia Anime Songs -
▶Spotify: https://open.spotify.com/album/1taEUi76ze9xWVJ79L0Xnm
▶iTunes/Apple Music: https://music.apple.com/tw/album/nostalgia-rus-piano-collection-vol-2/1571184153
▶YouTube Music: https://music.youtube.com/playlist?list=OLAK5uy_nqH79knIm7AerIZfsCRj7JlUgUdS82BdM
🎹Learn Anime piano easily: https://go.flowkey.com/ruspiano
💘Support Ru's Piano💘
▶PayPal: https://paypal.me/ruruspringroll
▶歐付寶: https://bit.ly/donateRuRuSpringRoll
▶ECPay: https://p.ecpay.com.tw/ED8DB07
👗Ru's Piano Merchandise
▶https://go.fandora.co/nku65
🟩Ru's Piano LINE stickers
▶https://line.me/S/sticker/12306838ership to support me create music videos
➜ https://www.youtube.com/c/RusPiano/join
#FinalFantasyVII #Tifa'Theme #PianoCover #TifaThemePiano #TifaShortHair #FF7Piano #FF7R
#ファイナルファンタジーVII #ティファ主題歌 #ピアノ #ティファピアノ #FF7ピアノ
#最終幻想7 #蒂法主題曲 #鋼琴演奏 #蒂法短髮 #太空戰士7 #最終幻想鋼琴 #蒂法鋼琴 #FF7蒂法
source of images 在 ウマヅラビデオ Youtube 的精選貼文
世の中には少なからずカルト宗教団体が存在しそこへ入信する者もいる。入信した彼らは洗脳され人生も奪われる。何を信じるもその人次第だが1つ考える必要もあるだろう。
🔥メンバーシップ『Club99』へこちらから加入できます。真実を追い求める方へ🔥
https://www.youtube.com/channel/UCvral4FSI9dOOUV-yRloawA/join
🚨否メンディーの公式LINEスタンプが完成しました!🚨https://store.line.me/stickershop/product/13067419/ja
☆ちょっとでも面白いなと思ったらチャンネル登録よろしく☆
http://youtube.com/subscription_center?add_user=umaduravideo
_____________________________________________________________________
◆メンバーのTwitter!!繋がれちゃうからね?いいね?◆
☆ウマヅラ
https://twitter.com/umaduravideo_
☆ベーコン
https://twitter.com/amuse_bacon
☆否メンディー
https://twitter.com/inainainamen
_____________________________________________________________________
※我々が話すことはあくまで都市伝説であり、実際に起きてることとは限りません。真実は皆さんで追ってください。また誹謗中傷を目的としてこの動画は制作されておりません。また使用している素材はすべて引用であり著作権を侵害する目的でこの動画を制作しておりません。
素材の引用URL
A+E Networks カルト集団と過激な信仰
Former NXIVM member says she was branded when invited to secret sorority: Part 1
https://youtu.be/pqNNwFe6gMM
https://www.google.com/url?sa=i&url=https%3A%2F%2Fwww.bbc.com%2Fnews%2Fworld-us-canada-43550908&psig=AOvVaw3ehuXSucEtKZxCJWiduNSg&ust=1604782565645000&source=images&cd=vfe&ved=0CAMQjB1qFwoTCJjij4nn7uwCFQAAAAAdAAAAABAF
ロイター/PATRICK T. FALLON
Story Block Video
https://www.videoblocks.com/videos
(Free) Dark Sad Piano Hip Hop Instrumental - Part Of Me
https://youtu.be/41Znld4vGCY
♩♫ Royalty Free Music - "The Last Battle" - Epic & Dramatic Action Trailer Score | No Copyright ♫♩
https://youtu.be/qvR21sKXWmA
Fear(A No Copyright Horror Theme Piano Music
https://youtu.be/-V2O_CHazcw
Music Atelier Amacha
http://amachamusic.chagasi.com/music_kurakunagaitunnel.html
DOVA-SYNDROME
https://dova-s.jp/bgm/download11429.html
source of images 在 PoGoTips Youtube 的最讚貼文
SWIPE RIGHT FOR THIS EPISODE!
e-mail : PoGoTips28@gmail.com
Twitter : https://twitter.com/PogoTips28
Posted : 7 AM Local Time
Intro / Outro:
Pokemon Go Sound Effects Remix by Zach Smith
https://www.youtube.com/watch?v=NDheF85cYZ0
Vexento - Home
https://www.youtube.com/watch?v=ojiGKxIKrWw
Vexento - I Love Mondays
https://www.youtube.com/watch?v=L83ceYS2w3g
Sprite Source:
https://www.furretturret.com/resources/hd/regular
Pokémon is Copyright Gamefreak, Nintendo and The Pokémon Company 2001-2016
#PoGoTips #MewNews #Shiny
All images and names owned and trademarked by Nintendo, Niantic, The Pokémon Company, and Gamefreak are property of their respective owners.