Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

113
Views
Solana token ownership

is there any way to check that user A owns spl token B inside solana contract? Maybe there is safe method to check it outside.

I need it to give some privileges to users, which own mine nfts. Users would write data to program only when they have nft.

about 4 years ago · Santiago Trujillo
1 answers
Answer question

0

To check the owner of an SPL token account from within a program, you'll have to deserialize it and check the owner field, ie:

use solana_program::{
    account_info::next_account_info, account_info::AccountInfo, entrypoint,
    entrypoint::ProgramResult, pubkey::Pubkey, program_pack::Pack,
};
use spl_token::state::Account;

entrypoint!(process_instruction);

const EXPECTED_OWNER: Pubkey = Pubkey::new_from_array([1; 32]);

fn process_instruction(
    program_id: &Pubkey,
    accounts: &[AccountInfo], 
    instruction_data: &[u8],
) -> ProgramResult {
    let account_info_iter = &mut accounts.iter();

    let spl_token_account_info = next_account_info(account_info_iter)?;
    let spl_token_account_data = spl_token_account_info.try_borrow_data()?;
    let spl_token_account = Account::unpack(&spl_token_account_data)?;
    if spl_token_account.owner == EXPECTED_OWNER {
        // your logic here
    }
}

Note that I haven't tried to compile this, so use with caution!

about 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!