New Ethereum talks, every Monday. The week's conference uploads by event, in your inbox.

Loading player…

Songcamp 🛠 How A Headless Band Built The NFT Pack Mechanic - Matthew Chaim and Isaac Patka

ETHGlobalSun, Oct 9, 2022, 12:00 AM

Speaker

Isaac Patka

Join Matthew Chaim and Isaac Patka for a workshop titled, "How A Headless Band Built The NFT Pack Mechanic." Zora’s Metabolism hackathon is a virtual space for creative experimentation, bringing together some of the world’s best creators from a broad variety of categories and inviting them to design new digital spaces, on-chain tools, artistic experiments and more. Web3 is both one of the biggest paradigm shifts since the advent of the internet age and an ever-evolving inquiry into the societal possibilities of creative technology: no matter if you are a developer, an engineer, an architect, a musician, a theorist or seasoned NFT artist - we invite you to build hyperstructures with us with focus on NFTs, on-chain music ecosystems, a new generation of DAOs and Zora’s vast ecosystem of tools and smart contracts. Let’s build. Let’s create. Let’s imagine - together. From August 4 — 10th, 2022 we invite you to build the future creative on-chain ecosystem with the ZORA Protocol and ETHGlobal ---------------------------------------------------- Follow us: https://twitter.com/ETHGlobal​ Check us out: https://ethglobal.co​m Email us at: hello@ethglobal.com

Transcript

