📜 [專欄新文章] 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.
👏 歡迎轉載分享鼓掌
同時也有52部Youtube影片,追蹤數超過21萬的網紅Triptravelgang,也在其Youtube影片中提到,ชวนเที่ยวงาน NaSatta Light Festival 2021 ณ สัทธา อุทยานไทย จ.ราชบุรี สัมผัสความงดงามแห่งไฟประดับกว่าล้านดวง ด้วยเทคนิค Interactive Light Art, Projec...
「art mapping」的推薦目錄:
- 關於art mapping 在 Taipei Ethereum Meetup Facebook 的最讚貼文
- 關於art mapping 在 Sharmaine Kwan - Artist Facebook 的精選貼文
- 關於art mapping 在 IELTS Thanh Loan Facebook 的精選貼文
- 關於art mapping 在 Triptravelgang Youtube 的精選貼文
- 關於art mapping 在 Triptravelgang Youtube 的最讚貼文
- 關於art mapping 在 LUXY BOYZ Youtube 的最佳解答
- 關於art mapping 在 藝述誌Artmapping 的評價
- 關於art mapping 在 Art Map 藝術地圖 的評價
- 關於art mapping 在 Projection Mapping (highlights), School of Art - YouTube 的評價
- 關於art mapping 在 130 Best map art ideas 的評價
art mapping 在 Sharmaine Kwan - Artist Facebook 的精選貼文
Only 15 days left till the opening of Digital Art Fair Asia 2021! Stay tuned for more exciting fair highlights and program details to be announced soon! I will be showing some neon artworks, light installation and NFT!✨
------------------------------------------------------------
Digital Art Fair Asia Edition 2021 - Hong Kong is the first-ever physical Art Fair in Asia with a focus on immersive art, new media art and NFT Crypto Art, using cutting edge technology such as Virtual Reality, Blockchain and 3D Mapping. The first Digital Art Fair featuring some of the most exciting artwork by renowned international artists.
Visit our exhibition in Hong Kong this September 2021 or via your VR Google anywhere in the world. We look forward to seeing you at our 20,000 sq ft venue in Central, Hong Kong
30th September - 17th October 2021
59 Queen's Road, Central, Hong Kong
art mapping 在 IELTS Thanh Loan Facebook 的精選貼文
THỬ SỨC VỚI 1 ĐỀ SPEAKING PART 2 TRONG QUÝ 2/2021 (THÁNG 5-8)
Không có gì bất ngờ lắm khi một đề Speaking part 2 trong cuốn “Câu hỏi & Bài mẫu IELTS Speaking theo chủ đề” lại xuất hiện trong bộ đề dự đoán quý 2.
Mời các bạn cùng tham khảo nhé. Cô Loan sẽ sớm cập nhật list đề dự đoán quý 2 đầy đủ nhất cho mọi người.
------------------------------------
Describe a product or application which is based on artificial intelligence
You should say:
What it is
What it is used for
How it is used
And what you think of it
You know, artificial intelligence is gaining its popularity in modern life because of the convenience it brings to us. I desired to own at least one, so I had been tightening my belt to possess a household appliance that operates based on AI. This is a house-cleaning robot.
I bought this robot on the Internet and only 3 days later, it became one of my family members. In fact, I could say that it is the most hard-working member of my family, and also the cleanest. It never refuses to work when I activate and tell it to clean the house, and it’s also so diligent since it can focus on cleaning up to 4 hours without complaint, no matter how dirty my room could be.
It can remove pet hair, automatically navigate around obstacles like chairs or tables’ legs. If I want it to clean the house when I go out, all I have to do is to set up a mapping plan, a time limit and turn it on. I’m pretty sure that the floor will be bright and shiny when I come back. More intelligently, this robot can autonomously recharge its battery and come back to its home when it has finished work. I mean that its operation is totally automatic, without any control or monitoring of humans.
As for me, this is the state-of-the-art technological device that I could grasp the opportunity to buy. It’s really a labour - saving device. Thanks to this gadget, I never have to worry about tedious household chores like laundry or cleaning. Besides, I have more time to pursue other interests and be immersed in some real page-turners, so I still think it is a perfect purchase.
------------------------------------
gain popularity /ˌpɒp.jəˈlær.ə.ti/ (verb phrase): ngày càng phổ biến
tighten my belt /ˈtaɪ.tən/ /belt/ (idiom): thắt lưng buộc bụng
diligent /ˈdɪl.ɪ.dʒənt/ (adj): chăm chỉ
obstacle /ˈɒb.stə.kəl/ (noun): vật cản
autonomously /ɔːˈtɒn.ə.məsli/ (adv): tự động
state-of-the-art /ˌsteɪt.əv.ðiːˈɑːt/ (adj): tối tân
labour-saving /ˈleɪ.bəˌseɪ.vɪŋ/ (adj): tiết kiệm sức lao động
purchase /ˈpɜː.tʃəs/ (noun): sự mua sắm, đồ mua sắm
------------------------------------
Đọc thử: https://drive.google.com/file/d/1lH3pUZxyDRBdEzizvLjpXADt80K3Czim/view?usp=sharing
Đặt mua sách: https://ielts-thanhloan.com/san-pham/ebook-luyen-ielts-speaking
art mapping 在 Triptravelgang Youtube 的精選貼文
ชวนเที่ยวงาน NaSatta Light Festival 2021 ณ สัทธา อุทยานไทย จ.ราชบุรี
สัมผัสความงดงามแห่งไฟประดับกว่าล้านดวง ด้วยเทคนิค Interactive Light Art, Projector Mapping และ Interactive Display ที่จัดขึ้นเป็นปีที่ 3 ชวนสัมผัสลมหนาวและเฉลิมฉลองหยุดยาวพร้อมส่งท้ายปีเก่าต้อนรับปีใหม่ ปีฉลู
สำหรับผู้ที่ต้องการมาเที่ยวชมและสัมผัสความงดงามของแสงไฟในยามค่ำคืน ช่วงเทศกาลส่งท้ายปีเก่าต้อนรับปีใหม่ กับงาน NaSatta Light Festival ภายใน ณ สัทธา อุทยานไทย หมู่ 3 ถ.เพชรเกษม-ดำเนินสะดวก ต.วังเย็น อ.บางแพ จ.ราชบุรี สามารถมาเที่ยวได้ทั้งกลางวันและกลางคืน จัดกิจกรรมทุกวันเสาร์-อาทิตย์ และวันหยุดนักขัตฤกษ์ ระหว่างวันที่ 18 –20,24 – 27, 29 – 31 ธันวาคม 2563 และ วันที่ 1 – 2 มกราคม 2564 เข้าชม เวลา 18.00 - 22.00 น. และ พิเศษสำหรับคืนวันที่ 31 ธันวาคม 2563 เข้าชม เวลา 18.00 – 24.00 น.
ร่วมฉลองส่งท้ายปีเก่าต้อนรับปีใหม่
สอบถามที่ 032-383-333
art mapping 在 Triptravelgang Youtube 的最讚貼文
ชวนเที่ยวงาน NaSatta Light Festival 2021 ณ สัทธา อุทยานไทย จ.ราชบุรี
สัมผัสความงดงามแห่งไฟประดับกว่าล้านดวง ด้วยเทคนิค Interactive Light Art, Projector Mapping และ Interactive Display ที่จัดขึ้นเป็นปีที่ 3 ชวนสัมผัสลมหนาวและเฉลิมฉลองหยุดยาวพร้อมส่งท้ายปีเก่าต้อนรับปีใหม่ ปีฉลู
สำหรับผู้ที่ต้องการมาเที่ยวชมและสัมผัสความงดงามของแสงไฟในยามค่ำคืน ช่วงเทศกาลส่งท้ายปีเก่าต้อนรับปีใหม่ กับงาน NaSatta Light Festival ภายใน ณ สัทธา อุทยานไทย หมู่ 3 ถ.เพชรเกษม-ดำเนินสะดวก ต.วังเย็น อ.บางแพ จ.ราชบุรี สามารถมาเที่ยวได้ทั้งกลางวันและกลางคืน จัดกิจกรรมทุกวันเสาร์-อาทิตย์ และวันหยุดนักขัตฤกษ์ ระหว่างวันที่ 18 –20,24 – 27, 29 – 31 ธันวาคม 2563 และ วันที่ 1 – 2 มกราคม 2564 เข้าชม เวลา 18.00 - 22.00 น. และ พิเศษสำหรับคืนวันที่ 31 ธันวาคม 2563 เข้าชม เวลา 18.00 – 24.00 น.
ร่วมฉลองส่งท้ายปีเก่าต้อนรับปีใหม่
สอบถามที่ 032-383-333
art mapping 在 LUXY BOYZ Youtube 的最佳解答
#LuxyBoyz # #
BOOKING:luxyboyz@gmail.com
0930-359615 王健
FB:https://www.facebook.com/luxy.boyz
IG:https://www.instagram.com/luxyboyz/
Official web:https://www.luxyboyz.com
art mapping 在 Art Map 藝術地圖 的推薦與評價
Art Map 藝術地圖, Hong Kong. 20976 likes · 33 talking about this · 7 were here. A pioneering art media that endeavours to bring together art communities and ... ... <看更多>
art mapping 在 Projection Mapping (highlights), School of Art - YouTube 的推薦與評價
art created for the ANU School of Art building by Gabriela Vayas, a post graduate student in Media Arts ... Projection Mapping (highlights), ... ... <看更多>
art mapping 在 藝述誌Artmapping 的推薦與評價
想參加既朋友仔可以23/10(2:30-5:30pm)同我哋一齊到深水埗區做義工派物資,有興趣加入我哋Art Mapping 共享社區團隊,參與11月共學課堂,請DM @artmapping. cowork ... <看更多>