Skip to content

Class: UserCurrencyService ​

Sub-service for managing a viewer's internal currency (the channel's Player currency): read the balance, add, remove, or set an amount.

Remarks ​

Accessible everywhere via k.users.currency. You never have to instantiate this service yourself — it is created by the SDK when the app/widget starts.

Example ​

ts
// Reward a viewer with 50 coins
await k.users.currency.add('twitchdev', 50);
const balance = await k.users.currency.get('twitchdev');
console.log(`New balance: ${balance}`);

Methods ​

add() ​

ts
add(login, amount): Promise<void>;

Adds an amount to a viewer's internal currency.

Parameters ​

login ​

string

The login (Twitch username) of the viewer.

amount ​

number

The amount to add (positive integer).

Returns ​

Promise<void>

A promise that resolves once the operation has been forwarded to the backend.

See ​

remove to remove an amount.


get() ​

ts
get(login): Promise<number>;

Reads a viewer's internal currency balance.

Parameters ​

login ​

string

The login (Twitch username) of the viewer.

Returns ​

Promise<number>

The current balance, or null if the viewer cannot be found.

Example ​

ts
const balance = await k.users.currency.get('twitchdev');

remove() ​

ts
remove(login, amount): Promise<void>;

Removes an amount from a viewer's internal currency.

Parameters ​

login ​

string

The login (Twitch username) of the viewer.

amount ​

number

The amount to remove (positive integer).

Returns ​

Promise<void>

A promise that resolves once the operation has been forwarded to the backend.

See ​

add to add an amount.


set() ​

ts
set(login, amount): Promise<void>;

Sets a viewer's internal currency to a specific value (replaces the balance).

Parameters ​

login ​

string

The login (Twitch username) of the viewer.

amount ​

number

The new balance to apply.

Returns ​

Promise<void>

A promise that resolves once the operation has been forwarded to the backend.