Code Monkey home page Code Monkey logo

subtopia-js-sdk's Introduction

npm version


🌟 About

Subtopia JS SDK is a JavaScript library for interacting with the Subtopia Platform. It provides a simple interface for creating and managing Products (Contracts that are responsible for subscription management).

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-sdk

# or with yarn
yarn add subtopia-js-sdk

Import the package:

import { SubtopiaClient, SubtopiaRegistryClient } from "subtopia-js-sdk";

πŸ› οΈ Usage

Example snippets of using the Subtopia JS SDK.

Subscriptions

Purchasing a subscription:

import {
  SubtopiaClient,
  SubtopiaRegistryClient,
  ChainType,
  SUBTOPIA_REGISTRY_ID
} from "subtopia-js-sdk";
// ...  your code

const subtopiaClient = await SubtopiaClient.init({
  algodClient: PUT_ALGOD_INSTANCE_HERE,
  chainType: PUT_CHAIN_TYPE_ENUM_HERE // 'testnet'|'mainnet'|'localnet'
  productID: PUT_PRODUCT_ID_HERE,
  registryID: SUBTOPIA_REGISTRY_ID(ChainType.{YOUR_CHAIN_TYPE_HERE}),
  creator: { addr: PUT_WALLET_ADDRESS, signer: PUT_WALLET_SIGNER },
});

const response = await subtopiaClient.createSubscription(
  { subscriber: { addr: PUT_WALLET_ADDRESS, signer: PUT_WALLET_SIGNER } },
);

console.log(response.txID); // response is of type string

// ... rest of your code

Subscription lookup:

// ... your code
const subscriptionRecord = await subtopiaClient.getSubscription({
  subscriberAddress: PUT_SUBSCRIBER_ADDRESS,
  algodClient: PUT_ALGOD_INSTANCE_HERE,
});

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

Unsubscribing:

// ... your code
const deleteResult = await subtopiaClient.deleteSubscription({
  subscriber: {
    addr: PUT_SUBSCRIBER_ADDRESS,
    signer: PUT_SUBSCRIBER_SIGNER,
  },
  subscriptionID: PUT_SUBSCRIPTION_ID,
});

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

Transfering subscription:

// ... your code
const transferResult = await subtopiaClient.transferSubscription({
  oldSubscriber: {
    addr: PUT_OLD_SUBSCRIBER_ADDRESS,
    signer: PUT_OLD_SUBSCRIBER_SIGNER,
  },
  newSubscriberAddress: PUT_NEW_SUBSCRIBER_ADDRESS,
  subscriptionID: PUT_SUBSCRIPTION_ID,
});

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

Discounts

Creating a discount:

// ... your code

const subtopiaRegistryClient = await SubtopiaRegistryClient.init({
  algodClient: PUT_ALGOD_INSTANCE_HERE,
  creator: { addr: PUT_WALLET_ADDRESS, signer: PUT_WALLET_SIGNER },
  chainType: PUT_CHAIN_TYPE_HERE,
});

const discount = await subtopiaRegistryClient.createDiscount({
  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.
});

console.log(discount.txID); // response is of type string

// ... rest of your code

Discount lookup:

// ... your code

const discount = await subtopiaClient.getDiscount();

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

Deleting a discount:

// ... your code

const deleteResult = await subtopiaRegistryClient.deleteDiscount();

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

⭐️ Stargazers

Special thanks to everyone who starred the repository ❀️

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

subtopia-js-sdk's People

Contributors

aorumbayev avatar github-actions[bot] avatar renovate[bot] avatar semantic-release-bot avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

subtopia-js-sdk's Issues

Dependency Dashboard

This issue lists Renovate updates and detected dependencies. Read the Dependency Dashboard docs to learn more.

Awaiting Schedule

