Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Snippet] Finding bytes of an account based on layout #130

Open
jacobcreech opened this issue Dec 28, 2021 · 4 comments
Open

[Snippet] Finding bytes of an account based on layout #130

jacobcreech opened this issue Dec 28, 2021 · 4 comments
Labels
Reference Reference for the Cookbook

Comments

@jacobcreech
Copy link
Collaborator

Section: Accounts

We need a snippet to find the size of an account based on the layout. We can use the layout's .span js/ts method from bufferLayout to get the size. Needs to be added

@anoushk1234
Copy link
Contributor

anoushk1234 commented Jan 4, 2022

Can you explain a bit more about the issue, I didn't quite understand

@jacobcreech
Copy link
Collaborator Author

@anoushk1234 Sure

So accounts are often denoted by structs in Rust, right? To create accounts, however, you need to know the size to allocate to that account given the variables within the account.

Let's take these instructions here https://github.com/solana-labs/solana/blob/master/web3.js/src/system-program.ts#L537

What you can do with this to find out the size of the account is SYSTEM_INSTRUCTION_LAYOUTS.Transfer.layout.span because it uses bufferLayout. This is often a very confusing part of writing the client

@jacobcreech jacobcreech added the Reference Reference for the Cookbook label Feb 28, 2022
@harshkn
Copy link

harshkn commented Apr 27, 2022

You mean amount of bytes required for an instruction right ? not accounts. Am I understanding this correctly ?

@jacobcreech
Copy link
Collaborator Author

@harshkn The data field is used in instructions to create specific accounts. You need to know the size of the account the instruction is creating.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Reference Reference for the Cookbook
Projects
None yet
Development

No branches or pull requests

3 participants