RPC function for add money to user storage

{RPC function for add money to user storage}

Hi ,i want to make Lua RPC function to add some value to user money that stored in storage table
I should get some value, for example 10 from client and send to RPC addSomeMoney function.
Then that function should get money from storage table and plus by 10.
Then send back (old value+10) to client to show the user .
Is this secure ? is there any better way to do these ?

Can you help me to complete the lua addSomeMoney function? please (in lua language)

I really appreciate any help , thank you all
and a very, very big thanks to whose make nakama, thank you all
You are all amazing!

  1. Versions: Nakama {3.13.1}, {Windows, Linux binary}, {client library (SDK) and version}
  2. Server Framework Runtime language {Lua}

local function addSomeMoney(context, payload)
  --[[get value from client to payload json input ?]]
  local user_id = context.user_id
  local quary=nk.sql_query( "SELECT username FROM users  WHERE id = $1", {user_id}  )
--[[
.
.
.
]]
  
  return nk.json_encode({ totalMoney = --[[.....]] })
end
nk.register_rpc(addSomeMoney, "add_Some_Money")

:tv: Media:

Hi @mohader23423,

Rather than implement this using the Storage Engine you should consider using Nakama’s Virtual Wallet functionality.

You can update the user’s wallet using the wallet_update function and then get the value of a user’s wallet using the get_account_id function and send it back to the player.

One thing to point out is with regards to security as you mentioned. Allowing the client to tell the server they just gained 10 coins is not secure and could be abused. If this is important then consider having the server decide how many coins to give the user and under what circumstances it should happen (e.g. at the end of a match when that player is the winner).