Quantcast
Channel: Active questions tagged rustc - Solana Stack Exchange
Viewing all articles
Browse latest Browse all 37

solana contract rust error anchor build

$
0
0

use anchor_lang::prelude::*;use anchor_spl::token::{self, Mint, Token, TokenAccount, Transfer, MintTo};

declare_id!("GTPh1tdHiMWVj3yBj2S2ZZftuLPEWPyQZ6Cy7g5ibM5K");

#[program]pub mod puj {use super::*;

pub fn initialize(ctx: Context<Initialize>, name: String, symbol: String, metadata_url: String) -> Result<()> {    let user_info = &mut ctx.accounts.user_info;    user_info.amount = 0;    let cpi_accounts = token::CreateToken {        payer: ctx.accounts.user.to_account_info(),        mint: ctx.accounts.mint.to_account_info(),        authority: ctx.accounts.user.to_account_info(),        rent: ctx.accounts.rent.to_account_info(),        system_program: ctx.accounts.system_program.to_account_info(),    };    let cpi_program = ctx.accounts.token_program.to_account_info();    let cpi_ctx = CpiContext::new(cpi_program, cpi_accounts);    token::create_token(cpi_ctx)?;    let cpi_accounts = token::SetMetadata {        mint: ctx.accounts.mint.to_account_info(),        authority: ctx.accounts.user.to_account_info(),        metadata: token::TokenMetadata {            name,            symbol,            uri: metadata_url,            seller_fee_basis_points: 0,            creators: None,        },    };    let cpi_ctx = CpiContext::new(cpi_program, cpi_accounts);    token::set_metadata(cpi_ctx)?;    Ok(())}pub fn deposit(ctx: Context<Deposit>, amount: u64) -> Result<()> {    let cpi_accounts = Transfer {        from: ctx.accounts.from.to_account_info(),        to: ctx.accounts.to.to_account_info(),        authority: ctx.accounts.user.to_account_info(),    };    let cpi_program = ctx.accounts.token_program.to_account_info();    let cpi_ctx = CpiContext::new(cpi_program, cpi_accounts);    token::transfer(cpi_ctx, amount)?;    let mut user_info = ctx.accounts.user_info.load_mut()?;    user_info.amount += amount;    Ok(())}pub fn claim(ctx: Context<Claim>, amount: u64) -> Result<()> {    let user_info = ctx.accounts.user_info.load()?;    if user_info.amount < amount {        return Err(ErrorCode::InsufficientFunds.into());    }    let seeds = &[ctx.accounts.mint.to_account_info().key.as_ref(), &[ctx.accounts.mint.bump]];    let signer = &[&seeds[..]];    let cpi_accounts = MintTo {        mint: ctx.accounts.mint.to_account_info(),        to: ctx.accounts.to.to_account_info(),        authority: ctx.accounts.mint_authority.to_account_info(),    };    let cpi_program = ctx.accounts.token_program.to_account_info();    let cpi_ctx = CpiContext::new_with_signer(cpi_program, cpi_accounts, signer);    token::mint_to(cpi_ctx, amount)?;    Ok(())}

}

#[derive(Accounts)]pub struct Initialize<'info> {#[account(init, payer = user, space = 8 + Mint::LEN)]pub mint: Account<'info, Mint>,#[account(mut)]pub user: Signer<'info>,pub rent: Sysvar<'info, Rent>,pub token_program: Program<'info, Token>,pub system_program: Program<'info, System>,#[account(init, payer = user, space = 8 + 8)]pub user_info: AccountLoader<'info, UserInfo>,}

#[derive(Accounts)]pub struct Deposit<'info> {#[account(mut)]pub from: Account<'info, TokenAccount>,#[account(mut)]pub to: Account<'info, TokenAccount>,pub user: Signer<'info>,pub token_program: Program<'info, Token>,#[account(mut)]pub user_info: AccountLoader<'info, UserInfo>,}

#[derive(Accounts)]pub struct Claim<'info> {#[account(mut)]pub mint: Account<'info, Mint>,#[account(mut)]pub to: Account<'info, TokenAccount>,#[account(mut)]pub user_info: AccountLoader<'info, UserInfo>,pub token_program: Program<'info, Token>,pub mint_authority: AccountInfo<'info>,}

#[account]pub struct UserInfo {pub amount: u64,}

#[error_code]pub enum ErrorCode {#[msg("Insufficient funds for claim.")]InsufficientFunds,}

good evening, I have a rust project to create a solana contract and I have not been able to resolve this error, can someone help me please? marcela@DESKTOP-NOEFO9H:~/video/my_tokenSolana$ anchor builderror: package solana-program v1.18.16 cannot be built because it requires rustc 1.75.0 or newer, while the currently active rustc version is 1.68.0-devEither upgrade to rustc 1.75.0 or newer, or usecargo update -p solana-program@1.18.16 --precise verwhere ver is the latest version of solana-program supporting rustc 1.68.0-devI have these versions active marcela@DESKTOP-NOEFO9H:~/video/my_tokenSolana$ cargo --versioncargo 1.79.0 (ffa9cf99a 2024-06-03)marcela@DESKTOP-NOEFO9H:~/video/my_tokenSolana$ rustc --versionrustc 1.79.0 (129f3b996 2024-06-10)marcela@DESKTOP-NOEFO9H:~/video/my_tokenSolana$ anchor --versionanchor-cli 0.30.0show me this. marcela@DESKTOP-NOEFO9H:~/video/my_tokenSolana$ rustup toolchain liststable-x86_64-unknown-linux-gnu (default) (override)solana,and respect to toml_edit error show me this marcela@DESKTOP-NOEFO9H:~/video/my_tokenSolana$ cargo update -p toml_edit@0.21.0error: package ID specification toml_edit@0.21.0 did not match any packagesDid you mean one of these?

toml_edit@0.21.1toml_edit@0.22.14 and i sont know how to resolve


Viewing all articles
Browse latest Browse all 37

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>