6

I was writing rust code where I used init_if_needed. Got the following error:

init_if_needed requires that anchor-lang be imported with the init-if-needed 
cargo feature enabled. Carefully read the init_if_needed docs before using 
this feature to make sure you know how to protect yourself against re-initialization attacks.

how do I import anchor-lang with the init-if-needed cargo feature enabled

1 Answer 1

6

add this in the cargo.tomlfile

anchor-lang = {version = "0.25.0", features = ["init-if-needed"]}

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.