ERC-6551 is a new Ethereum standard that allows NFTs to have their own token-bound accounts (smart contract wallets), enabling them to hold and manage assets like ERC-20 tokens and other NFTs. The implementation involves two key components: a permissionless registry that computes and deploys token-bound account addresses, and an account interface that defines how these accounts can receive assets, execute calls, and interact with their bound NFT. The registry uses a deterministic address computation based on the NFT contract address, implementation address, chain ID, token ID, and salt, ensuring each NFT can have a unique, predictable account address.
ERC-6551 Tutorial: Deploy Tokenbound Smart Contract Accounts
Added:foreign it's Kelly here Dev evangelist at pinata today I'm here to present to you another awesome technical walkthrough in the next 15 to 20 minutes we're going to cover the ins and outs of a new nft standard that it's going to shake up the industry before we get into it if you haven't subscribed to the pinata Channel please do so we post awesome content on more than ipfs we actually talk about AI we talk about different nft standards and other blockchain Concepts in our CEO Kyle also gives some great insights on the industry as a whole so please if you haven't already go ahead and smash that subscribe button alright let's get this party started so today we are talking about [Music] erc6551 a new standard for token bound accounts a couple of weeks ago I posted a written overview of the standard things like what it is what it's useful for a rough summary of how it might work and what I see for its future since then there have been multiple hackathons where hackers have been building some pretty cool projects with it so in this tutorial to keep things super simple we're gonna Deep dive into the technical implementation this is personally something that I had to study for a long time up till now I have just been playing around with simple you know ERC is 721 1155 nfts so understanding how ERC is 6551 augments the world of nfts was a great mental challenge so in this video my goal is to really simplify the technical implementation so that you know how parts are meant to move and just exactly where they fit into the picture okay so in a nutshell ERC 6551s allow nfts to have their own token bound account that is they allow them to have their own smart contract wallet what does this mean this means that nfts can hold assets whether it's you know ERC 720 ones 11 55 or even erc20 tokens they can send other wallets assets as well so they can essentially act like you know the owner of a wallet just as you and I have browser wallets or Hardware routes and we can do whatever you want with the assets inside ERC 6551 allows nfts to have that same I guess layer of identity so I'm sure by now there's already a gazillion ideas floating around in your mind as to what exactly happens when you give nfts this power you know nfts that have been such a core part of I guess some people's identities since the last boom this diagram that we're looking at right here I pulled this from the official erc6551 EIP proposal and this is a layout of how you know all the moving Parts work so we're going to focus on two parts here so for the purposes of really breaking down the underlying Tech we're going to focus on two things as you can see we have our EIP 721 contracts we also have the registry so we we're going to focus on the registry and also the implementation accounts okay so firstly is the permissionless registry what do I mean by a permissionless registry so I am currently on the official page for the ethereum Improvement proposals and if we scroll down here that's the diagram I pulled from we're going to go down to the registry it is the single entry point so this is where uh all token bound accounts when they're being deployed they come to the registry first it has two functions the first is the create account the other is the account function so what is the difference between these two accounts well for starters let's go with the similarities they both need an implementation address the only difference is that the create account is the actual function that deploys the TBA whereas account is a read-only function that simply computes it so you can't really create an account without Computing the token Mount account first but this actually deploys it whereas this just generates the address with the implementation address passed in if we go down to the registry interface you can see the very basic interface that they have provided for us and by they I mean the um Future Primitive team who are the founders of this standard all right now moving on to the account interface so all token brand accounts should be created by the registry and then all token Mountain implementations must Implement ERC 165 interface detection and the ERC 1271 signature validation and they also must implement the following interface so this interface is the account interface so to put this into perspective you remember how I said we were going to focus on two things the first was the registry interface now the registry is what creates the tokenbound account as in it generates the address and then deploys it now the account interface is I guess the instruction manual for how this tokenbound account should behave there are a couple of functions that you should understand the first is this receive function this means that you're allowed to receive for example erc20s or ERC 721 tokens now that is crucial in order for your tokenbound account to be alive and these second is the execute call function this means that you can send assets from your TBA and then this function here function which is called token it Returns the identify of the ERC 71721 token to which this account is bound to and then lastly is the function owner this basically Returns the owner of the account which is the owner of the ERC 721 token of which this TBA is bound to it's possible that you're extremely confused right now because there was a lot there but don't worry once I get into but do not fret I was like that for a few days and once I get into actually showing you how all these parts move together and interact you're going to be in very good hands okay so starting with tooling what tools do we need in order to successfully complete this tutorial well we don't need much I realize that the easiest way to kind of show how tbas work is to do it all from one place you know you don't have to import in test net funds or anything so I'm going to be using remix which is um an ethereum specialized ID and we'll be pulling in different contracts from open Zeppelin but they're actually already in there so uh the first thing you'll have to do is just go to uh remix and I think that URL is something like remix Dot ethereum.org and create an account if you don't already have it you'll be probably landing on this page it looks something like this you've got a file explorer and then the main home page what you're going to do is you're going to go over to clone and then what you're going to do is go over to this GitHub repo grab the https URL from the Repro that I will link in the description I already have everything set up for you so that you don't have to copy and paste or do anything to get started and you're going to clone it into your remix IDE editor and then it should all be good to go okay once that's loaded this is what you should see so you should see my readme use the folder called contracts this is mainly where we'll be working you'll also see a folder called scripts you won't have to worry too much about that and you won't have to worry too much about tests either so we're going to concentrate on the contracts folder inside the root of the contracts folder I have the contract for the erc6551 account and the registry whoops I'll also have a simple contract for an ERC 721 called my nft I have a folder called interfaces and this is where I put both of the interfaces like copy and pasted from the official EIP proposal page and then inside lib I have a few other bits and Bobs that you'll need in order for everything to compile and work smoothly so let's get into it so the first thing we're going to do is we're going to go to nft Sol all right let's get started and just before I started the screen share again what I did was I changed my compiler to 0.8.19 otherwise I think there will be some issues that you'll run into so I highly recommend doing that first uh what we're going to do is we're going to go into the my nft.sol contract and this is a very basic uh implementation of an ERC 721 token it is the Constructor is my nft um and it just basically creates an erc721 okay we're gonna go ahead and compile and we're going to go ahead and let's just make sure everything's right okay make sure that you're on the contract here and we're going to deploy this contract all right so now that that contract is deployed we're going to go ahead and mint a couple of nfts so we're going to go and save mint so from this current address this is where we deployed this contract from we're gonna just select a random address you can safe mint this address let's put it as token id1 and transact cool so now this address here has one nft from this contract and if we go ahead and just select the next one copy that address go back to our original address and we're going to save mint another token cool token id2 I'm going to transact another one awesome and so if you see let's just check the owner of token id1 it should be that first address that we minted the nft to well ab84 okay cool and then token id2 787 okay I guess I selected that one that's all good I just need to remember that next up we're going to go ahead and deploy the registry contract remember this is the place that deploys the TBA and creates the contract address so we're going to go and compile that deploy make sure you're in the right contracts cool so that's deployed at this address gonna go back into the account contract compile and then we're going to deploy this all right so we should have three deployed contracts we should have the account registry and also the ERC 721 nft that we just um minted to two different addresses all right so now that we have all three contracts deployed uh the first one we're going to play around with is this one right here which is the registry uh contract so remember how I said that this is the single point of entry when it comes to creating a tokenbound account what we're going to do is we're going to compute a token Mount account address and then we're going to deploy it with the create account function so what we're going to do that with is this address right here so let's just copy that nft address let us go and oh just paste that nft token in and for the implementation address we're going to use this account implementation that we just deployed so go ahead and copy and paste that here chain ID one token ID we're also going to put as one so we're playing with the first nft that we minted and then for salts we're just going to put zero cool and then call that if you see here I'm just gonna expand this the decoded output was this address so this is the address that will be um of our token about account so if you go back and we deploy we actually create the account so remember that this simply computes the account address whereas the create account function actually deploys it so we're going to go salts and let's just put an empty array in here gonna pop in transact so let's double check this account it should be the same as what was computed before okay now that we have this implementation address computed I'm just going to go and copy that you're going to make sure you're in your account contract and instead of deploying from here we're going to add the contract from address so what we're going to do right now is we're going to compute our actual smart contract address for this nft contract right here so what you can do is you can just click add address and you should have created another contract right here I'm going to go ahead and delete these so you should just be left with these two contracts now how can you verify that this account here belongs to this nft with the token id1 well what you can do is you can go to the owner and it should be the owner of the nft that we minted with the token id1 right here so let's see the owner when we call the owner function on this new account we have 0xab8 and if we just check here the account that we admit to the first nft2 is this one here 0xab8 and similarly if you go to let's go token id2 sorry one it should be the same cool so now we can surmise that the owner of token id1 in this nft contract is also the person who controls this tokenbound account the smart contract account all right so let's go ahead and add some Shmoney to this so we're going to go and make sure we're we're here make sure we're on the contract address and we're going to go ahead and maybe put in 10 East on this account here we're going to try to execute a call which is send some Shmoney to another address so let's send it to let's send it to this one the one that has token id2 I'm going to copy that go back to the account address that owns this smart contract account and we're going to put in continue 2015 60 17 18.
sweet and let's just put in an empty array and we can transact that should be successful so now we have nineef now if we switch and just pick like a random account maybe let's pick this one cool and we try that again it should not work and there we have it we have successfully created a token Mount account for the owner of the nft with the token ID one from this nft erc721 contract they now have the power to send receive assets to the smart contract and yeah there we go I hope that was useful in figuring out just exactly how talking about account works and what you can do with them
Up Next

Implementing ERC-6551 Token Bound Accounts | Smart Contract Tutorial
@net2dev
670 views•2024-02-02

Torrent File Format & Bencoding: A Technical Deep Dive
@AsliEngineering
12.5K views•2022-08-08

Operational Security Essentials: A Guide for Hacktivists (OPSEC)
@hitbsecconf
157.4K views•2012-11-26

Understanding Ethereum: A Comprehensive Beginner's Overview
@99Bitcoins
3.1M views•2018-06-26
Related Study Plans & Knowledge Roadmaps
Structured learning paths in Blockchain & Crypto
















![Intro to Blockchain Programing [FULL COURSE 2023]](https://i.ytimg.com/vi_webp/cGQHXmCS94M/maxresdefault.webp)


