[Applause] [Music] hello good morning good afternoon good evening depending on where you are uh we have matthew from songkam and isaac from logos down doing their workshop on how a headless band built the nft pack mechanic workshop questions go into the zoom chat they'll be more than happy to answer them for you and with that being said i'll hand off the mic to our two speakers hi everyone um thanks for thanks for having us i'll give just a quick intro and then we'll jump into the to the topic at hand but um yeah my name is matthew musician i've been working on song camp uh for the last year and a half song camp we call it a web3 laboratory experimenting at the edges of music and the new internet and we're here to talk about one of the mechanics in the most recent experiment we ran called chaos um so yeah that's me and here's isaac hey i'm isaac i'm a developer primarily with logos down we got to know the song cam folks through just like kind of collaborating in various taos and then at eat denver last year we met up had coffee and decided to kind of build this build the contracts together so excited to kind of talk through those dynamics and show you how you can fork those and use those for similar dynamics for your own applications cool so i'll share my screen here making sure this is viewable by everyone um so yeah so chaos is our third uh kind of flagship experiment in songkam um our our experiments take the shape of kind of like a songwriting camp like a music collaboration experience kind of glued together with a web 3 hackathon we ran three camps our first one was called genesis about a year year and a half ago segment was called elektra and this one was called chaos chaos was a 77 person group including those musicians and and um engineers and then also visual artists operators uh lore builders storytellers podcasters a big group of 77 of us and and we're gonna walk through a bit i'll give like a quick overview of the project but we'll zoom in on um the the kind of like distribution mechanic which we're gonna talk about here called chaos packs um so yeah as i said there were 77 of us we consider everyone in this project uh an artist we were 77 artists and we all joined on march 8th of this year into the songkam discord to start our our camp camp chaos with the kind of hypothesis can we build a headless band called chaos where we are all building for this one kind of meta entity called called chaos um release music and art and and nfts through that brand and then also share in the value flow from that kind of big project as kind of uh one group moving together um so there's as you could hear from just the amount of people involved in the different sort of subgroups within that there's a lot in this project and there are definitely a lot of domains of it but we're going to zoom in on mainly like the music and visuals and how those came together and then how they were packaged within these packs so just to understand the songwriting camp side of it there were 45 musicians involved in this camp broken down into 15 15 bands um and here you can see how we kind of like broke that down into different houses kind of all these uh chaotic mechanics to run this very kind of uh almost like magical journey into a songwriting camp over six weeks so each house had four bands plus an alchemist band which is just a special kind of band making music a little bit differently but in the end five bands in each house with 15 bands and all those bands were essentially given the same task which was to create one song every two weeks um and we're gonna repeat that over a six week period so by the end everyone was part of three different bands uh part of three different songs and at the end of it we had what looks like this 45 songs um so every act which um included each of those two week periods people were collaborating on a song they collaborated over three acts we ended up with 45 songs these are these are the song titles um and then with all that music we were not just going to release them as one of ones but this time create a very large nft project that included that music in it so how that was done was on the visual end um there was a generative or a primitive uh way that the music that the cover artworks were created much like the pfp projects we're used to in the crypto punks style and these 45 songs were then um kind of printed in in multitudes of dynamic rarity amongst completely unique generative cover artwork for every single one of these uh 21 000 pieces um so that creates a big project of a lot of of uh of nfts a lot of um music and visual artwork um minted as nfts but instead of just minting those one by one and just like clicking mint and getting one song the idea came for us to and here's a little look at the visual aspect of this project the idea came to actually package these into songs of four so the idea was five thousand packs would be created four songs each um and then you would actually open these packs to get the uh four songs with completely unique cover artwork included so we kind of have like a bit of a visual of that here um this is where the actual uh sale is still going but yeah this is what the pack looks like and the idea there was to create you know this is so much artwork so much music how can we give everyone their almost like personal um uh ep or their personal experience of this with just four songs and will jurgens who is a long-standing member of our community actually had that first kind of light bulb moment of what if we actually package these into four and so chaos pax was born in each of them when opened four music nfts are revealed at random with their own unique cover artwork each of these four is a unique song of the 45 songs available so you get four songs per pack and you have the choice to either open your pack or keep it closed so this was the sort of idea of how we were packing packaging together this sort of chaotic art that was being created in this camp and that is when isaac came in to figure out how in the world we were actually going to do this so i'll pass to you isaac uh thanks um so the we initially uh we discussed a lot of different options for uh how to actually distribute these songs randomly uh into packs um yes if you go back to the previous uh visual and so like um after all 21 uh after all actually so it was split into two there's there's the 21 000 because a thousand were generated to go to the actual camp participants themselves and those actually had uh royalties attached to them from the rest of the collection but the 20 000 are the ones that came from pacs so those twenty thousand were randomly distributed between like token ids uh one thousand and twenty one thousand um and then they were um chopped up into like uh sets of four um and uh distributed into packs and then those packs were opened in random orders so it's kind of like multiple levels of shuffling um we discussed a bunch of different ways of potentially doing this randomness uh ranging from like uh having just you know different song uh different like token ids that would get generated um different uh like cases where like when you actually open the pack it would like kind of randomly decide based on uh based on like modular arithmetic like which song idea got but what we actually ended up with um was just like distributing all of the songs based on rarities uh along that kind of continuum of 20 000 songs and then chopping them up into pieces and then having the pack numbers randomly choose a different pack from that continuum and so there's once we decided on that mechanic there was actually a bunch of different ways to handle pack opening and we i simulated a bunch of the different ones uh to see which one would be more most gas efficient um so if you go to the next slide this is like a uh this is like a from excel just like a a graph of the different uh pack opening dynamics so the most naive implementation which i call guess and check was like uh choose a get a semi get a semi random number between you know one and five thousand um and if it has not been opened yet then that's the path you got and so like every single time that a pack was opened it might give you a number between one and five thousand and if it collided meaning like and then you would once it's open then you mark it as open and so um you in the beginning very small chance of collisions because like there's 5 000 uh different potential packs you open one uh if it has not been opened yet that's the pack you get then you do that for the next one and the next one and then if it detects a collision then it like increments up to the next pack so this was fine as you can see kind of between packs one and uh and like 4000 or something but like it starts getting more and more chaotic uh which is kind of funny like part of me actually kind of liked this dynamic because it was chaotic uh where um as you got closer and closer to the end it got more and more expensive to open the packs because there was a higher chance of getting a collision and having to like increment in a loop to find an unopened pack and so that's why that blue line is like the most naive implementation which is cheap in the beginning but gets like really expensive towards the end so i then uh was experimenting with different ones where um kind of split the 5 000 packs into a tree where you could check to see if a specific branch of the tree was filled and so that like made it was still like kind of a naive guess and check uh algorithm but it was made slightly um better just or not not necessarily better but more consistent due to the fact that like we could limit the amount of bad potential choices and so in the worst case you were going to have like uh 200 loops of a for loop rather than the worst case being 5 000 loops of a for loop so you can see that green that light green color was like twice as uh about like one and a half times more expensive in the beginning but then it was like pretty consistent um throughout um except that it was actually a bit more a bit more chaotic um so after i tried a couple of these methods we actually reached out to the zora team and wanted and to get some uh input on like potential ways to do this algorithm and one of the developers was like hey i actually wrote code that has done this already and so he shared this code with me which used this like select and this like um this permutation algorithm which would allow you to like select a an integer from a set um and then remove it from the set that so that you could never get a collision again and so that's that yellow line um this is like the zora the the zora algorithm um that we implemented to see how efficient that was but then he said that like he thought that there was actually an an even better way to do it which used a mapping instead of an array um and that was my that that dark green and so um those are like there's so this is just kind of interesting to see the different choices that you make with regards to like implementing these different algorithms have very different implications on gas we ultimately ended up going with that dark green line which kept gas for opening consistently around 140 000 uh which was pretty cheap like that's still like way cheaper than a normal like nft mint and in this case you're getting four nfds let's see what's the next graph oh the next uh another thing i did was just to make sure that there was no sort of like weird uh biases in the algorithm with regards to like when certain song certain uh certain packs were opened um this is just a blob of uh of uncorrelated stuff which is good and so what i was checking here is like as i opened pack numbers uh which pack did the which like a group of songs got assigned and since like there's no discernible pattern here um i thought okay this algorithm is pretty good um and there was no chance of like there was no information that somebody could uh obtain about like when they were gonna open their pack which songs they were gonna get yeah so the nice thing about all this is i'll share in a bit um this is all open source so um if you're curious about and you can even look through my git history and see all my like crappy initial implementations before like the final one that i like um so it's all on like the song camp github and i think towards the end of this i might have a chance to kind of walk you through and and find some of those uh yeah so if you go to contracts uh uh on this page batch shuffle um this is my fork of the logic that the zora team contributed so this allows you uh this is kind of a combination of that logic and some logic from adam fuller who did this like martian premier league nft project which was in turn based on i think tubby cats or something so there's the nft space is full of borrowed code so this is like a bunch of different um people contributing to create this like uh batch shuffling algorithm to make it so that you can have a different shuffled id from a discrete set um so in this case um use in the constructor you set the available account which in our case was 5000 um the batch size which was four and the start shuffle id which is just like you know zero or one depending on how you wanna do it um and then what you can do is use this inside of the pack opening logic contract to make sure that you're getting a random pack um along that continuum of pre-shuffled songs uh so if you go up a couple levels um you can [Music] in this level you can see chaos packs um and then chaos song so packs are the unopened nfts and then you can see in songs that's where the dynamic is of actually opening which burns the pack and then mints uh four songs and assigns this like shuffled offset uh and then if you go up one level to cam chaos um there's a full this is a hard hat development suite so if you go to test um you can see i have this end to end this the first file there that's probably the best place to look if you just want to see like how this stuff gets deployed um and then how it gets open so this is a full if you run this uh it'll probably take a few minutes to run because this actually goes through and opens like mints 5000 packs and then opens every single one um don't you don't generally need to do this you can make it smaller but this is like an a complete end-to-end script which will show you how the whole how all the dynamics work and then if you go up a couple levels to tasks um you can see there's uh this actually has a lot of really useful stuff around generating like dna and images um this is a fork of hash lifts but i added a bunch of nice utility functions like i separated the dna generation from the image from the image generation because like if you do that at the same time and you're trying to do like 10 000 things your computer will it'll take like seven hours for your computer to do this and in this case the generate dna script um will automatically like run in uh 30 seconds and so you can kind of do that first and then generate the images and also generate the json metadata i've just kind of split that out into different functions um in case you need to like mess with stuff and that way you don't have to like run a seven hour script every time you want to like generate your stuff so all of that stuff is in here you can also like ping me if you have if you're interested in understanding how to do it um i uh oh there's also some like residual vestigial code in here i was trying to parallelize the process generate images parallel and workers but the underlying library that hashtags uses called canvas is not uh compatible with parallel light parallelizing and so don't go down that rabbit hole i already tried it doesn't work um but you can see what it would look like if it did work and maybe canvas will someday update their library to work in parallel because right now it does not and it's really slow so there you go cool and maybe just uh i'm not mew today um just to put this all together and then we could maybe take some questions and this is this is the website um this is how you actually interact with it you have all the 45 songs we were talking about here uh listenable on the site um and with uh some you know uh example cover artwork and then the actual mint process is minting packs um and once you mint packs the packs enter your chaos inventory which i'm not connected right now am i signed in let's see i'm not signed in okay well can i sign in without you guys seeing what i do yeah no matter it might i don't know i can we can see you typing in your password but don't don't fish me anyone please just paste your seed phrase in the chats and we'll send you something okay here so uh so here you can actually see the beautiful artwork here um our work done by j gap designed by losing my ego front end built by daniel rudge kind and we have here like the ability to actually actually open your packs which yeah as as isaac was saying burns the pack and then mince those four songs and then you start filling your chaos inventory down here with the songs that you've minted and the cover artwork you've received from those so that yeah that kind of brings it all together um and that's what we wanted to share with you guys today nice any questions it looks like helios just said something in the chat yeah this would actually um generate this would pair really well with some kind of like loot uh loot crate kind of thing um actually think of loot like i think it'd be kind of fun if somebody pair this up with something in the loop ecosystem in general where you can just where you can like shuffle uh um you could like shuffle any sort of in-game things into this thing and the way that we shuffled the songs um and then you can give people packs uh to open them because like there's really there's actually no requirement for all the packs to be sold before people start opening so like you could create this uh you could create like a let's imagine that you're i don't know fortnite or something and you have like a season full of uh of like game uh of like in-game items you could create those allow people to buy them or even like drop packs on people periodically throughout a season and allow them to open it and get a random pack of four things and the only knowledge that people have is like what's already been claimed um but it doesn't there's no indication on like what uh what you're going to get next so i think that there's a there's a lot of potential to use these same dynamics and shot and algorithms in uh in general like kind of gain nfe game dynamics well if anyone else has any questions or anything you want to discuss definitely feel free to use the same chat or even come off mute yourself to say it live i could also ask a question um for isaac uh because i i'd be just interested if like you were to go and do this again would you do anything differently um and i guess one like maybe a second part of that question just one maybe like potential idea i think we've spoken about a little bit before of like uh including um like uh like a chain link random number generator something like that oh yeah so the rng part of this is like a very simple implementation um it's technically gameable uh because it uses like previous block cash and so if you were to use something like flashbots or if you were like had control of a miner you could wait to open a pack until you had an optimal previous block hash it's like hard to er it's like not technically hard to exploit it would take time to kind of like sit there and wait until you open the pack that you want um but this was like in my mind an acceptable complexity trade-off for this type of application previous block cache is good enough but there's a version of this that you could do using chain link vrf where you could uh when you you would click you would do open pack um and when you opened a pack it would it would request a true random number from uh from chanen's oracle and then when that answer was uh available because chain like oracle's in this case act as kind of like a question and answer you would have to hit open pack which asks the question hey chain link which pack am i gonna get and then their node replies and that's when your pack would be revealed and in that case it is completely not gameable um so uh something that i might experiment with maybe i don't know if chain link is uh sponsoring but they they're i think if somebody wanted to like fork this and add the chain link brf that would be a really cool project other than that i'm trying to think if there's anything else that i would change about the contracts um everything came together pretty smoothly uh it actually uses erc721a and that's why opening a pack is so cheap it's because like when you open a pack you're getting four consecutive songs from that from that distribution and so it's only charging you for one mint but the contract marks you as getting four consecutive things so then if you want to transfer one then it like then it identifies like uh who uh that you own like which ones you own in the middle of that chunk of four um but it uses erc721a to make it so that pac opening costs 150 000 gas not like 600 000 gas awesome um i guess if that's it for questions um we can end the workshop here today um thank you so much matt and isaac for taking the time to do a workshop for metabolism i'm super excited to see like what the hackers learn from this and what they're going to be building for their projects and to you hackers thank you so much for tuning into the workshop we do have a couple more workshops today so hope to see all of your faces there as well um and other than that i hope everyone has a great rest of your day thanks everyone thanks see you soon

Automatic transcript — names and jargon may be misspelled.