1
warning: unused variable: `ctx`
 --> programs/calculator-dapp/src/lib.rs:9:23
  |
9 |     pub fn initialize(ctx: Context<Initialize>) -> Result<()> {
  |                       ^^^ help: if this is intentional, prefix it with an underscore: `_ctx`
  |
  = note: `#[warn(unused_variables)]` on by default

1 Answer 1

3

A solution is in the warning message:

prefix it with an underscore: _ctx

For example:

    pub fn initialize(_ctx: Context<Initialize>) -> Result<()> {
       ...
    }

Generally, you'll use the context to access the accounts for your instructions, but the example above should get rid of the warning.

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.