STP
Grants

Time Grants

ℹ️

Only the contract owner, managers, and agents can grant and revoke time.

Granting time to an account does three things:

  1. Mints a new NFT for the account if they don't currently have one
  2. Adds a given amount of time to their subscription
  3. Optionally places them in a given tier

Grants enable the creator to give time without paying for it. This is useful for promotions, giveaways, or other scenarios where the user shouldn't pay for the time.

Additionally, grants can be leveraged to move subscribers around tiers, even if the subscriber doesn't meet the requirements for a tier. Keep in mind the subscriber may not want to be in the tier, so it's important to communicate with the subscriber before moving them.

If you want to grant time to a user and keep them in their existing tier, passing 0 as the tierId when granting will keep the user in their current tier.

import {
  prepareGrantTime,
} from '@withfabric/protocol-sdks/stpv2';
 
const grant = await prepareGrantTime({
  contractAddress: `0x...`,
  account: `0x...`,
  numSeconds: 86400n,
  tierId: 5,
});
 
const receipt = await grant();

Revoking Granted Time

At any time, grantors can revoke the time of a given account. This will remove the time from the subscription and leave the NFT intact and in the tier. If the goal is to remove them from the tier, then deactivateSubscription should be used after the time is revoked.

import {
  prepareRevokeGrantedTime,
} from '@withfabric/protocol-sdks/stpv2';
 
const revoke = await prepareRevokeGrantedTime({
  contractAddress: `0x...`,
  account: `0x...`,
});
 
const receipt = await revoke();