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

Fixing compile error in Anchor CPI lesson #636

Merged
merged 2 commits into from
Nov 23, 2024

Conversation

banescusebi
Copy link
Contributor

Problem

After implementing the code in the Lab section of the Anchor CPI lesson here, I ran into the following build errors:

% anchor build
   Compiling anchor-movie-review-program v0.1.0 (/Users/s/anchor-movie-review-program/programs/anchor-movie-review-program)
    Finished release [optimized] target(s) in 1.46s
   Compiling anchor-movie-review-program v0.1.0 (/Users/s/anchor-movie-review-program/programs/anchor-movie-review-program)
error[E0599]: no function or associated item named `create_type` found for struct `anchor_spl::token::Mint` in the current scope
  --> programs/anchor-movie-review-program/src/lib.rs:89:10
   |
89 | #[derive(Accounts)]
   |          ^^^^^^^^ function or associated item not found in `Mint`
   |
   = note: this error originates in the derive macro `Accounts` (in Nightly builds, run with -Z macro-backtrace for more info)

error[E0277]: the trait bound `anchor_spl::token::Mint: Discriminator` is not satisfied
  --> programs/anchor-movie-review-program/src/lib.rs:99:30
   |
99 |     pub mint: Account<'info, Mint>,
   |                              ^^^^ the trait `Discriminator` is not implemented for `anchor_spl::token::Mint`
   |
   = help: the following other types implement trait `Discriminator`:
             InitializeTokenMint
             MovieAccountState
             __idl::IdlAccount
             anchor_lang::ProgramData
             anchor_lang::idl::IdlAccount
             instruction::AddMovieReview
             instruction::DeleteMovieReview
             instruction::UpdateMovieReview

error[E0599]: no function or associated item named `insert_types` found for struct `anchor_spl::token::Mint` in the current scope
  --> programs/anchor-movie-review-program/src/lib.rs:89:10
   |
89 | #[derive(Accounts)]
   |          ^^^^^^^^ function or associated item not found in `Mint`
   |
   = note: this error originates in the derive macro `Accounts` (in Nightly builds, run with -Z macro-backtrace for more info)

error[E0599]: no function or associated item named `create_type` found for struct `anchor_spl::token::Mint` in the current scope
   --> programs/anchor-movie-review-program/src/lib.rs:107:10
    |
107 | #[derive(Accounts)]
    |          ^^^^^^^^ function or associated item not found in `Mint`
    |
    = note: this error originates in the derive macro `Accounts` (in Nightly builds, run with -Z macro-backtrace for more info)

error[E0277]: the trait bound `anchor_spl::token::Mint: Discriminator` is not satisfied
   --> programs/anchor-movie-review-program/src/lib.rs:127:30
    |
127 |     pub mint: Account<'info, Mint>,
    |                              ^^^^ the trait `Discriminator` is not implemented for `anchor_spl::token::Mint`
    |
    = help: the following other types implement trait `Discriminator`:
              InitializeTokenMint
              MovieAccountState
              __idl::IdlAccount
              anchor_lang::ProgramData
              anchor_lang::idl::IdlAccount
              instruction::AddMovieReview
              instruction::DeleteMovieReview
              instruction::UpdateMovieReview

error[E0599]: no function or associated item named `insert_types` found for struct `anchor_spl::token::Mint` in the current scope
   --> programs/anchor-movie-review-program/src/lib.rs:107:10
    |
107 | #[derive(Accounts)]
    |          ^^^^^^^^ function or associated item not found in `Mint`
    |
    = note: this error originates in the derive macro `Accounts` (in Nightly builds, run with -Z macro-backtrace for more info)

error[E0599]: no function or associated item named `create_type` found for struct `anchor_spl::token::TokenAccount` in the current scope
   --> programs/anchor-movie-review-program/src/lib.rs:107:10
    |
107 | #[derive(Accounts)]
    |          ^^^^^^^^ function or associated item not found in `TokenAccount`
    |
    = note: this error originates in the derive macro `Accounts` (in Nightly builds, run with -Z macro-backtrace for more info)

error[E0277]: the trait bound `anchor_spl::token::TokenAccount: Discriminator` is not satisfied
   --> programs/anchor-movie-review-program/src/lib.rs:134:39
    |
134 |     pub token_account: Account<'info, TokenAccount>,
    |                                       ^^^^^^^^^^^^ the trait `Discriminator` is not implemented for `anchor_spl::token::TokenAccount`
    |
    = help: the following other types implement trait `Discriminator`:
              InitializeTokenMint
              MovieAccountState
              __idl::IdlAccount
              anchor_lang::ProgramData
              anchor_lang::idl::IdlAccount
              instruction::AddMovieReview
              instruction::DeleteMovieReview
              instruction::UpdateMovieReview

error[E0599]: no function or associated item named `insert_types` found for struct `anchor_spl::token::TokenAccount` in the current scope
   --> programs/anchor-movie-review-program/src/lib.rs:107:10
    |
107 | #[derive(Accounts)]
    |          ^^^^^^^^ function or associated item not found in `TokenAccount`
    |
    = note: this error originates in the derive macro `Accounts` (in Nightly builds, run with -Z macro-backtrace for more info)

Some errors have detailed explanations: E0277, E0599.
For more information about an error, try `rustc --explain E0277`.
error: could not compile `anchor-movie-review-program` (lib test) due to 9 previous errors
Error: Building IDL failed

Summary of Changes

Added a paragraph to the lesson that indicates what needs to be added to the Cargo.toml file in order for the code to compile successfully.

@banescusebi banescusebi requested a review from ZYJLiu as a code owner November 20, 2024 17:57
@ZYJLiu ZYJLiu merged commit 462c9a1 into solana-foundation:main Nov 23, 2024
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants