sub2
  • sub2 protocol
  • Concepts
    • Subscription
    • Fees
    • Fee auction
    • Sponsored subscriptions
    • Processors
  • Deployments
  • SDK
    • Query subscriptions
    • Listen for incoming subscriptions
    • Listen for canceled subscriptions
    • Listen for incoming payments
    • Sponsor subscriptions
    • Check if user is a payed subscriber
    • Cancel subscription
    • Process payments
    • Query active subscriptions to recipient
    • Query active subscriptions from sender
  • Popup integration
  • Become a payment processor
  • Technical Reference
  • DAO
Powered by GitBook
On this page
  • Overview
  • Installation and setup

SDK

PreviousDeploymentsNextQuery subscriptions

Last updated 9 months ago

Overview

The sub2 SDK is a Node library to interact with the sub2 protocol in a typescript/javascript environment. It is built with and contains functionality that makes it easy to integrate sub2 as a receiver of subscription payments among other features. The implementation can be found .

Interactions requiring querying on-chain data require the user to supply a viem public client. Some functionality like canceling a subscription or generating a sponsor signature requires the user to additionally supply a viem wallet client.

Installation and setup

The SDK can be installed through npm.

npm i --save sub2-sdk

After installation, the SDK contains a class called Sub2SDK which can be initialized as follows:

import { Sub2SDK } from 'sub2-sdk';
import { publicClient, walletClient } from "./config";

const sub2SDK = new Sub2SDK(publicClient, walletClient);
import { createPublicClient, createWalletClient, http, PublicClient, WalletClient } from 'viem';
import { privateKeyToAccount } from 'viem/accounts';
import { baseSepolia } from 'viem/chains';

export const publicClient: PublicClient = createPublicClient({
  chain: baseSepolia,
  transport: http()
}) as PublicClient;

export const walletClient: WalletClient = createWalletClient({
  account: privateKeyToAccount('0x...'),
  chain: baseSepolia,
  transport: http()
});

Now you are ready to start interacting with the sub2 protocol!

Careful: Remember to never store your private key and RPC URL in plain text in your project. We recommend creating and using a .env file.

Note: The sub2 protocol is currently only deployed on the Base Sepolia network.

viem
here