These updates are awaiting their schedule. Click on a checkbox to get an update now.

  • chore(deps): update all non-major dependencies (@types/node, @types/react, @vitejs/plugin-react)
  • chore(deps): update dependency conventional-changelog-conventionalcommits to v8
  • chore(deps): update dependency eslint to v9
  • chore(deps): update dependency eslint-config-prettier to v9
  • chore(deps): update dependency eslint-plugin-prettier to v5
  • chore(deps): update dependency prettier to v3
  • chore(deps): update dependency semantic-release to v23
  • chore(deps): update dependency stylelint to v16
  • chore(deps): update dependency stylelint-config-recommended to v14
  • chore(deps): update dependency stylelint-config-sass-guidelines to v11
  • chore(deps): update dependency vite to v5
  • chore(deps): update typescript-eslint monorepo to v7 (major) (@typescript-eslint/eslint-plugin, @typescript-eslint/parser)
  • chore(deps): update vitest monorepo to v1 (major) (@vitest/coverage-v8, vitest)
  • chore(deps): lock file maintenance

Open

These updates have all been created already. Click a checkbox below to force a retry/rebase of any.

Detected dependencies

github-actions
.github/actions/setup-subtopia-registry/action.yaml
  • actions/checkout v4
  • actions/setup-python v5
.github/workflows/cicd.yaml
  • actions/checkout v4
  • actions/setup-node v4
  • actions/checkout v4
  • actions/setup-node v4
  • actions/checkout v4
  • actions/setup-node v4
  • codecov/codecov-action v3
  • actions/checkout v4
  • actions/setup-node v4
  • JamesIves/github-pages-deploy-action v4
  • actions/checkout v4
  • actions/setup-node v4
.github/workflows/prod_release.yaml
  • actions/checkout v4
  • devmasx/merge-branch 6ec8363d74aad4f1615d1234ae1908b4185c4313
  • devmasx/merge-branch 6ec8363d74aad4f1615d1234ae1908b4185c4313
npm
package.json
  • @feki.de/semantic-release-yarn 1.0.1
  • @semantic-release/changelog 6.0.3
  • @semantic-release/git 10.0.1
  • @types/node ^20.0.0
  • @types/react ^18.0.26
  • @types/react-dom ^18.0.9
  • @typescript-eslint/eslint-plugin ^5.46.0
  • @typescript-eslint/parser ^5.46.0
  • @vitejs/plugin-react ^4.0.0
  • @vitest/coverage-v8 ^0.34.3
  • commitizen 4.3.0
  • conventional-changelog-conventionalcommits ^6.0.0
  • cz-conventional-changelog 3.3.0
  • dotenv ^16.3.1
  • dts-bundle-generator ^8.0.0
  • eslint ^8.29.0
  • eslint-config-prettier ^8.5.0
  • eslint-plugin-prettier ^4.2.1
  • prettier ^2.8.1
  • semantic-release 21.1.2
  • stylelint ^14.16.0
  • stylelint-config-recommended ^9.0.0
  • stylelint-config-sass-guidelines ^9.0.1
  • ts-node ^10.9.1
  • tslib ^2.6.2
  • typescript ^5.2.2
  • vite ^4.0.0
  • vitest ^0.34.6
  • @algorandfoundation/algokit-utils ^5.0.1
  • algosdk ^2.7.0

  • Check this box to trigger a request for Renovate to run again on this repository

The automated release is failing 🚨

🚨 The automated release from the main branch failed. 🚨

I recommend you give this issue a high priority, so other packages depending on you can benefit from your bug fixes and new features again.

You can find below the list of errors reported by semantic-release. Each one of them has to be resolved in order to automatically publish your package. I’m sure you can fix this πŸ’ͺ.

Errors are usually caused by a misconfiguration or an authentication problem. With each error reported below you will find explanation and guidance to help you to resolve it.

Once all the errors are resolved, semantic-release will release your package the next time you push a commit to the main branch. You can also manually restart the failed CI job that runs semantic-release.

If you are not sure how to resolve this, here are some links that can help you:

If those don’t help, or if this issue is reporting something you think isn’t right, you can always ask the humans behind semantic-release.


Cannot push to the Git repository.

semantic-release cannot push the version tag to the branch main on the remote Git repository with URL https://x-access-token:[secure]@github.com/subtopia-algo/subtopia-js.

This can be caused by:


Good luck with your project ✨

Your semantic-release bot πŸ“¦πŸš€

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. πŸ“ŠπŸ“ˆπŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.