Building with Token Bound Accounts (ERC 6551) - Jayden Windle
ETHGlobal·Mon, Oct 9, 2023, 12:00 AM
Join Jayden Windle for a talk titled "Building with Token Bound Accounts (ERC 6551)". Welcome to back to ETHGlobal Waterloo, where it all began! Returning to Canada's tech hub, we're thrilled to bring together international enthusiasts and local talent for an unforgettable hackathon experience. This year we had 650+ attendees from 29 different countries and 47% were new to Web3! We concluded the weekend with 168 projects submitted and gave away $250,000+ in prizes ----------------- Follow us: https://twitter.com/ETHGlobal Check us out: https://ethglobal.com Email us at: hello@ethglobal.com
Transcript
foreign [Music] well thank you all for coming uh this is a talk on building with erc6551 it's going to be a little bit technically in depth it's going to do we're going to chat a little bit about what erc6551 is um what you can do with it and then we kind of get hands on into how you can use it in your hackathon projects this week um so yeah obligatory intros I'm Jaden I'm one of the developers at Future Primitive which is a web 3 Venture studio if you want to ping me this weekend for questions about erc6551 that's my Twitter DMS are open feel free to ask um would love to help support anyone who's building erc6551 related things uh yeah we're feature Primitives we build all sorts of crazy experiments with tokens so we do uh we've done a lot of experimental nft projects and erc6551 is a proposal that we proposed based on a lot of the work that we've been doing on trying to push the bounds of what can you do with nfts how can you give nfts abilities Beyond just being an asset that's stored in your account and let them do things um so we've been doing a lot of crazy experiments with that and erc6551 introduces A New Concept called a token bound account erc6551 gives every single nft that's ever existed or ever will exist its own won't your nft has its own unique wallet address and that means it can own other nfts they can own e they can own erc20s your nft can now own things natively because it has its own wallet address it also means that you can use your nft to interact with applications because your nft has a wallet your nft can now do anything on chain that a wallet can do so you could connect to openc and trade nfts as your nft your nft would own other nfts that it buys and sells and Trays on opency or you can trade in beam course you can you know vote on proposals anything you can imagine doing with a wallet your nfts can now do too and this works with everything like these addresses you can see on my screen are real token bound account addresses for real nfts and I'll show you that real quick so one thing if you want to start playing around with erc6551 that's really easy to do is if you want to see the tokenbound account address for an existing nft it's really easy so this is the Genesis crypto Kitty this launched at eath Waterloo six years ago was when cryptocurities launched as the one of the first nft projects so this is a really old NFC nobody's you know touched the nft contract in ages but this nft has a token bound account via erc6551 and an easy way to find that is to just replace openc with tokenbound.org for any nft uh any eight years to 721 nft and you'll find whoops I got a deal with viewport sizes or something oh here we go there we go um this is the nft's wallet address this is a unique wallet Associated only with this nft and this wallet can only be used by the owner of the Genesis crypto kit you can think of it like a token gated Nosa set wherever the nft goes ownership of the wallet goes to so you get this NF this nft owns this nft via a token about account and so for any nft you want to see the total amount of count up you can just replace openc with tokenbound.org and you'll find it um so yeah every nft from cryptic kitties onwards the project you launched this weekend it comes with a wallet that means you can make assumptions that nfts can own things that nfts can do things which is some really powerful things you can do in projects You're Building um and she's also have their own transaction history which is kind of cool you can see all the actions and nfts down on either scan so here's how it works so erc6551 um proposes a couple of new smart con it proposes the new smart contracts and a new account interface um inside the EIP so what you're seeing here it's kind of like it'll expand as we go through it but you're used to nfts existing on chain right so nfts exist as a smart contract there could be many nfts in one smart contract and usually there's a user that owns the energy right so this case we have a 721 contract called nftb and there's a token with id456 and so this user owns uh nftb number 456. we're used to that every everybody's kind of aware of and nfts are owned by wallets uh what to what erc6551 introduces is a new smart contract called the erc6551 registry and this registry is what gives every single nft its unique address you can query this registry with the token contract and token ID for any nft and get back a unique wallet address that will be owned by that mft the registry is a single entry point you can query for all of that data and it works with any nft the registry also deploys the smart contract at these addresses so these token bound accounts are really smart contractable ones that are owned by by the nft and that ownership by the nft owner is enforced at the Smart contract level so when you ask the registry for an account address for your nft it'll give you back an account address that you know will only ever be owned by that nft and so nfts can own multiple accounts so in this case you know token one two three on contract a owns two accounts token uh four five six on contract B owns one account and this account is managed by the holder of the nft so this user owns token 456 that means that they have full root execution permissions on the account but they can do whatever they want with it they can use it as a wallet they can do anything you can do with a wallet but if they ever sell this token everything in the wallet goes with the token so when you sell the nft all of the things you've collected in the wallet go with it because it's really the nft that owes the account and then the final piece of this is the implementation every account is really just a proxy to an accountable limitation that implements a very minimal interface and that you can find all that in the EIP but essentially the EIP provides a registry that everybody can query for account addresses or nfts and that it also provides a very minimal interface for implementations um so that's it it works on every evm chain wherever you're building as long as it's EDM compatible you can use it you can also permissionlessly deploy that registry to the canonical address um it fully decentralized like we don't own it it's in the IP you can go nuts deploying it and it works with every nft on every evm compatible chain and so you can now build applications assuming that nfcs can own things to do things from day Zero um there's been lots of people who have been helping us build this out this kind of originated as a project that we were building on but as we've started to speak with other folks it started to collaborate with other teams this is a list of a couple of the other companies that have been involved in helping refine the standard or building on the standard we've got a working group of like 700 developers who are building on ear 66551 if you want to join our questions it's available to you this weekend so um yeah what you've seen already there's a bunch of tooling that we've been building around here 6655 well that kind of core concept of nfts having wallets that's basically all you need to know to work with erc6551 you don't need to do anything special on your nft contracts you can launch the most normal vanilla off-the-shelf template nft and it will come with a wallet and so that's all you need to know all you need to know is your nfts come with wallets now and there's a few ways that you can interact with them one way you can interact with them is via the tokenbound Explorer so you saw this earlier when I went to tokenbound.org when I replaced openc URL you can see that on the tokenbound Explorer the address for any NFC so if I go back this tab here this is the cryptic Kitty I I don't happen to own this crypto Kitty but if I connect my wallet go to my nfts you can see a list of nfts that I own on chain and so for any of these nfts I can go in here and I can see the account contents of the NFC um this is an nft project that we released called sapiens uh which is one of the first collections to use this natively but what happens is this at sapiens nft owns these three nfts and these three nfts are actually clothing items that the nft can equip so you can see this background is an equippable item and this nft has that background equipped onto its artwork that's possible because this nft owns this background token but what's really cool is you can use this nft can own tokens that are from other collections too so this this nft is not part of the clothing collection that we released this is from a separate collection but you could also equip this nft as a piece of clothing onto your Sapient nft by giving nfts wallets we let nfts own any assets and you can build on top of this crazy composability layer like you can send any nft you want to into another nft another example here if I go and show you um this is someone who's sent a whole bunch of stuff into their sapiens nft you can see this nft owns a Suzuki and it owns a doodle and it owns a moon bird I know it's a crypto kit and this just works out of the box because the nft has its own address and can receive any asset um sorry I gotta fix a bug in the the renderer Apparently on this page but that's the erc651 Explorer you can go there you can connect your wallet you can think of it like like etherscan for tokenbound accounts for any nft you can find its wallet address you can see it here and that'll link you off to etherscan where you can see all the transactions it is done it'll also show you everything inside the wallets and if you own the nft you can transfer things out I click this I can transfer this nft to any other world I can use this like a wallet through the tokenband.
org interface um so that's one place you can go to start building on top of talk about accounts if you want to link out to this in your projects this is kind of like a good default place where people can play around with document accounts but this is a hackathon so we're going to want to build some cool interesting new custom stuff this weekend so we have a lot of tooling we've built to help you with doing that um the first and foremost is a token about SDK so if you go npm install at tokenbound SDK that's the GitHub repo tokenbalance SDK this is probably the easiest way to get started building front ends with prc6551 you're just an npm package away and you can query for the address for any existing nft you can deploy the smart contract at that address and you can interact with a smart contract at that address if you're the owner of the NIT so you can build all the experiences that you see on the tokenbot site you can build those into your dap and you can kind of build experiences on top of these wallets and use them as an additional wallet inside your dap um so I can actually show you real quick let's see is this big enough for people to see is this like can people kind of see what's going on here awesome um so this is just a normal this is what you get when you do uh wag me create app if Wagner is a great front-end development framework if you're bootstrapping a web3 app you can just run I think it's uh npm create web me and it'll spin you up this project this is basically a super basic project with the one exception that I've added the token bad SDK I've done npm install at tokenbound SDK and now it's installed so I just run this server real quick hello all right so I'm running the development server I should be able to spin it up locally and fingers crossed that the Wi-Fi works and it'll spin it up there we go this is what you get when you just create a new wagme project it has some some things out of the out of the box and you can see at the top we've added this tokenbound account page and so what you're seeing here is this is the address for the sapiens project the sapiens that I showed you and this is the token ID and this is the chain ID so every evm chain is a chain ID token bound accounts are tied to a chain ID and so with these three inputs this is the address I get back from the token bound SDK so in here in my reacts component it's pretty easy I just added in the token contract the token ID and the um and that's it it uses the chain ID of the provider I'm connected with and down here I instantiate a new tokenbound client passing it in the provider that I'm working with in the front end application if you're using VM it's really easy to grab that it's got a nice little hook if you're using ethers or something you can pass that in as well so I instantiate the token Mount client here and then it's one call away I call tokenbound.getaccount and this gives me back the token bound account address for this nft and you'll see this address here is the same address that you see in this little iframe here 0x uh 0x5416 is sapien's number zero and we're passing in sapiens number zero we get back the same token amount of count address so you can query that address really easily without having to know anything about how tokenbao works or how erc655 Works under the hood you can get that address information into your applications and then you can start using it there are other methods on the SDK we have a docs page at docs Dot tokenbound.org where you can see all the methods on the SDK you can deploy the account you can execute calls against the account it's all pretty much the same you pass in the provider from your front-end application and you can start executing against those accounts um so that's the SDK you've got it's a npm installed away you can start building 6551 related stuff into your front end without having to worry about any of the smart contracts work behind the scenes all that's taken care of for you you can just use the nfts that your application is already interacting with and interact with their wallets um so that's one way to build on top of the token mountains it's uh tokenbass SDK it up another thing we provide is a wallet implementation so in six five five one you can actually bring your own wallet implementation you don't need to use ours you don't need to use anyones it's fully decentralized you can build your own wallet for your nfts we provide one that's out of the box it's got some of the nice things you'll expect from a smart contract wallet like 1437 supports uh 1271 support so you can sign messages um some very uh some stuff around delegation and things like that so it's kind of a fully featured extensible wallet that you can build on top of and if you're using the SDK you already are using this out of the box if you're using the total about Explorer you're using this out of the box but this is a fully open source wallet implementation that you can start using if you want to hack on building a custom erc6551 account implementation if you want to add custom features to the wallets for your nfts you can Fork this and go nuts and build a custom implementation that's the read before token contracts um if you're using the SDK you don't have to worry about it but you can totally uh interact directly with this I'll show you another demo of this if I just switched to my contracts directory um I'm not sure how many of you are familiar with Forge but this is this is Foundry this is forged the smart contract development toolcast uh this is a script so this is a smart contract but I'm going to run it locally but you can use the same code inside of your smart contract accounts or inside of your smart contracts that you're building this weekend so getting the token amount account address for an nft is as simple as using this erc6551 accountlib from the ERC reference repo um and passing in pretty much the same data that you passed in in the SDK there's two extra parameters one is the registry address this is the canonical registry is deployed on every chain so this is the registry address the second is a wallet implementation address so this is using our wallet implementation against deployed across change you can feel free to use it if you're gonna do a custom implementation you would pass your own custom implementation address here and then the rest is the details about the nft so a chain ID of one because it's on mainnet the contract address of the nft and the token ID which is zero and then the final argument is assault and so by default this is zero you can use the account with a salt of zero but if you're used to using wallets within metamask where you have one seed phrase but you can have many wallets it's the same kind of thing you can have one implementation for a wallet but you can have many wallets for an nft using that implementation just change the value of salt so these are the default values these two for the registry and uh tokenbound account address and then zero for the salt and then the middle three are your token information the chain ID token contract and token ID and so if I run this all this is going to do is calculate the account address of the nft locally and log it out uh if I run this script using Forge it'll run this and then it gives me back the same address Xerox 5416 because we're calculating the address for my nft and the same kind of thing you can use the um You can call directly into the account contract from your smart contracts and use the X Cube fault call functions or the other functions on the total amount account so you can have Smart contracts that are aware of nfts that are aware of the nft's wallets and do really interesting things with them one cool thing about if you're doing this with either the SDK or the solidity library is you're not actually calling in to any contracts you're not making an RPC call when you calculate the address for an entity you're not making a contract call when you use solidity to calculate the address because addresses can be statically computed by the client you'd actually need to make that Network call it just happens locally which is kind of a cool benefit that you guess with six pack one um anyways that's the so there's a client SDK that you can use in your front end apps there's a solidity SDK you can pull it in from the erc6551 repo you can also fill in our wallet contracts and start building in your application um so let's talk about what uh one other thing we have is an iframe so you probably saw when I was playing around with the um with the sapiens nft there's this little thing in the bottom that shows you the contents of the wallet shows you the assets and other ones it shows you the wallet address um this is something we built for the sapiens project because it's really useful if you're going to be on open seat trading nfts to see the contents of the nft's wallet and to see its wallet address like I can comment here and I can copy and paste the wallet and then I can go over to whoops I can go over to etherscan I can paste it it's really nice to have this information accessible in open site this is all open source um so if you want to use this iframe in your projects it's really simple there is a repo here it's tokenbau slash iframe I believe if you chat with Ray afterwards there's also a URL that you can do it what you do is when you're creating an nft you can pass in a custom animation URL field in the metadata and that can point to a full website so if you pass it an animation URL and you use the token Mount iframe you'll get the artwork of your nft rendered but this nice little account overlay that shows you the contents of the account and the account address within the nft and so that's a nice little way you know in the interim before openc and all the other marketplaces support talk about accounts natively you can build in support for it at a visual level using the iframe um so that's at tokenbalance iframe on GitHub again we'll be here all weekend so come find us and we can we can walk you through using mass um yeah finally Doc's not talking about.org so this is where all the information you'll need to work with the compound accounts is the contract addresses for both the registry and for the implementations um some information on using the sdks the iframe um so anything you want to know about tokenbound accounts for using the token bound uh tools is it docs.talkabout.
org and if you're interested in the actual EIP spec itself you can look that up at eip6551 it should be on the yappu site and you can read through here this is kind of a really in-depth exactly how it works behind the scenes uh deep into some of the the theories of it and all of the ways that the smart contracts are structured um for building Lots output you don't necessarily need to know that but you can go there and see it if you think that's cool finally we've got some bounties we're giving out this weekend so um we're here we would love to see people building on top of erc6551 building on top of this concept that every nft comes with a wallet now uh and so we would love to see you all build crazy stuff with us we have some ideas for you if you don't have stuff planned yet um we've got some prizes for the best usage as best overall got the best nft use or NPC use case if you want to do some crazy stuff combining nfts with AI controllers that do actions on chain we think that's a really interesting use case if you're around a pragma yesterday you saw a demo of Benny talking with an nft via a web3 chat app and that nft actually executing Unchained actions to send him stuff if you want to do something similar in that day where you're giving nfts AI capabilities you can use like there's that's the NPC category we'd love to see you build us uh infrastructure we would love to see some things built on top of this to make it easier to build with talking about accounts so if you are building this weekend on top of your c6551 running into issues or you know just seeing things that you think shouldn't exist like indexers if you want to build wallet connect support if you want to build tooling for getting snapshots of a whole collections token Mount account addresses or even if you just want to submit a poll request to any of the open source tools that's the infrastructure category we would love to see all of you build on top of your system 551 and contribute to some of the stuff we're doing open source finally if you're a little bit less Technical and you don't want to do like some crazy uh solidity or front-end stuff uh that we've got a prize for the basketball chain media use case if you're you know creating art using 6551 what happens if you have composable nfts that change the artwork um or if you want to do like some interaction design or some visual design all right how do we represent this concept of nfts owning wallets and those wallets wanting assets uh doing some visual stuff around that this category for that so anyways that's the year 26551 every nft comes to the wallet now every nft that you launch this weekend in your projects will come with a wallet and you can feel free to use that so yeah thanks so much
Automatic transcript — names and jargon may be misspelled.