developer-content
developer-content copied to clipboard
CPIs Lab instructions missing step that breaks compilation
Description
The code for the lab, as is, does not compile. See the section at the bottom with the output of anchor build
when using the lab's docs as they are today. I'm using anchor 0.30.1
, as the docs use as well here.
The problem is in this section:
https://github.com/solana-foundation/developer-content/blob/3a4505ef09649ed12092ac56930613211c9cb524/content/courses/onchain-development/anchor-cpi.md?plain=1#L350-L362
It is missing that, besides just editing the [dependencies]
section of the Cargo.toml
, it is also needed to add the following entry to it:
[features]
# ... (pre-existing features omitted here just for clarity)
idl-build = ["anchor-lang/idl-build", "anchor-spl/idl-build"] # note the added "anchor-spl/idl-build"
With this additional entry, the code compiles and tests run successfully. I'm creating this issue and not sending the PR myself as I don't have a good explanation for why that is needed (since anchor 0.29.0
apparently), as I'm very new to Solana and Anchor. For reference, this additional entry is present in the linked solution code, but it should be added to the lab instructions as well.
Kudos to this comment in another issue which helped me get it to work when I ran into this 👍
Output of anchor build
without changes to the Cargo.toml
nchor build
Finished release [optimized] target(s) in 0.11s
Compiling anchor-movie-review v0.1.0 (/Users/tobi/dev/solana-course/anchor-movie-review/programs/anchor-movie-review)
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/src/lib.rs:139:10
|
139 | #[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/src/lib.rs:159:30
|
159 | 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/src/lib.rs:139:10
|
139 | #[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/src/lib.rs:139:10
|
139 | #[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/src/lib.rs:166:39
|
166 | 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/src/lib.rs:139:10
|
139 | #[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[E0599]: no function or associated item named `create_type` found for struct `anchor_spl::token::Mint` in the current scope
--> programs/anchor-movie-review/src/lib.rs:204:10
|
204 | #[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/src/lib.rs:214:30
|
214 | 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/src/lib.rs:204:10
|
204 | #[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)
Some errors have detailed explanations: E0277, E0599.
For more information about an error, try `rustc --explain E0277`.
error: could not compile `anchor-movie-review` (lib test) due to 9 previous errors
Error: Building IDL failed```