I am trying to write a program in Rust for Solana, but I encounter a problem when using the macro #[entrypoint]. Here is my code:
// src/lib.rs use solana_program::entrypoint; use solana_program::{ account_info::{next_account_info, AccountInfo}, entrypoint::ProgramResult, program_error::ProgramError, pubkey::Pubkey, }; use borsh::{BorshDeserialize, BorshSerialize};
#[entrypoint] fn process_instruction(program_id: &Pubkey, accounts: &[AccountInfo], instruction_data: &[u8]) -> ProgramResult { let instruction: TokenInstruction = TokenInstruction::try_from_slice(instruction_data) .map_err(|_| ProgramError::InvalidInstructionData)?;
// ... the rest of the code ...
}
// Cargo.toml [package] name = "token" version = "0.1.0" edition = "2021"
[dependencies] solana-program = "1.18.11" borsh = "1.4.0" serde = "1.0.198" bincode = "1.3.3" pyo3 = "0.21.2"
[lib] crate-type = ["cdylib"]
When I try to build a project using cargo build, I get the following error:
error: cannot find attribute entrypoint
in this scope
--> src/lib.rs:43:3
|
43 | #[entrypoint]
| ^^^^^^^^^^
|
note: entrypoint
is imported here, but it is a function-like macro
--> src/lib.rs:1:5
|
1 | use solana_program::entrypoint;
| ^^^^^^^^^^^^^^^^^^^^^^^^^^
- Rust version 1.68.0
- Solana version 1.18.11
- macOS Ventura 13.3.1
I would be grateful for any help or recommendations to solve this problem.