Skip to content

Redemptions

A Redemption offer represents a reward that a user can redeem points to earn.

Creating a redemption

Offchain Redemption

typescript
const { id: redemptionOfferId } = await stack.createRedemptionOffer({
  name: "Stack Baseball Hat Redemption",
  points: 200, // number of points required for redemption
  type: RedemptionOfferType.OFFCHAIN,
});

Parameters

  • name: The name of the redemption offer
  • type: OFFCHAIN means that there is no onchain transaction during redemption
  • points: The number of points required for one redemption

Returns

  • id: The unique ID for the redemption offer
  • name: The specified name of the redemption offer
  • type: The type of redemption
  • status: "ACTIVE" if the offer is active
  • points: The number of points required for the redemption
  • createdAt: Timestamp for creation
  • updatedAt: Timestamp for last change to the redemption offer

ERC20 Redemption

ChainRedemption Contract
Basehttps://basescan.org/address/0x000001C983E593F48b60b9a6038D6d1Bc24Bc4e4
Base Sepoliahttps://sepolia.basescan.org/address/0x000001C983E593F48b60b9a6038D6d1Bc24Bc4e4
Arbitrum Onehttps://arbiscan.io/address/0x000001C983E593F48b60b9a6038D6d1Bc24Bc4e4
Arbitrum Sepoliahttps://sepolia.arbiscan.io/address/0x000001C983E593F48b60b9a6038D6d1Bc24Bc4e4

INFO

In order to successfully transfer funds and create an ERC20 offer you need to set the allowance on the token for this Redemption Contract 0x000001C983E593F48b60b9a6038D6d1Bc24Bc4e4.

typescript
const { id: redemptionOfferId } = await stack.createRedemptionOffer({
  name: "USDC Redemption",
  points: 200, // number of points required for 1 USDC
  type: RedemptionOfferType.ERC20,
  chainId: 8453,
  tokenAddress: "0x833589fcd6edb6e08f4c7c32d4f71b54bda02913",
  tokenBudget: "10000000000000", // denominated according to decimals
  tokenDecimals: 18,
  tokenSupplier: yourWalletAddress, // where the funds are coming from
  maxPointsPerUser: 300000, // optional to limit the amount of points a user can redeem
});

Parameters

  • name: The name of the redemption offer
  • type: ERC20
  • points: The number of points required for 1 decimally-denominated value of the token (i.e. points per 1USDC)
  • chainId: Chain ID of the ERC20 token
  • tokenAddress: address of the ERC20 token
  • tokenDecimals: decimals of the token, default is usually 18
  • tokenBudget: lowest denominated value of the token budget according to decimals
  • maxPointsPerUser?: optional field if you want to restrict the number of points a user can redeem

Fetch redemption offers

Get a list of redemptions for the current point system.

typescript
await stack.getRedemptionOffers();

// [{
//     id: 30,
//     name: 'Stack Baseball Hat Redemption',
//     type: 'OFFCHAIN',
//     status: 'ACTIVE',
//     points: 200,
//     createdAt: '2024-04-17T18:32:41.050Z',
//     updatedAt: '2024-04-17T18:32:41.050Z'
// }]

Redeem

Redeeming for a reward will subtract points from the user's point balance and track an event.

typescript
await stack.redeem(redemptionOfferId, {
  pointAmount: 200, // only optional for offchain redemptions which assumes redemption of 1 item
  address: "0x627306090abaB3A6e1400e9345bC60c78a8BEf57"
});

// Tracks an redeem event and deducts 200 points from 0x2eeb301387D6BDa23E02fa0c7463507c68b597B5

// {
//   address: '0x2eeb301387D6BDa23E02fa0c7463507c68b597B5',
//   redemptionOfferId: 30,
//   claimedAt: "2024-04-17T18:32:44.222Z"
// }

Fetch redemption claims

Fetch all of the users that have redeeemed for a particular redemption offer.

typescript
await stack.getRedemptionClaims({
  redemptionOfferId: 30,
});

// [{
//   address: '0x2eeb301387D6BDa23E02fa0c7463507c68b597B5',
//   redemptionOfferId: 30,
//   claimedAt: '2024-04-17T18:32:44.222Z',
// }, {
//   address: '0x627306090abaB3A6e1400e9345bC60c78a8BEf57',
//   redemptionOfferId: 30,
//   claimedAt: '2024-04-17T18:34:44.222Z',
// }]