Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

150
Visualizações
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
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda