
FiveM RPC
Call FiveM server, client and NUI listeners like async functions: typed, with timeouts, no event ping-pong
A TypeScript library that lets the different parts of a multiplayer GTA V server talk to each other as simply as calling a function. Open-source
In plain words
Every FiveM server is built from three parts:
- the server, which holds the shared world and the rules
- the game client on each player's computer
- the in-game screens: menus, phones and shops, built as small web pages
These parts constantly need things from each other. For example, when a player presses "Buy" in a shop menu, the menu has to ask the server whether the player can afford the item and then show the answer
Out of the box, FiveM only lets these parts leave notes for each other. One side sends a message and never finds out whether anyone read it. Getting an answer back means wiring up a second message by hand every time, and it is easy to get wrong
FiveM RPC turns those notes into phone calls. One part asks and waits, and the other part answers. The call always ends in one of two ways: an answer, or a clear explanation of what went wrong
const bought = await rpc.emitServer('buyItem', 'water')Why it matters
- Nothing gets stuck. Every request ends within 5 seconds, with an answer or a readable error, so a menu never freezes waiting for a reply that will not come
- Players cannot pretend to be someone else. The server gets each player's identity from the game itself, never from what the player's computer claims. A modified game client cannot act in another player's name or fake another player's answers
- Mistakes are caught before the game even starts. Developers describe their messages once, and their code editor autocompletes names and flags typos and wrong data as they type
- Errors explain themselves. Instead of "something failed", a developer reads, for example:
No listener for "buyItem" on server. Register it with rpc.onClient("buyItem", ...) in server code - Friendly to AI coding assistants. The package ships a short guide that AI assistants can follow, so code they generate uses the library correctly
How it works
SERVER <-- network events --> CLIENT <-- NUI messages --> WEBVIEW
Where server - world and rules; client - player's game; webview - in-game menus. Calls between webview and server are relayed through the player's client
- One entry point per part.
createRPC({ env: 'server' | 'client' | 'webview' })returns an object with matching pairs of methods:emit*to call,on*to answer - Ten call types, including calls within the same part and a server-wide broadcast to every player
- Every call carries a unique id
- - A pending call waits for the response with the same id, or times out
- - On the server, a call only accepts a response from the player it was sent to
- Listeners never crash the receiver. A missing or failing listener sends a structured error back, and the caller receives it as a typed
RPCError - Typing is opt-in. With nothing declared, everything is accepted. Once a developer declares their events in a shared file, every call in all three parts is checked by the compiler
Inspired by altv-xrpc from the alt:V community
End-to-end