Boxes: Unlimited On-Chain Storage Q&A

Recorded: Nov. 22, 2022 Duration: 0:34:27

Player

Snippets

All right, hey, hey, Algo fam. Welcome to another episode of the Algorand No Forks Given Post Show. We just wrapped up with Andrew and Anne on the Algorand proof estate show where they walked through boxes, box stores,
for Algarand smart contracts and they're going to join me up here on stage and we're going to turn it over to you the Algalfam and the Algadevs to ask them some questions whatever you want to ask about developing with with boxes or
or just developing in the general storing state within your smart contract and understanding how box storage expands your ability to store unbounded amounts of data within your smart contract. So we are going to be bringing them
up here right now. Let's see here. I am still waiting. I saw somebody request. We do want to get you up here. So put your hand in the air. We will request and request and we'll get you brought up here to ask some questions. But I am waiting for
And Andrew to join in here. Yes, I'm getting it. Sorry one sec. They're coming. They're coming. Don't worry. Hope the agafam are all doing well out there. I know we are just a week away in fact from the start of decipher. I hope you guys are following the
at Decifer event Twitter handle. Decifer is our annual conference. This year we are hosting it in Dubai. It starts actually from Monday afternoon next week from 28th through the 30th.
you can get yourself a ticket or join us in person or stream it live by going to decipher event.com if and because you are a viewer here or listener or participant here in the No Fork given post show I've got discount code for you if you can join us in person
that is going to be decipher fam 22 join us in person. Alright, still looking for an and Andrew to come into the space. So really, all right, Andrew thinks he's in here. Which one of these is you?
you. Hit the request button and make sure that we get you up here. I see some builders, I see some algodabs in the audience. Again, if you have questions about box storage, hit the request button. We'll bring you up to the stage and we'll let you ask
questions. So do that now. You can even ask me I can fill in as Andrew and Anne get themselves connected here. Oh, I see some requests coming. Here we go. We've got Anne coming. Good. Tick that box. They're excellent. Here she comes.
All right, very good. Yeah, I see builders out there. I'd really be interested to hear if you guys got questions. This is your opportunity. And Kenyan, senior technical product manager at Algorand, welcome to the NoForksGiven Posture.
Thank you Ryan. All right great. We are trying to get Andrew to come up and join you. I think I see him now. All right, here he comes. Here he comes. Yes, he is coming. Oh, all right. And we've also got, we've got the AP going to come up and ask some questions. All right.
Set the table for us, right? Box storage at a high level. What is it? Why would I want to use it as an algorithm? Well, it's the most flexible storage mechanism that we have on chain for your smart contracts.
If you're familiar with global and local storage, those are great, but now you can have an unlimited amount of storage. You can create and delete boxes as you need them. So it's a lot more dynamic as well. All right. Well, let's head right over to
AP the angry penguin is up here on stage. Do you have a question for Anne and how you may use back storage? Yeah, thank you. Thank you and like we are planning to like improve upon whatever we have built now. It's a notification protocol like communication protocol on algorithm. So we need
that mapping facility like as you mentioned maybe and in your YouTube like that's feeling that you have just finished. So we are taking it like into another level where like we need we will be starting maybe with a 32 kb box which will allow
maybe to store 32 notifications kind of a thing for a person notifications kind of a thing for an end user. And if you want to like increase the size like so what we will do is that these notifications will be stored in the boxes created by the smart contract.
yeah and like and what we are planning is maybe like there will be 32 like KD space and so once 32 is finished then we will refill it. So the last message will be removed and
and then your one will come up. That's the plan we have. My question I will come to my question. I'm talking about this thing so that you can understand what we are building. We have a plan maybe to increase it. So then you want to
is opting into more channels, then like we have a plant in Greece it is 64 and more or so what is the limit that we can go up to? So is it scalable? Maybe we have to think about algorithm becoming maybe top 10 or at that time the number of channels will be higher. So I am thinking in that direction.
Okay, so let me repeat what I understood. So you're building some kind of notifications platform and you're storing like an individual user all their notifications in a box for them. So you're creating a 32 kilobyte box.
and storing all their notifications and they're filling it up as the notifications appear. Am I correct so far? Yes. So yeah, you're correct. Okay. And you are thinking about scalability. What do we do once they have more than 32k?
it's worth of notifications then we have to create another box. Is that right? No, no, no, no. The thing is that we will be giving that 30, we will be refilling it so that 30 will be 6. So once a 33rd one will come the first one will be removed and that will be the like yeah, but what we will do is
that a future plan is like see there will be some people who will be opting into more channels that means they may get more than 30 to notifications in a day or in a time frame. So for them there is an option to increase it another 30 to can be added. So like that the scalability is what
we are thinking about. So that's my question. I think you got it. I see. So and are people can subscribe to an unlimited number of channels potentially? Right? That's what you'd like. Yes, yes. Yeah. Yeah. And one more thing is there. Yeah. And one more thing actually.
When the end user opts into a channel, there will be a box for the channel where we will be adding the list of people who have opted in. So you can pull that list and then see like, yeah, which are the addresses that are optally and then maybe send a bulk notifications kind of a thing like maybe, yeah.
So for that also like maybe we have checked 32kd can only have maybe around 1000 addresses. So like once maybe more than that is coming there should be an automatic maintenance number. One more box will be added and then like that continues, the process continues. So that is also like we are thinking.
I see, I think. So you're saying you might actually have one box per channel, like with all the notifications for that channel, and then another box for that channel that just says who
who is subscribed to that channel. Yes. Yeah. Okay. Okay. That's, I mean, this is a great interesting case to talk through.
Absolutely, and let me interject and welcome Andrew Choy to the stage. Andrew, I'm glad you got yourself connected. Welcome. I'm not sure how much of this conversation you heard from AP as he was describing his use case, but I think Anne kind of said it succinctly. Did you catch it and do you have anything to add here?
Yeah, I think I caught the last part for you not the whole thing. Yeah, maybe, and then maybe start and I can interject. Yeah, so I think I've got the situation AP can you repeat again? What is the challenge that you're having?
So, in our notification like protocol what we are building, so we need like there will be a box, there will be a channel, a channel will be like the entity which will be sending notifications to the end user. So, what we are doing
planning to have is a box which will be of 32 kb for the end user and once 32 notifications are filled up that will be basic thing and once the 32 notifications are filled up we will be like when 33rd one will come up, first one will be removed and then we will add the
But in the future like there will be an option for the end user to increase it this 32k bit to 64 and maybe to 128 etc depending upon to like how many channels he subscribe here she subscribe to yeah and there is yeah and on the other side
from the channel side, channel has to store the list of addresses which has opted into the channel, so that uses addresses. So that will also in the long term may come to 10,000, 20,000, so maybe in a
it will be what we have calculated is we can only store around 1000 addresses. So that will also be scaling. So this is the thing that we are having our mind. So yeah, I hope you understood my problem. I think so. What's interesting is like you're using
use case doesn't require, you could do some, you could theoretically store things in a lot of boxes and you don't need to necessarily access all the information for the users in one app call, because it's a
It's not a time, it's not like the user is going to take some action on chain based on the notifications, right? The user will read their notifications on their computer. So you know, it doesn't matter if you have maybe your
the notifications in multiple app calls. So I think what I think what I'm trying to say is you could store all the information on chain, but then you can also use the indexer or whatever to look up all
the boxes that are storing the user information and then maybe make several app calls to fetch them. Does that make sense for your use case? >> Yeah. But the problem is that everything will be done
So, that is why we wanted it to be fully on chain, we do not have any other, what we are planning to build is we will not have any other server, so something like that. So, in our UI we will be using the same SDK that anybody else can use.
If a decentralized application wants to maybe integrate the notification system into their application, they can use the same as DQ that we are using and become free as creative as possible. >> Yeah. Yeah.
I think that that is still possible you might have to do something complicated, you know, like store, like if right if you really want to store like a huge amount of data for a single like that you want to, you know, for a single
call you might need to like store in one box, all the other boxes that are then that you'll then need to use, right? If that makes sense. I know some people have been talking about trying to do that kind of thing.
And we change the boxes maybe like what we do for pagination kind of a thing. And yeah, yeah. Yeah, yeah. Yeah, I think, you know, what I said, I agree. I think on chain data is also extremely expensive. So I agree that you either want to do some sort of pagination or you can even
try to kind of offload as much data onto offchain or ipfs, you know, just generally speaking. Blockchain data is very expensive. It has to be replicated by so many nodes. So yeah, I agree. I think there needs to be some sort of pagination going on or kind of splitting up your app calls. Yeah, I think that's a really
interesting. Yeah, we have thought about all the things even thought about using IPFS. The problem is that then you use IPFS, the keys will be there so you cannot have an open protocol. This actually everybody has to use an app protocol when you build something, right? So that's why like our vision is everybody
should be able to use. So you have to have an open protocol which anybody can integrate. Like if somebody comes to algo and starts building something if they want notifications, just install our SDK done. That's our solution. I wanted to interject the minimum balance requirement into this
conversation here. Andrew, you talked earlier about how the minima balance requirement works for box storage. I don't know if you have that data handy, but essentially if you were going to use an entire box, a 32K
Hey, box, I think you said that was 13 ish algos. Is that right? Yes, that should be. It depends also on your key length, but the minimum key length. Yeah. So around around about 13 ish algos. That would be stored in
the balance of the smart contract, right? So I guess to you AP then in your design. So for a user who is getting all these notifications, like your system would have to ensure that the minimum balance requirement was held by that smart
contract and maybe your end users would have to send in the maximum allocation so that they could have the maximum number of notifications put into that.
Yeah, yeah, I understood like maybe yeah, I got that point. So 13 around 13 I'll go right that will be the cost for maybe a 32kb space. Right, that's correct.
Yes, we have a document in article that Ann published on the Dev Portal that's featured right now. It should be the first moment that you see if you're going there right now and it talks about box storage.
it goes through it, it does the calculation, or it has the math in there for the calculation. How much does it cost essentially per byte in order to allocate or how does allocating these boxes and the storage therefore increase the minimum balance requirements?
Oh good does we'd love to have you hit that request button and come up and join Andrew and Anne from our product and engineering teams. They're here to tell you answer all of your questions, I should say, answer all of your questions that you may have about box storage, developing that. So we're
We're thrilled to have you guys here and is going to be at the cipher next week and I'm going to be talking about this as well. But here's your opportunity, I'll go fam, to ask some questions to the team now. Yeah. And even if you don't have a question, but you just want to tell us how you're going to use boxes. We'd love to hear it.
Yeah, that's that's super helpful because I remember answering that as in her roles, right, she's she's product manager, right, she's always thinking about how how will the devs use this product?
that she designs and not the engineering team implements, right? And then they put it out there and they're like, "Oh wow, I had no idea they were going to use it that way."
So, AlgoDez, if there are things that you want to see in this or, you know, if you see shortcomings in the way that we are designing storage systems, then let us know. This is how we improve. Love to hear from you.
Yeah, but I can make sure that we will try to utilize it as soon as possible and try to put in more data with less cost. So like we never thought like maybe we were waiting for Box your age. So since we knew that the it will almost cost 13 algo for 32kb.
like we will try to make sure that it will be cost effective. Yeah, correct. And do you show us a demo during the auguran proof of state show earlier today? Can you tell us your GitHub handle where we can find that demo if we want to do the play at home game?
Yeah, sure. Yeah, sure thing. So it's on GitHub. So it should be in my repos my GitHub handle is Algo Troy, same as my Twitter handle, a LGO, CHOI. And there I have a repo called a box demo.
And if you see there, if you install the requirements using the latest pi-teal version, which is 0.20.1 and using the latest Python FK version 1.20.1, you should be able to kind of replicate my demo using sandbox. And yeah, you can see all the new features
that are in our Python kind of algorithmical system there. And so basically that demo goes through the complete lifecycle of a box from create to get to to delete and then what else you got in there as well. Yes, but currently we have kind of five methods that
show what boxes can do. So like you said, create, put, get the length, get the value and delete boxes. And yeah, you can see that a lot has not changed. So existing developers will see that this syntax is very familiar to them. There are new PiteOop codes, obviously, but using
You can kind of integrate them seamlessly into existing ABI contracts like I did and you can compile them down to Tiel or you could use Tiel outright to build your contracts there. And even in your Python SDK, it's very similar. There's just a new field called BoxSense similar to foreign apps for an accounts array.
You just kind of declare which boxes you want to touch beforehand and then you could operate with boxes using the SDK using these SDK calls. All right, and then tell us about some of the caveats that are associated with boxes in terms of how the data can
can be read, read, or written to, like, who has access to see the data and to interact with the boxes. >> Yeah, that's a great question. And also, touched upon this, but the box itself, it's kind of
private to the app account that owns it. So for instance, the app can only kind of read and get whatever is in the box's own content. So it's associated with the smart contract itself, but of course in a blockchain, it's also transparent in public. It's a
open to the world. So anyone, you know, for instance, you can go on Algo Explore and inspect the contents of a call that someone else made to their smart contracts. So in that case, it's somewhat public in a view state, but in terms of accessing putting stuff into the box, only the smart
track can do that. And I think you kind of also mentioned caveats. So I think an interesting caveat on boxes that you should always remember to delete your box before you close out your app account. And that's because we want to recover back our minimum balance requirement. And it's kind of like a deposit
it, you know, in other kind of languages or ecosystems, it's a deposit or it's like a pseudo deposit where you pay more upfront and get a refund back. But in Algrany, you know, as soon as you delete your box, you get that minimum balance requirement back so you can free up that liquidity to do something else or create more
more boxes. It's free, so you can do whatever you'd like with that. All right, cool. And then when you declare a box, do you have to declare the size of the box initially?
What does that box create look like?
Yeah, and you want to take this or sure? Yes, you do need to when you create the box, you give it a name and you give it a size. And you can also, I mean, there is a different opcode and Andrew keep me honest, but I think an opcode that, you know,
puts where it will just put all the contents in a new box if a box doesn't already exist. Is that correct, Andrew? Yeah, that's correct. So put this kind of a convenience where you can just create a box with a variable like the bytes. Right. Yeah, one thing we didn't really discuss
yet is the when your, so boxes obviously are can be potentially large pieces of data that you know need to be brought into memory to execute the app, the app call. And so boxes are especially
in the boxes array, which is analogous to the foreign arrays, the foreign app array, the foreign assets array, and the foreign accounts array. So in the same way, those arrays served to tell Algrin, like the AVM, which pieces of data the contract will need to
to interact with to execute. So now we tell it which boxes it needs to execute. And because boxes can be larger than any of those other things, like each of those other things have limited sizes, like maximum sizes, you know, apps, accounts, and assets, right?
Because the level state is limited, it can be at most 6.4 key value pairs. But boxes can be up to 32k. So if you need to make a call, like that is then a lot of work for the AVM to go and bring that 32k into memory. That's something, you know, piece of work.
the A/BMS to do that has to be paid for by putting it into the foreign boxes array. And one thing that's interesting about this design, that if you need to access a large box, you'll actually need to put multiple box reference
in the boxes array, to call time, you'll need to pay for the access to that data. So that's another form of payment. So you're paying every time you're interacting with that box just a little bit.
So that's complementary to the minimum balance requirement which pays for the persistent storage of that information. Does that make sense? Yeah, and then also the ADM, the stack machine that is the ADM, it also has some limitations.
on how much data it can actually have on the stack. So I don't think you can handle an entire 32k worth of data on the stack. So how do we deal with that? Right. The stack elements may be in the right most 4k.
I think the best thing to do is there's an example I think in the article that was published that shows, or there's at least an example on GitHub that shows how you can manipulate, you know, get the data from a box that's larger than 4K into your teal contract.
Okay, so it'd be something more like like a hash map where I know kind of the organization of the maximum of that 32k with a bytes and I know that okay, I've got elements here at the first through the fifth
I'll just parse that out of my box, throw that on the stack, do my manipulation, and then either put data back in to the box at those byte strings, or
just rewrite a brand new box if I want to base on that. Is that correct in? I think so. I haven't looked at that pattern super closely recently, but I think that's correct. And one thing that's also important to note, and you remind
me with what you said is when you're interacting with the box, the whole box will be loaded into memory for Dave. People ask me, "Can't I just get a piece of the box and just put that in my box's array, specify what part of the box I need to access?" But no, you get the
whole box because that's the way the data is organized on the ledger. So just clarifying that is a common question I've been getting. Yeah, I find me also there's I didn't show it in my demo, but there's there's two kind of a cause that you can use to write toolbox. What is putt which is
what I showed and as Anne said, there's a limit in the AVM where, you know, by the race can be only up to four kilobytes. So if you're using box putt, yeah, you can only, you know, put stuff up to four kilobytes. But if you use this up code called box replace, like
Brian said you can kind of forge different parts of this box into your box to get these puzzle pieces and form into a hole. So that's kind of one thing, one caveat to boxes that I thought it was interesting. All right, good. I'm going to throw out the last
call to our Algo Devs in the audience. Hit that request button and you can come up and ask and and do some questions. We've got one up here right now. Kirby.algo is joined us on stage. What do you got for a question today? Hey, as a good guy. Apologies if I missed this already.
I think I was a little late, but I read somewhere that the box storage is going to be private on chain, unlike local storage and global storage, but it was my understanding that it's still readable off chain. I'm just curious about what the psychology or the reasoning behind that is.
Yeah, good question. I think one sort of compelling reason for that choice. I mean, we, this was a choice that we debated that a lot, by the way. But one compelling reason was to give oracles a business model, right? Oracles serve a very important purpose.
You know, bringing data like useful information to the chain that all all dApps can use. But if Oracle's are storing that information in their global or local state, then nobody, you know, you can just read their global or local state. You don't have to make an app call
to them and pay them whatever fee they have. So then they have no incentive to actually, like, there's no business model in that case. So boxes give them the business model. If you need, you know, to know the price of like the Algo USDC pair or whatever for that round and you're going
make the trade, you'll actually need to make the call to the Oracle contract to get that information and thereby paying them and there's the business model. Does that make sense? Yeah, okay. And we also, you know, one like I think it makes sense for
from a programmer perspective to have the ability to have a private set of information and a public set of information. So you can build your applications in a nice way that, in a natural way for a developer, I think.
Yeah, makes sense to me. I covered his answer to your question.
It does. Thank you. All right. Great. Andrew, anything to add here? That was. That was great. All right. Yeah. Thank you for the question, Kirby. I think it was an interesting question though. Yeah. Thanks. Thanks to both our guests here.
Kirby and the angry penguin coming up here to ask Anne Kenyon and Andrew Choi are two colleagues here at at Algorand on the product and engineering team all about box storage here today we're going to wrap up this episode of the Norforks Given Post Show
We're going to invite you back in future weeks. Next week we're going to be in Dubai. So we're going to take an off week. We're going to invite you to make sure that you are following the Decider Events Twitter handle and also the Decider Event.com website. There you can get yourself tickets.
If you would like to come and join us in person into by next Monday through Wednesday or live streaming will be available. I'm hosting the Tech Talk stage. I've got Anne. I think actually Anne. I think she's on the main stage next week talking about boxes. We'll have Superbacali. I found her up there.
We've got the executive officers from both Inc and Foundation as well as many within our leadership teams coming and telling you all about what's being built on Al Grand will meet various projects that have already built and you'll get the
lots of informative panels on the DeFi space, the creators and builders, plenty for all you DGENs and creators and the Algo Fam in general. That is DecipherEvent.com. Hope to see you there. And Kenyan and Andrew Choi. Once again, thanks so much for joining us here today.
Thank you for having me. Yeah, thanks to hear from everybody. All right, everyone out there in the Algo fam. Hope you have a great rest of your day and have fun building an Algo grant.