2.0.1 • Published 6 months ago

subtopia-js v2.0.1

Weekly downloads
-
License
SEE LICENSE IN LI...
Repository
-
Last release
6 months ago

🌟 About

Subtopia JS SDK is a JavaScript library for interacting with the Subtopia Platform. It provides a simple interface for creating and managing Subscription Management Infrastructures (SMIs).

For detailed documentation, refer to sdk.subtopia.io.

⚡ Examples

  • subtopia-js-examples - A separate repository with examples of using the Subtopia JS SDK in React, Svelte, Vue and NextJS.

📦 Installation

Install the package:

# with npm
npm install subtopia-js

# or with yarn
yarn add subtopia-js

Import the package:

import { SubtopiaClient } from "subtopia-js";

🛠️ Usage

Example snippets of using the Subtopia JS SDK.

Subscriptions

Purchasing a subscription:

// ... your code

const response = await SubtopiaClient.subscribe(
  {
    subscriber: { address: {PUT_WALLET_ADDRESS}, signer: {PUT_WALLET_SIGNER} },
    smiID: { PUT_PRODUCT_ID_HERE }, // number - the ID of the SMI instance you want to subscribe to
    duration: { PUT_EXPIRATION_TYPE_HERE }, // pick duration from DurationType enum. If there is a discount available for this duration, it will be auto applied.
  },
  { client: {PUT_ALGOD_INSTANCE_HERE} // object of type algosdk.Algodv2
);

console.log(response.returnValue) // response is of type ABIResult

// ... rest of your code

Subscription lookup:

// ... your code
const subscriberBox = await SubtopiaClient.getSubscriptionRecordForAccount(
  client,
  { PUT_SUBSCRIBER_ADDRESS },
  { PUT_PRODUCT_ID_HERE }
);

// SubscriptionRecord (throws Error if not subscribed)
console.log(subscriberBox);
// ... rest of your code

Unsubscribing:

// ... your code
const deleteResult = await SubtopiaClient.unsubscribe(
  {
    subscriber: {
      address: { PUT_SUBSCRIBER_ADDRESS },
      signer: { PUT_SUBSCRIBER_SIGNER },
    },
    smiID: { PUT_INFRASTRUCTURE_ID },
  },
  {
    client: { PUT_ALGOD_CLIENT },
  }
);

// ID of the deleted subscription ASA
console.log(deleteResult.returnValue);
// ... your code

Transfering subscription:

// ... your code
const transferResult = await SubtopiaClient.transferSubscriptionPass(
  {
    newOwnerAddress: { PUT_NEW_OWNER_ADDRESS },
    oldOwner: {
      address: { PUT_OLD_OWNER_ADDRESS },
      signer: { PUT_OLD_OWNER_SIGNER },
    },
    smiID: { PUT_INFRASTRUCTURE_ID },
    subID: Number(result.returnValue),
  },
  { client: { PUT_ALGOD_CLIENT } }
);

// Transaction ID of the transfer transaction
console.log(deleteResult.txID);
// ... your code

Discounts

Creating a discount:

// ... your code

const discount = await SubtopiaClient.createDiscount(
  {
    creator: { address: {PUT_WALLET_ADDRESS}, signer: {PUT_WALLET_SIGNER} },
    smiID: { PUT_PRODUCT_ID_HERE }, // number - the ID of the SMI instance you want to subscribe to
    discount: {
      duration: DurationType // number - the type of expiration to apply. Also serves as static id for the discount.
      discountType: {PUT_DISCOUNT_TYPE_HERE} // number - the type of discount to apply. FIXED or PERCENTAGE
      discountValue: {PUT_DISCOUNT_VALUE_HERE} // number - the discount to be deducted from the subscription price
      expiresIn: {PUT_EXPIRATION_TIME_HERE} // (Optional) Set 0 for discount to never expire. Else set number of seconds to append to unix timestamp at time of creation.
    }, // number - the discount in percent
  },
  { client: {PUT_ALGOD_INSTANCE_HERE} } // object of type algosdk.Algodv2
);


console.log(discount.returnValue) // response is of type ABIResult

// ... rest of your code

Discount lookup:

// ... your code

const discount = await SubtopiaClient.getDiscountRecordForType(
  client,
  { PUT_PRODUCT_ID_HERE }
  { PUT_EXPIRATION_TYPE_HERE },
);

// DiscountRecord (throws Error if not found)
console.log(discount);
// ... rest of your code

Deleting a discount:

// ... your code

const deleteResult = await SubtopiaClient.deleteDiscount(
  {
    creator: {
      address: { PUT_SUBSCRIBER_ADDRESS },
      signer: { PUT_SUBSCRIBER_SIGNER },
    },
    smiID: { PUT_INFRASTRUCTURE_ID },
    duration: { PUT_EXPIRATION_TYPE_HERE },
  },
  {
    client: { PUT_ALGOD_CLIENT },
  }
);

// ID of the deleted discount ASA txn
console.log(deleteResult.txID);
// ... your code

⭐️ Stargazers

Special thanks to everyone who starred the repository ❤️

Stargazers repo roster for @subtopia-algo/subtopia-js

3.0.0-beta.30

6 months ago

3.0.0-beta.31

6 months ago

3.0.0-beta.32

6 months ago

3.0.0-beta.33

6 months ago

3.0.0-beta.34

6 months ago

3.0.0-beta.35

6 months ago

3.0.0-beta.27

7 months ago

3.0.0-beta.28

7 months ago

3.0.0-beta.29

7 months ago

3.0.0-beta.21

7 months ago

3.0.0-beta.22

7 months ago

3.0.0-beta.23

7 months ago

3.0.0-beta.24

7 months ago

3.0.0-beta.25

7 months ago

3.0.0-beta.26

7 months ago

3.0.0-beta.20

7 months ago

3.0.0-beta.19

7 months ago

3.0.0-beta.1

8 months ago

3.0.0-beta.3

8 months ago

3.0.0-beta.2

8 months ago

3.0.0-beta.5

8 months ago

3.0.0-beta.4

8 months ago

3.0.0-beta.7

8 months ago

3.0.0-beta.6

8 months ago

3.0.0-beta.9

8 months ago

3.0.0-beta.8

8 months ago

3.0.0-beta.10

8 months ago

3.0.0-beta.11

8 months ago

3.0.0-beta.12

8 months ago

3.0.0-beta.13

8 months ago

3.0.0-beta.14

8 months ago

3.0.0-beta.15

8 months ago

3.0.0-beta.16

8 months ago

3.0.0-beta.17

8 months ago

3.0.0-beta.18

8 months ago

2.0.1

12 months ago

2.0.0

1 year ago

0.0.9

1 year ago

0.0.8

1 year ago

0.0.7

1 year ago

0.0.6

1 year ago

0.0.5

1 year ago

0.0.4

1 year ago

0.0.3

1 year ago

0.0.2

1 year ago

0.0.1

1 year ago

1.0.8

1 year ago

1.0.7

1 year ago

1.0.6

1 year ago

1.0.5

1 year ago

1.0.4

1 year ago

1.0.3

1 year ago

1.0.2

1 year ago

1.0.1

1 year ago

1.0.0

1 year ago

0.5.0

1 year ago

0.4.15

1 year ago

0.4.14

1 year ago

0.4.13

1 year ago

0.4.12

1 year ago

0.4.11

1 year ago

0.4.10

1 year ago

0.4.9

1 year ago

0.4.8

1 year ago

0.4.6

1 year ago

0.4.5

1 year ago

0.4.4

1 year ago

0.4.2

1 year ago

0.4.1

1 year ago

0.4.0

1 year ago

0.3.9

1 year ago

0.3.8

1 year ago

0.3.7

1 year ago

0.3.6

1 year ago

0.3.5

1 year ago

0.3.4

1 year ago

0.3.3

1 year ago

0.3.2

1 year ago

0.3.1

1 year ago

0.3.0

1 year ago

0.2.29

1 year ago

0.2.28

1 year ago

0.2.27

1 year ago

0.2.26

1 year ago

0.2.25

1 year ago

0.2.24

1 year ago

0.2.23

1 year ago

0.2.22

1 year ago

0.2.21

1 year ago

0.2.20

1 year ago

0.2.19

1 year ago

0.2.18

1 year ago

0.2.17

1 year ago

0.2.16

1 year ago

0.2.15

1 year ago

0.2.14

1 year ago

0.2.13

1 year ago

0.2.12

1 year ago

0.2.11

1 year ago

0.2.10

1 year ago

0.2.9

1 year ago

0.2.8

1 year ago

0.2.7

1 year ago

0.2.6

1 year ago

0.2.5

1 year ago

0.2.3

1 year ago

0.2.2

1 year ago

0.2.1

1 year ago

0.2.0

1 year ago

0.1.7

1 year ago

0.1.5

1 year ago

0.1.4

1 year ago

0.1.3

1 year ago

0.1.2

1 year ago

0.1.1

1 year ago

0.1.0

1 year ago