Skip to content

Quickstart: from an empty project to a purchase

You will install the Stores module, fill a store with a sample, publish it to staging and buy two offers from a game: a free welcome pack of 100 gems, then a starter pack for 10 of them.

Download the rudder CLI first. The SDK of your engine installs from the Rudder package registry in the steps below.

  1. Open the Rudder Dashboard, enter your email and open the link that comes to it; that creates your account and signs you in.

  2. In your game repository, sign the CLI in and create a project.

    Terminal window
    rudder login
    rudder project create "My Game" --json

    Use the returned project ID to select it, then install the agent instructions if you want an agent to carry out the following steps.

    Terminal window
    rudder project use --environment staging <project-id>
    rudder agent init
  3. Save the following currency objects as gems.json and gold.json.

    {"slug":"gems","name":"Gems","clientVisible":true}
    {"slug":"gold","name":"Gold","clientVisible":true}
    Terminal window
    rudder currency create --file gems.json
    rudder currency create --file gold.json
  4. Read the ready modules and install Stores. Inventory is installed with it.

    Terminal window
    rudder module show stores --json
    rudder module install stores
    rudder module apply-sample inventory starter
    rudder module apply-sample stores starter
  5. Check the configured draft. Use the returned revision for publication.

    Terminal window
    rudder release check --json
    rudder release publish --expected-revision <revision> --json

    If the check reports a problem, correct the catalog through the CLI or Dashboard and check again. Record the published staging version for client generation.

  6. Read the staging SDK key.

    Terminal window
    rudder environment show --env staging --json

project use writes rudder.json at the root of your repository. Commit it: every later command reads the project from it.

The client is typed code written for your project: a class per module and a method per function a client may call. Generate it from the staging version returned by publication.

Terminal window
rudder client generate --lang csharp --output Assets/Rudder/Rudder.g.cs \
--game-address https://api.rudder.build --release-version <version>

Then add the SDK to Packages/manifest.json of your Unity 6 project, from the Rudder package registry:

{
"scopedRegistries": [
{
"name": "Rudder",
"url": "https://hub.rudder.build/api/packages/rudder/npm/",
"scopes": ["@rudder"]
}
],
"dependencies": {
"@rudder/unity": "1.3.0"
}
}
using Game;
using Game.Stores;
using RudderSdk;
using UnityEngine;
public class FirstPurchase : MonoBehaviour
{
[SerializeField] private string sdkKey;
private async void Start()
{
var rudder = await Rudder.SignInDevice(sdkKey, SystemInfo.deviceUniqueIdentifier);
foreach (var offer in new[] { "welcome", "starter" })
{
try
{
var bought = await rudder.Stores.Buy(new BuyArguments { Offer = offer });
Debug.Log($"Bought {bought.Name}, {bought.Remaining} more allowed");
}
catch (RudderException exception) when (exception.Code == "limit_reached")
{
Debug.Log($"This player bought {offer} already");
}
}
var balances = await rudder.Session.Wallet();
Debug.Log($"gems {balances["gems"]}, gold {balances["gold"]}");
}
}

The first run prints 90 gems and 300 gold: the welcome pack gave 100 gems, the starter pack cost 10 and gave 300 gold and two potions. The next run on the same device gets limit_reached for both packs: each sells once per player.

Open Players, choose Staging in the header and open the newest player. Its card shows the balances, the potions under Inventory and the purchases under Stores. History lists both calls of stores.buy with every change they made: the gems paid, the currencies and items granted, the purchases counted.

The marketplace covers the common features. What is unique to your game, such as a daily bonus or a battle pass on the purchases of Stores, is a module of your own: see Own modules. Your first module walks through writing one; a project on the Free plan writes and tests it locally and needs Pro to publish it.