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):
units to a wallet address / account I provide