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

149
Views
SOL token transaction using javascript and rust

I am trying to push data to a Solana account as well as charge for the posting. I have a simple rust function:

pub fn place_bet(ctx: Context<PlaceBet>, wager: String, reward: String, game: String) -> ProgramResult {
        let base_account = &mut ctx.accounts.base_account;
        let user = &mut ctx.accounts.user;

        
        let item = ItemStruct {
            game: game.to_string(),
            wager: wager.to_string(),
            reward: reward.to_string(),
            user_address: *user.to_account_info().key,
        };


        
        base_account.read.push(item);
        base_account.total_bets += 1;
        Ok(())
    }

I call this function in my App.js using:

await program.rpc.placeBet(units.toString(), reward(units,line).toString(), id, {
        accounts: {
          baseAccount: baseAccount.publicKey,
          user: provider.wallet.publicKey,
        },
      });

Now when I call this function in my web application, the phantom wallet window pops up to have the provider sign (and pay the small gas fee). I'd like to also transfer an amount along with this function. My thought would be to use the spl_token transfer function:

pub fn transfer(
    token_program_id: &Pubkey, 
    source_pubkey: &Pubkey, 
    destination_pubkey: &Pubkey, 
    authority_pubkey: &Pubkey, 
    signer_pubkeys: &[&Pubkey], 
    amount: u64
) -> Result<Instruction, ProgramError>

I'm still new to rust so am having trouble figuring it out. Ultimately I'd like the function to (in a single transaction):

  1. post the data to the account (which I've already done)
  2. Send the amount (in SOL) of units to a wallet address / account I provide
about 4 years ago · Juan Pablo Isaza
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!