Incentives #

Read more about the Incentives system in Hiro here.

Functions #

SenderList #

List all sender incentives for a user.

1
2
3
4
5
6
userId := "userId"

incentives, err := systems.GetIncentivesSystem().SenderList(ctx, logger, nk, userId)
if err != nil {
  return err
}

SenderCreate #

Create a sender incentive for a user.

1
2
3
4
5
6
7
userId := "userId"
incentiveId := "incentiveId"

incentives, err := systems.GetIncentivesSystem().SenderCreate(ctx, logger, nk, userId, incentiveId)
if err != nil {
  return err
}

SenderDelete #

Delete a sender incentive for a user.

1
2
3
4
5
6
7
userId := "userId"
code := "incentiveCode"

incentives, err := systems.GetIncentivesSystem().SenderDelete(ctx, logger, nk, userId, code)
if err != nil {
  return err
}

SenderClaim #

Claim a sender incentive for a user.

1
2
3
4
5
6
7
8
userId := "userId"
code := "incentiveCode"
claimantIds := []string{"claimantId_001", "claimantId_002"}

incentives, err := systems.GetIncentivesSystem().SenderClaim(ctx, logger, nk, userId, code, claimantIds)
if err != nil {
  return err
}

RecipientGet #

Get a recipient incentive for a user.

1
2
3
4
5
6
7
userId := "userId"
code := "incentiveCode"

incentive, err := systems.GetIncentivesSystem().RecipientGet(ctx, logger, nk, userId, code)
if err != nil {
  return err
}

RecipientClaim #

Claim a recipient incentive for a user.

1
2
3
4
5
6
7
userId := "userId"
code := "incentiveCode"

incentive, err := systems.GetIncentivesSystem().RecipientClaim(ctx, logger, nk, userId, code)
if err != nil {
  return err
}

Hooks #

SetOnSenderReward #

Set a custom reward function which will run after an incentive sender’s reward is rolled.

1
2
3
4
5
6
systems.GetIncentivesSystem().SetOnSenderReward(OnSenderReward)

func OnSenderReward(ctx context.Context, logger runtime.Logger, nk runtime.NakamaModule, userID, sourceID string, source *hiro.IncentivesConfigIncentive, rewardConfig *hiro.EconomyConfigReward, reward *hiro.Reward) (*hiro.Reward, error) {
	// Modify reward or take additional actions.
	return reward, nil
}

SetOnRecipientReward #

Set a custom reward function which will run after an incentive recipient’s reward is rolled.

1
2
3
4
5
6
systems.GetIncentivesSystem().SetOnRecipientReward(OnRecipientReward)

func OnRecipientReward(ctx context.Context, logger runtime.Logger, nk runtime.NakamaModule, userID, sourceID string, source *hiro.IncentivesConfigIncentive, rewardConfig *hiro.EconomyConfigReward, reward *hiro.Reward) (*hiro.Reward, error) {
	// Modify reward or take additional actions.
	return reward, nil
}