Understanding zero copy account for salting
Solana is a popular blockchain platform that supports zero costs, also as #[account (zero copy)]] or #[account (zero copy (uncertainty))]]]
#[account (zero copy)] (secure)
The most common variant of the Zero-Copie account is “#[account (zero)]. This type ensures that all changes introduced on the account are reflected in all chains with a safe, unchanging lock. The “#account (zero copy (dangerous))” variant is similar, but uses an uncertain approach.
#[account (zero copy))
The less common variant of the zero-dip account is #[account (zero copy (dangerous))]
be used only carefully and in some scenarios.
Differences
The main difference between these two variants is your behavior:
#[Account (zero copy)]
(secure): All changes made to the account are reflected on all chains with a safe, unchanging lock.
#[Account (zero (dangerous))]
: changes are allowed on the account without security control. This variant should be used only with caution and in some scenarios.
When can I use everyone
Use #[account (zero copy)]
When:
- You need to make sure your data are safely reflected in all chains.
- You write rust code and want to use the Rust language safety function.
- You work on a project with several chains and you must provide profits.
Use#[account (zero copy)]if:
- Your data does not have to be safely reflected in all chains (e.g. if you write only data in your own chain).
- You want to use a "dangerous" keyword for some tasks, e.g. B. Creating an account lock.
Can I write an uncertain rust code?
Yes, it is possible to write an uncertain code directly in rust. However, the use of a zero sermon account is generally safer than writing a raw code. In addition, you can use libraries such as "Solana Program" and "Anchor" to work safely with zero accounts.
Diploma
To sum up, working on the project he uses is important to understand the differences between zero accounts. Use#[account (zero copy)]for secure, unchanging blocking and
#[Null Comple) (uncertain)]for some scenarios in which you need to make changes to your account without security control.
Sample code
Here is an example of how the zero cost account is used in rust:
` Rost
Use Solana_program :: {
Conct_info :: {next_account_info, conctinfo},
Entrance point :: Program result,
Program_error :: printerror,
};
Use anchor_lang :: {conct_info, einrypoint};
// Define the function of transferring money to your account
FN Deposit (account_dem: & Conccountinfo <'_>, amount: U64) -> Program result {
// you will receive a current account balance
Be balance balance = next_account_info (account_id)?;
// place a certain amount
Balance.amount += amount;
// Save the updated account balance back to your account
Next Konting
Printing house! (“Effective deposit”);
OK (())
}
// Define Zero Cost Account
#[Account (zero copy)]
Zerocopyaccount structure {
Deposit: U64,
}
Imp
Type System Programinfo = Conccountinfo <'_>;
Type programid = program;
Type Type Terror = Printerror;
fn new () -> self :: program
// Create a new program -id
0x1234567890ABCDEF
}
FN Call (& Self, quote: U64) -> Program result {
Deposit (yourself.