# RPC function for add money to user storage

**URL:** <https://forum.heroiclabs.com/t/rpc-function-for-add-money-to-user-storage/2970>\
**Category:** Runtime Framework\
**Tags:** lua\
**Created:** [August 26, 2022, 6:30pm UTC](https://forum.heroiclabs.com/t/rpc-function-for-add-money-to-user-storage/2970 "2022-08-26T18:30:31Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![mohader23423](https://avatars.discourse-cdn.com/v4/letter/m/7bcc69/32.png) [@mohader23423](https://forum.heroiclabs.com/u/mohader23423)\
**Post date:** [August 26, 2022, 6:30pm UTC](https://forum.heroiclabs.com/t/rpc-function-for-add-money-to-user-storage/2970/1 "2022-08-26T18:30:31Z")

</div>

{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}

```auto

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")

```

📺 **Media:**

---

<div class="post-metadata">

**Author:** ![tom](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.heroiclabs.com/tom/32/676_2.png) [@tom](https://forum.heroiclabs.com/u/tom)\
**Post date:** [August 31, 2022, 11:06am UTC](https://forum.heroiclabs.com/t/rpc-function-for-add-money-to-user-storage/2970/2 "2022-08-31T11:06:41Z")

</div>

Hi @mohader23423,

Rather than implement this using the Storage Engine you should consider using [Nakama’s Virtual Wallet](https://heroiclabs.com/docs/nakama/concepts/user-accounts/#virtual-wallet) functionality.

You can update the user’s wallet using the [`wallet_update` function](https://heroiclabs.com/docs/nakama/server-framework/lua-runtime/function-reference/#wallet_update) and then get the value of a user’s wallet using the [`get_account_id` function](https://heroiclabs.com/docs/nakama/server-framework/lua-runtime/function-reference/#account_get_id) 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).
