Current location: Homepage > php > Solana Developer Bootcamp 2024 - Learn Blockchain and Full Stack Web3 Development - Projects 1-9 - Ep10

Solana Developer Bootcamp 2024 - Learn Blockchain and Full Stack Web3 Development - Projects 1-9 - Ep10

2025-07-11 13:29:11 [ai] Source: MetaScripta
it um so if you rememberin the previous example or viral interviews 2025previousproject we built we use D the accountmacro or the dve accounts macro soDriveaccounts and we're going to create thisas a struct called initialized Bol youcan see it's uh copilot kind of alreadyknows what we're doing um doesn't knowentirely but we're going to create itourselves so struct ini iiz poll we'regoing to use a lifetime for this andthen we have to create a different abunch of different accounts within thisuh context as part of this initializedpoll we're going to be creating accountsuh so that means we need two accountsalready we need the signer and we needthe system program now anchor is reallynice it'll actually pull in the systemprogram already to you so you don't haveto worry about that uh we'll so we'lljust need the signer so let's go buildthat signer so it would be because we'regetting money from it it's a mutablesigner and then we just have this as apub U I'm going to call it signerbecause it's justnice signerinfo so we know this is getting createdperfect great we have a signer that'sgoing to be used to pay for this accountso next thing that we need to do if youremember correctly we had the pollaccount so we need to create an accountfor the poll so let's go and create itso account and I'll fill everything inin just a moment we just want to makesure that we set it up so poll uh thiswill be account info poll that works outand down here we going to create thatstruct real quick so I'm going to use uhaccount we're going to do Pub structpole and we're going to put everythingin this so we have we're going to have apub what poll ID say it already kind ofknows what we're doing um thank youco-pilot so we're going to have a pollID that's going to be u64 as wementioned earlier um we have adescription so this is Pubdescription we're going to call this astring uh we have a poll start so Pubpull start that's also going to be use64 because that's how you measure it'sgoing to be a Unix time stamp we havepoll end which is also going to be use64 and then we have a poll indexuh we can have this or we had it as a uhcandidate amount so candidate amount andwe're going to have this as E64 so thisis everything in our poll uh this shouldbe everything that we need right hereand so we should be able to create itright here uh create the account righthere so let's go build it all if youremember last time and co-pilot isgiving us all the answers ahead of timeis that you can use in it to make aaccount automatically initi ize um thenext thing is we're going to have thepair we have toote which pair it is sowe're going to have to give it the pairuh we have to give it the space involvedand so we we had some variable stuffhere we have a string we have a bunch ofU 64s use 64s we know how many bytesthey are but the string might be adifferent amount of bytes so we have touse something called max length to giveit's a it's in a macro to give the maxlength that this string could possiblybe so is going to give that right hereall right so do that we actually using amacro called maxor Len and we can justgive the number of characters that thestring can possibly be so I'm going justput uh 32 and that should be good Ithink that's good enough um we couldgive I guess we can do like a Twitterpost to 80 characters um we can put awhole bunch of description in there thatshould be good enough for this um so wehave the pair we have the size and we'regoing to do another thing there's 'sanother thing called in it space thatallows you to automatically calculatethe space and you don't have to do someextra work or math in your head tofigure out how much space this is calledso in order to do that you do uhhash uh it's going to bederive in itspace and so this basically allows youto get the space very easily so when wedo the space here and do space whoops uhit'll we always eight cu the way theAnor does in the in the current versionis that it always has eight bytesreserved to it so 8pluspole in itspace it's actually in it space there wego um and then we need the seeds so ifyou remember earlier we have the seedsas the PO so we can actually pull thatin and use that as a seed um so we'regoing to do seeds you can see as pull asref it's not exactly what we're going todo um but that's okay we'll update itall right so the way that you pull indifferent uh parameters that you use isyou'll actually use a macro calledinstruction and you can see it pulls inthe pole ID as a u64 and then what youcan do is you can then use the poleID think it's as rough uh to do a SEfor this poll account so this seeds setsup the poll ID um as seeds to get thatpoll account and then finally asexplained earlier you always need thebump so we always have the bump in thepole we have the signer of the poll umand I believe we can just run this nowlet's let's go and do anchorbuild build early and often um let's seeif we run into errors we did run intoerrors let's go fix them real quick umso Trad bump blah blah blah pole okay solet's see oh let's keep going up notfound in scope so it looks likesomething is not set as the same thinglet's see I I did use that correctly UNDdeclared usize we always have to go tolike the top Air good thing about thethe rust the rust uh analyzer sorry therust compiler is actually gives reallygood errors um so it says here theprogram okay cool initialized pole

(Editor: swift)

Recommended articles
Hot reading