📜 [專欄新文章] 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.
👏 歡迎轉載分享鼓掌
同時也有9部Youtube影片,追蹤數超過86萬的網紅Joseph Prince,也在其Youtube影片中提到,Over the past month, we’ve received numerous videos from all across the world as so many of you shared your moments of partaking of the Lord’s Supper ...
「the chosen ones」的推薦目錄:
- 關於the chosen ones 在 Taipei Ethereum Meetup Facebook 的最讚貼文
- 關於the chosen ones 在 Milton Goh Blog and Sermon Notes Facebook 的最佳解答
- 關於the chosen ones 在 Milton Goh Blog and Sermon Notes Facebook 的最佳貼文
- 關於the chosen ones 在 Joseph Prince Youtube 的精選貼文
- 關於the chosen ones 在 JUUN D Youtube 的最佳解答
- 關於the chosen ones 在 themblan Youtube 的最讚貼文
- 關於the chosen ones 在 The Chosen One - Home | Facebook 的評價
- 關於the chosen ones 在 THE CHOSEN ONES-PTT/DCARD討論與高評價商品 - 飛比價格 的評價
- 關於the chosen ones 在 THE CHOSEN ONES-PTT/DCARD討論與高評價商品 - 飛比價格 的評價
the chosen ones 在 Milton Goh Blog and Sermon Notes Facebook 的最佳解答
See a Mighty Jesus
“In the year that king Uzziah died, I saw the Lord sitting on a throne, high and lifted up; and his train filled the temple. Above him stood the seraphim. Each one had six wings. With two he covered his face. With two he covered his feet. With two he flew. One called to another, and said, “Holy, holy, holy, is Yahweh of Armies! The whole earth is full of his glory!” The foundations of the thresholds shook at the voice of him who called, and the house was filled with smoke.” (Isaiah 6:1-4 WEB)
Picture this majestic vision. The mortal king of Israel had just died, and the Lord Christ revealed Himself, seated on His throne of glory which was high and lifted up, and the train of His robes filled the whole temple. The longer the train, the more honorable the king is—it was a picture of the supreme ruler. The King of kings and Lord of lords!
No mortal king rules forever, so regardless of who rules in Israel, Christ is the ultimate king who is watching over the nation, protecting it from all her enemies.
We can benefit from seeing Jesus in His love and Grace, and also from seeing Him in His power and authority. However, the former is more important to be established in first because without having a sense of being loved by Him, you will be afraid of Him due to the latter.
Behold Jesus in His power. Can any enemy stand against a God like that? He is Yahweh of Armies, who commands the seraphim, the cherubim, the four living creatures, the chariots of fire, and all the heavenly armies. The natural elements of this world like the wind and waves obey His word, and nothing can resist His command.
When we magnify the Lord in our hearts, we won’t fear the enemies because the greatness of our God overshadows the problems we face in life.
What does the passage mean when it says that “the house was filled with smoke”? This smoke is the smoke from the altar of incense, which is a picture of the prayers being offered up by the nation of Israel. The people were crying out for God to help them, and that is why the temple was filled with smoke—the many prayers of the people.
“The Lord said, “Listen to what the unrighteous judge says. Won’t God avenge his chosen ones, who are crying out to him day and night, and yet he exercises patience with them? I tell you that he will avenge them quickly. Nevertheless, when the Son of Man comes, will he find faith on the earth?”” (Luke 18:6-8 WEB)
God is being patient, not wishing that any should perish, but that all should come to repentance in Christ Jesus. There is a day of vengeance coming, which is the period of time called the Tribulation and the Day of Christ, and it will be horrible for the inhabitants of this earth who have not received Jesus Christ as Lord. We won’t be going through the Tribulation, but we will be returning to earth with Jesus on the Day of Christ (popularly known as the Second Coming).
Our Lord is not coming back as a meek Lamb, but as the mighty Lion of the tribe of Judah.
“I saw the heaven opened, and behold, a white horse, and he who sat on it is called Faithful and True. In righteousness he judges and makes war. His eyes are a flame of fire, and on his head are many crowns. He has names written and a name written which no one knows but he himself. He is clothed in a garment sprinkled with blood. His name is called “The Word of God.” The armies which are in heaven followed him on white horses, clothed in white, pure, fine linen. Out of his mouth proceeds a sharp, double-edged sword, that with it he should strike the nations. He will rule them with an iron rod. He treads the wine press of the fierceness of the wrath of God, the Almighty. He has on his garment and on his thigh a name written, “KING OF KINGS, AND Lord OF LORDS.”” (Revelation 19:11-16 WEB)
We have to change the picture of the ascended Jesus we have in our minds. He is no longer the bleeding and suffering man of sorrows who was so injured that He fell from the weigh of the cross that He was carrying.
He is now high and lifted up, back on His throne of glory, with all the heavenly armies at His command. In fairy tales, there is often a handsome prince on a white horse that whisks the damsel in distress away to a happy ending where they ride away together into the sunset. Where did humans get this picture from?
“He has made everything beautiful in its time. He has also set eternity in their hearts, yet so that man can’t find out the work that God has done from the beginning even to the end.” (Ecclesiastes 3:11 WEB)
God has set eternity into the hearts of men. Jesus is the prince who will save Israel from her oppressors. When you think of Jesus today, see a mighty King who commands the heavenly armies to fight your battles for you. He does this because He loves you!
My vision drawings was one of the Bible Study series shared for GEM patrons on Patreon. Join our Patreon community to receive fresh rhema words from the Holy Spirit to help you in every season of life: http://patreon.com/miltongohblog
the chosen ones 在 Milton Goh Blog and Sermon Notes Facebook 的最佳貼文
The tweet is a rhema word from God for me, and perhaps also for you. 🙏
Whatever is causing you stress, remember that God is bigger than your problems and He is more than able to help you.
He is a good, generous, and gracious God. He is love.
“What then shall we say about these things? If God is for us, who can be against us? He who didn’t spare his own Son, but delivered him up for us all, how would he not also with him freely give us all things? Who could bring a charge against God’s chosen ones? It is God who justifies. Who is he who condemns? It is Christ who died, yes rather, who was raised from the dead, who is at the right hand of God, who also makes intercession for us. Who shall separate us from the love of Christ? Could oppression, or anguish, or persecution, or famine, or nakedness, or peril, or sword? Even as it is written, “For your sake we are killed all day long. We were accounted as sheep for the slaughter.” No, in all these things, we are more than conquerors through him who loved us. For I am persuaded that neither death, nor life, nor angels, nor principalities, nor things present, nor things to come, nor powers, nor height, nor depth, nor any other created thing, will be able to separate us from God’s love, which is in Christ Jesus our Lord.” (Romans 8:31-39 WEB)
Don’t measure God’s love based on your circumstances.
His love is demonstrated at the cross, when He delivered up His beloved Son to suffer and die, so that our sins would be fully atoned for by the shedding of Jesus’ sinless divine blood.
God is not condemning or punishing you. He is the one who justified you, intercedes for you, and freely gives you all things.
“But to him who doesn’t work, but believes in him who justifies the ungodly, his faith is accounted for righteousness.” (Romans 4:5 WEB)
If Abba God placed our sins upon Jesus before we even repented or truly cared about Him, then we can be confident that nothing can separate us from His love, especially now that we have been justified through faith.
“Yahweh appeared of old to me, saying, “Yes, I have loved you with an everlasting love. Therefore I have drawn you with loving kindness.” (Jeremiah 31:3 WEB)
No created thing—including yourself, can stop God from loving you with an everlasting love!
If you have suffered any losses or endured any hardship, you can receive abundant restoration from God. Discover His plan to prosper you in all things through restoration, in “All Things Made New”: https://bit.ly/prosper-through-restoration
the chosen ones 在 Joseph Prince Youtube 的精選貼文
Over the past month, we’ve received numerous videos from all across the world as so many of you shared your moments of partaking of the Lord’s Supper together with your loved ones. A huge thank-you to ??? ?????? ?????? ??? ???? ????? ???????????, ?? ????????? ??? ??????????? ?? ???? ?????! ❤️ We’ve loved seeing so many of you having your own holy moment with the Lord in your homes.
We believe that Jesus instituted such a simple way of receiving from Him through the holy Communion, and we would love for you to partake of the holy Communion together with Pastor Prince and our global family wherever you are, as we believe and agree together with you for the breakthroughs you are believing the Lord for.
Are you ready to partake together? ?
–
The Communion | Decibel Worship
Follow Decibel Worship: https://bit.ly/35fVBid
Find chord charts, lyrics, and more at: http://bit.ly/decibelworship
Available everywhere:
Apple Music - https://apple.co/2QGHq0f
Spotify - https://spoti.fi/2tOlDw0
Google Play - http://bit.ly/35DvP7H
Amazon - https://amzn.to/2R42WMt
Connect with Decibel Worship:
https://facebook.com/decibelworship
https://instagram.com/decibelworship
https://twitter.com/decibelworship
// Lyrics
Verse 1
Your blood, shed for me
My hope, eternity
Your grace, shown to me
Gives me life, and now I see
Chorus
Your broken body is my healing
Your sinless blood gives my redemption
Your chosen suffering brings perfect life to me
Lord Your sacrifice has made me whole
Through the cross I am forever Yours
Verse 2
Your love, poured on me
With the oil of Your spirit
The anointing, breaking fear
I’m alive, I am free
Bridge
This is a holy moment with You
I open my heart to all You wanna do
I still my soul to remember the cross
Where You took all my shame and restored all I lost
Where you took all my shame and restored all I lost
The Communion (CCLI #7147341)
Words and Music by Michael Davis
(copyright icon) 2020 Decibel Worship
CCLI License #11169105
![post-title](https://i.ytimg.com/vi/VpE0vIUgVPA/hqdefault.jpg)
the chosen ones 在 JUUN D Youtube 的最佳解答
Music video by JUUN Đăng Dũng performing "A Better Place".
The song “A Better Place” is inspired by the heartfelt stories happening around the world.
Everyone has someone they love, but in this battle, there are lots of doctors, nurses, officials, or volunteers who have to sacrifice their own being and happiness for what matters to the whole society. Instead of staying at home with their beloveds, they’ve chosen to stay on duty and fight for us all.
On behalf of the health heroes, officials, and volunteers around the world, I would like to send the words of love to their loved ones. I believe that wherever we are, we can always be connected by music.
► Stream Audio on Spotify & Apple Music ??https://lnk.to/ABetterPlace
► Vietnamese Version: https://youtu.be/xzAONySfw3s
Special thanks to Josef Lee (IG @joseflee.stories)
Executive Producer: Linh Vo
Creative Director: JUUN D
Production House: Starberry
Composer: Bao Kun, Cheng, Juun D, Michael T. Legend
Arranger - Recording Stusio & Master: VNBEATS
Illustration Artist: Josef Lee
Motion Artist: Nguyen Phan
Graphic Designer: Tram Bach
#JuunDangDung #ABetterPlace #NguocChieuNoiNho
-------------------------------------------------------
©2020 starberry Vietnam. All rights reserved.
https://starberry.vn
-------------------------------------------------------
Vì lý do bản quyền, nếu các creators có các video reaction lyric video này xin hãy gửi email về địa chỉ contact@starberry.vn để được xử lý nhanh chóng. Cảm ơn các bạn
Due to copyright restrictions, if creators want to create a reaction video, please share the video link to email contact@starberry.vn for whitelist. Thank you.
-------------------------------------------------------
FOLLOW JUUN D:
► Facebook: https://www.facebook.com/juun.dd
► Instagram: https://www.instagram.com/juund.juund/
► TikTok: https://www.tiktok.com/@juund.juund
► Twitter: https://twitter.com/JUUNDofficial
![post-title](https://i.ytimg.com/vi/QwmYignktIk/hqdefault.jpg)
the chosen ones 在 themblan Youtube 的最讚貼文
On the last episode of "Playing Zelda with Japanese Voices," I went to Kakariko Village and Hateno Village, with unexpected adventures along the way.
Now, the story continues...
----------------------------
Thank you for watching, and have a great day.
----------------------------
Subscribe for more awesome videos! ► https://bit.ly/2M1H2Fy
----------------------------
The song in my intro and outro was done by Hyper Potions, and it is called Time Trials. You can check out the full song here: https://youtu.be/mnfNWe-HHsI.
----------------------------
The font I used in my thumbnail is Hylian Serif, and is from https://zeldauniverse.net/media/fonts/. It was created by Artsy Omni (http://artsyomni.com/hyliaserif).
----------------------------
I have purposefully chosen to use generic titles and thumbnails out of respect for people who have not played the game yet. I kind of want to use more clickbaity ones, but oh well.
![post-title](https://i.ytimg.com/vi/pphAylS9S6M/hqdefault.jpg)
the chosen ones 在 THE CHOSEN ONES-PTT/DCARD討論與高評價商品 - 飛比價格 的推薦與評價
THE CHOSEN ONES 在PTT/DCARD討論網購與高評價商品,提供DVD THE CHOSEN ONE優惠價格,找THE CHOSEN ONES相關商品就來飛比. ... <看更多>
the chosen ones 在 THE CHOSEN ONES-PTT/DCARD討論與高評價商品 - 飛比價格 的推薦與評價
THE CHOSEN ONES 在PTT/DCARD討論網購與高評價商品,提供DVD THE CHOSEN ONE優惠價格,找THE CHOSEN ONES相關商品就來飛比. ... <看更多>
the chosen ones 在 The Chosen One - Home | Facebook 的推薦與評價
THE CHOSEN ONE 先相信才有機會,本以短片形式發佈,感謝大家參與活動!!! ... .本月歡慶1111購物節,即日起凡購買NOV 2021 Riot of Colours Logo Sticker加碼抽「PS5 三 ... ... <看更多>