How can I fix it?

This is my errors:

error: target is not supported, for more information see: https://docs.rs/getrandom/#unsupported-targets
   --> src/lib.rs:267:9
    |
267 | /         compile_error!("\
268 | |             target is not supported, for more information see: \
269 | |             https://docs.rs/getrandom/#unsupported-targets\
270 | |         ");
    | |__________^

error[E0433]: failed to resolve: use of undeclared crate or module `imp`
   --> src/lib.rs:291:5
    |
291 |     imp::getrandom_inner(dest)
    |     ^^^ use of undeclared crate or module `imp`

For more information about this error, try `rustc --explain E0433`.
error: could not compile `getrandom` (lib) due to 2 previous errors
warning: build failed, waiting for other jobs to finish...

And this is my Carog.tmol file.

[package]
name = "mint-nft"
version = "0.1.0"
description = "Created with Anchor"
edition = "2021"

[lib]
crate-type = ["cdylib", "lib"]
name = "mint_nft"

[features]
default = []
cpi = ["no-entrypoint"]
no-entrypoint = []
no-idl = []
no-log-ix-name = []
idl-build = ["anchor-lang/idl-build"]

[dependencies]
anchor-lang = "0.30.0"
anchor-spl = "0.30.0"
base64 = "=0.21.7"
bincode = "1.3.3"
curve25519-dalek = "4.1.2"
ed25519-dalek = "1.0.1"
getrandom = { version = "0.2.15", features = ["custom"] }
mpl-token-metadata = { version = "4.1.2" }
serde = "1.0.203"
serde_json = "1.0.117"
zeroize = "=1.3.0"

Help me please~~~

What target are you building for? There might be a fallback feature in getrandom you can enable to make it compile. See here.

2 Likes

Thank you for your help.
I'm going to implement the security about signer in my program.
This is some of them of my code.

use anchor_lang::prelude::*;

use anchor_spl::{associated_token::AssociatedToken, token::Token};

use ed25519_dalek::{PublicKey, Signature, Verifier};

// use anchor_lang::solana_program::ed25519_program;

use serde::{Deserialize, Serialize};

use serde_json;
... ... ...
pub fn mint(
        ctx: Context<MintNFT>,
        signature: Vec<u8>,
        message: Vec<u8>
    ) -> Result<()> {
        // Deserialize the message into a PurchaseMessage struct
        let message_str = String::from_utf8(message).map_err(|_| ErrorCode::InvalidMessage)?;
        let purchase_message: PurchaseMessage = serde_json::from_str(&message_str).map_err(|_| ErrorCode::InvalidMessage)?;

        // Verify the signature
        require!(
            ed25519_verify(&signature, message_str.as_bytes(), &ctx.accounts.mint_authority.key()),
            ErrorCode::InvalidSignature
        );
... ... ...
pub fn ed25519_verify(signature: &[u8], message: &[u8], pubkey: &Pubkey) -> bool {
    let pubkey_bytes = pubkey.to_bytes();
    let pubkey = match PublicKey::from_bytes(&pubkey_bytes) {
        Ok(key) => key,
        Err(_) => return false,
    };
    
    let signature = match Signature::from_bytes(signature) {
        Ok(sig) => sig,
        Err(_) => return false,
    };
    
    pubkey.verify(message, &signature).is_ok()
}

#[derive(Serialize, Deserialize)]
struct PurchaseMessage {
    metadata_title: String,
    metadata_symbol: String,
    metadata_uri: String,
    sale_lamports: u64
}

#[error_code]
pub enum ErrorCode {
    #[msg("[x] The provided signature is invalid.")]
    InvalidSignature,
    #[msg("[x] The provided message is invalid.")]
    InvalidMessage,
}

What do you think about that?
Why have I the errors?

What target are you building for? Your target might be the default target (run rustup default to see the default target) or defined in your Cargo configuration file or you pass it directly, i.e. by running cargo build --target=.... It is definitely a target that is not supported by getrandom. There might be workarounds to get getrandom to compile for your target though, see the link from my previous post.

3 Likes

I'm just developing the NFT Mint program and I'm going to implement the security for buyer accounts.

How can I fix it?
Thank you in advance.

Can you tell us the exact command you are running in the terminal when you get the error? We can't help you if we can't know how you tried to build it.

2 Likes

I used this command.

anchor build

Thank you in advance

That's BPF as far as I can tell (never done anything related to blockchain). So bpfel-unknown-none is the exact target, as far as I can judge from this line in an example from the anchor repo. genrandom does not support that target, and there is also no fallback. So you need to use a different library, one that does support the BPF target.

3 Likes

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.