Toolset for managing subscriptions on Ergo built with Fleet SDK
Built during ErgoHack VI
npm install sigma-subscriptions
import { SigmaSubscriptions } from 'sigma-subscriptions';
let manager = new SigmaSubscriptions(Network.Mainnet);
Set desired API url
let manager = new SigmaSubscriptions(Network.Mainnet, "https://api.ergoplatform.com/api/v1/");
const tx = await manager.createServiceConfig(ergo, name, description, fee, length);
const serviceConfigNFT = "a03c1503ab91a256ee9d256bd8cb3866c2803c2cca1450c33ced5f142d7b4cd7";
const tx = await manager.editServiceConfig(ergo, serviceConfigNFT, name, description, fee, length);
const tx = await manager.createService(ergo, serviceConfigNFT);
Set max number of subscriptions
const tx = await manager.createService(ergo, serviceConfigNFT, "100");
const serviceTokenId = "0c5b3144f8db88ce0fd78c0a7fd5f5681f4bc26382c6c4c0a964d99c14fb78c3";
const tx = await manager.subscribe(ergo, serviceTokenId);
const tx = await manager.renew(ergo, serviceTokenId);
const tx = await manager.cancel(ergo, serviceTokenId);
const subscriberBoxId = "2128567ba692bac62bce7c0d631e09862dbbb78e6cf5ee02154ecdf12e7b521e";
const tx = await manager.collect(ergo, subscriberBoxId);
const serviceTokenId = "0c5b3144f8db88ce0fd78c0a7fd5f5681f4bc26382c6c4c0a964d99c14fb78c3";
const auth: SigmaSubscriptionsAuthResponse = await manager.auth(ergo, serviceTokenId);
const services = await manager.getServices(serviceWalletAddress);
const subscriptions = await manager.getSubscriptions(serviceTokenId);
ErgoScript Contracts View All
Service Configuration Contract View
This contract is used to manage the settings for a given subscription service.
Subscribe Contract View
This contract is used to manage the distrubtion of subscription tokens, ensure the fee is sent to the correct subscription contract, and ensure the a correct subscription length is set.
Service Contract View
This contract holds the service fee. Its created on a subscribe and is used to enforce the renewal, cancel, and collect rules.
Config boxes are created to manage subscription services and are used as data inputs to ensure proper setup of subscriptions. They should contain the following.
- Service Config NFT
- R4: Service Address
- R5: Hash of Service Contract
- R6: Service Fee
- R7: Service Length (milliseconds)
- R8: Service Name
- R9: Service Description
Services are created with a configuation box and they will control the distribution of Service Tokens. They will contain the following.
- Service Tokens
- R4: Service Name
- R5: Service Description
- R6: 0 (Decimals in EIP-004 token standard)
- R7: Service Config NFT
Subscription boxes are created when the Subscribe box is spent. This will result in 2 Subscription tokens being minted with 1 sent to the Subscribe box and other sent to the Subsciber wallet. The Subscription box will contain the following.
- 1 Service Token from the Subscribe box
- 1 Subscription Token that is minted
- R4: Service Config NFT
- R5: Start date of service (unix timetamp in milliseconds)
- R6: End date of service (unix timetamp in milliseconds)
To renew a service contract the subscriber must send the correct fee along with their unique Subscription Token. The service box is then recreated, the previous fee is sent to the Service address, and the Start/End dates are adjusted.
To cancel a subscription the subscriber must send thier unique Subscription Token
- If the service start date has not been reached then a full refund is issued
- If the service is active then a partal refund is issued and the remaning fee is sent to the service
- THe Service Token and both Subscription Tokens are sent back to the service
The service can force collect the fee in this box if the service end date has passed.
A subscription is considered valid if there is a unspent Subscription Box containing the service token and a unique subscription token.
Distributed under the MIT License. See LICENSE
file for more information.
Discord: @cornbelt #sigma-subscriptions
Open source is the way.