You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'm trying to init a mint account and then mint to an associated token account, but my code won't compile.
I'm using anchor 0.20.1, below is my code:
usecrate::program::Example;use anchor_lang::prelude::*;use anchor_spl::{
associated_token::AssociatedToken,
token::{Mint,Token,TokenAccount},};declare_id!("Fg6PaFpoGXkYsidMpWTK6W2BeZ7FEfcYkg476zPFsLnS");#[program]pubmod example {usesuper::*;pubfnmint_request(ctx:Context<MintRequest>) -> ProgramResult{Ok(())}}#[derive(Accounts)]pubstructMintRequest<'info>{#[account( init, payer = minter,// I'd like my program as authority// and since mint::authority = <target_account>,// and per documentation target_account needs to be// part of this struct, I introduced this_program. mint::authority = this_program, mint::decimals = 0,)]pubmint_account:Account<'info,Mint>,#[account( init, payer = minter, associated_token::mint=mint_account, associated_token::authority = minter,)]pubtoken:Account<'info,TokenAccount>,#[account(mut)]pubminter:Signer<'info>,pubsystem_program:Program<'info,System>,pubtoken_program:Program<'info,Token>,pubassociated_token_program:Program<'info,AssociatedToken>,pubthis_program:Program<'info,Example>,}
The problem seems to be #[derive(Accounts)]. anchor build results in
developer@7c961325b3bd:~/solana/example/programs/example/src$ anchor build
BPF SDK: /home/developer/.local/share/solana/install/releases/1.9.1/solana-release/bin/sdk/bpf
cargo-build-bpf child: rustup toolchain list -v
cargo-build-bpf child: cargo +bpf build --target bpfel-unknown-unknown --release
Compiling example v0.1.0 (/home/developer/solana/example/programs/example)
error[E0425]: cannot find value `rent`in this scope
--> programs/example/src/lib.rs:18:10
|
18 |#[derive(Accounts)]| ^^^^^^^^ not found in this scope
|
= note: this error originates in the derive macro `Accounts` (in Nightly builds, run with -Z macro-backtrace for more info)
For more information about this error, try `rustc --explain E0425`.
error: could not compile `example` due to previous error
I'f I remove the account with the mint:: constraint, this example will still not work. In order to get it compiled I also need to remove the init constraint on the token account (but not the associated_token::). There, I can remove the init constraint, but the mint:: constraint requires the init constraint, so removing it there is not possible.
The text was updated successfully, but these errors were encountered:
I'm trying to init a mint account and then mint to an associated token account, but my code won't compile.
I'm using anchor 0.20.1, below is my code:
The problem seems to be
#[derive(Accounts)]
.anchor build
results inI'f I remove the account with the
mint::
constraint, this example will still not work. In order to get it compiled I also need to remove theinit
constraint on thetoken
account (but not theassociated_token::
). There, I can remove theinit
constraint, but themint::
constraint requires theinit
constraint, so removing it there is not possible.The text was updated successfully, but these errors were encountered: