1

Since newly created accounts are required to be rent-exempt, what are some examples where the #[account(rent_exempt = skip)] and #[account(rent_exempt = enforce)] anchor constraints would need to be used?

The docs.rs mentions:

Enforces rent exemption with = enforce. Skips rent exemption check that would normally be done through other constraints with = skip, e.g. when used with the zero constraint

Can someone help me better understand why the constraint would be used with the zero constraint?

1 Answer 1

1

It's an uncommon use-case, but bf you want to use an account only for the duration of a transaction, and are ok with it getting cleaned up by the runtime afterwards, there's no requirement to move lamports into it.

For example, you can initialize an account with 10k bytes, write some data into it, and then pass it down to another program for it to read. You wouldn't be able to pass all that data as instruction data, so you use an "ephemeral" account, and your instruction doesn't require a payer to move lamports in and out.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.