Main API

Browser-compatible JavaScript API client for AzothPay Streaming payments, subscriptions, and revenue splits with no axios dependency.

✅ Works in modern browsers

✅ Uses native fetch()

✅ Non-custodial, signer-based transaction execution

✅ Supports USDT/USDC on Polygon and L2s (Arbitrum, Base, etc.)


📦 Installation

npm install @azothpay/api ethers

ℹ️ Requires ethers.js (v5 or v6). For browser bundles, use [email protected] or the ESM build of ethers@6.


🚀 Quick Start

import { AzothPayApiClient } from '@azothpay/api/browser';
import { ethers } from 'ethers';

// 1. Connect user wallet (MetaMask / WalletConnect)
const provider = new ethers.providers.Web3Provider(window.ethereum);
const signer = provider.getSigner();

// 2. Create AzothPay client
const client = new AzothPayApiClient(
  'https://azothpay.com',     // production endpoint
  'bsc-usdc',                 // 'bsc-usdc' | 'bsc-usdt' | 'pol-usdc'| 'pol-usdt' 
  'your-api-key'              // issued after KYB and onboarding
);

// 3. Create and send a subscription in one call
const receipt = await client.createSubscriptionAndSend(
  {
    author: '0x742d35Cc6634C0532925a3b8D4C9f2a93A9E3F1A', // creator or merchant address
    subscriptionRate: '50000000000000000000',             // 50 USDT (18 decimals)
    projectId: 0 
  },
  signer,
  1 // number of confirmations
);

⚙️ Client Initialization

Constructor Parameters

Param
Type
Required
Description

baseUrl

string

API base URL, e.g. 'https://azothpay.com'

contract

string

Contract identifier: 'bsc-usdc', 'bsc-usdt', 'pol-usdc', 'pol-usdt'

apiKey

string

API key (issued by AzothPay during onboarding)

provider

ethers.providers.Provider

Web3 provider, can be set later via .setProvider()

🔐 Header x-api-key is automatically added to all HTTP requests.


🔎 API Introspection

getAvailableContracts()

Returns list of supported contracts:

Method
Returns
Description

getAvailableContracts()

Promise<{ name: string, address: string }[]>

Available AzothPay contracts


📰 Subscriptions

Core methods to work with subscriptions.

Method
Params
Returns
Description

createSubscription(params)

{ author, subscriptionRate, projectId }

Promise<TransactionResponse>

Builds a subscription tx (not sent)

createSubscriptionAndSend(params, signer, confirmations?)

Promise<TransactionReceipt>

Creates, signs and sends a subscription

cancelSubscription(author, params)

author, { from }

Promise<TransactionResponse>

Builds a cancel-subscription tx

cancelSubscriptionAndSend(...)

author, params, signer, confirmations?

Promise<TransactionReceipt>

Cancels subscription and sends tx

listSubscriptions(address)

string

Promise<{ subscriptions: Subscription[] }>

Lists active subscriptions for an address

📌 subscriptionRate is in token smallest units (wei-like). For USDT/USDC (18 decimals), multiply USD amount by 1e18: 50 USDT → '50000000000000000000'.


💸 Payments & Funds

One-off payments

Method
Params
Returns
Description

makePayment(params)

{ from, to, amount, projectId? }

Promise<TransactionResponse>

Builds a one-off payment transaction

makePaymentAndSend(...)

params, signer, confirmations?

Promise<TransactionReceipt>

Signs and sends a payment

📌 amount is in token smallest units (wei-like). For USDT/USDC (18 decimals), multiply USD amount by 1e18: 50 USDT → '50000000000000000000'.

Deposits & withdrawals

Method
Params
Returns
Descriptions

depositFunds(params)

{ from, amount }

Promise<TransactionResponse>

Builds a deposit transaction

depositFundsAndSend(...)

params, signer, confirmations?

Promise<TransactionReceipt>

Deposits and sends tx

withdrawFunds(params)

{ from, amount, to? }

Promise<TransactionResponse>

Builds a withdraw transaction

withdrawFundsAndSend(...)

params, signer, confirmations?

Promise<TransactionReceipt>

Withdraws and sends tx

📌 amount in withdrawFunds() in token smallest units (wei-like). For USDT/USDC (18 decimals), multiply USD amount by 1e18: 50 USDT → '50000000000000000000'. 📌 amount in depositFunds() in token should be same as for native token. example: USDT on Polygon (6 decimals), multiply USD amount by 1e6: 50 USDT → '50000000'.

Balance & active streams

Method
Params
Returns
Descriptions

getBalance(...)

address

Promise<{ balance: string, streamingOut: string, streamingIn: string[] }>

Balance and active streams for address


⚡ Advanced Operations

Some clients use additional methods for gas optimization and bulk operations.

Method
Params
Description

createBatchSubscriptions(...)

{ items: { author, rate, projectId }[] }

Creates multiple subscriptions in a single call

processBatchPayments(...)

{ items: { to, amount }[] }

Bulk payouts (affiliates, models, partners)

liquidateAccount(params)

{ from, target }

Forced liquidation when funds are insufficient

getAnalytics(params?)

{ projectId?, startDate?, endDate? }

Basic analytics for flows and revenue

ℹ️ Availability of specific methods depends on contract version and project configuration. Please confirm with the AzothPay team during integration.


✍️ Manual Signing & Sending

If you want to separate tx preparation from signing/sending, use low-level helpers:

Signing helpers

Method
Description

signAndSendTransaction(tx, signer)

Signs and sends a transaction. Returns TransactionResponse.

signAndSendTransactionAndWait(tx, signer, confirmations = 1)

Signs, sends and waits for N confirmations. Returns TransactionReceipt.

This approach is useful if you want to log, modify, or batch transactions before sending them.


🔧 Provider & HTTP Configuration

Changing provider after initialization

HTTP settings

All calls use fetch() with:

  • default timeout: 10 seconds;

  • default headers:

There is a low-level _makeRequest() method that allows overriding headers/timeouts, but it is not recommended to use it directly in production.


🚨 Error Handling

All methods throw exceptions with readable messages:

Typical error categories:

  • validation errors (400 Bad Request);

  • missing permissions / invalid apiKey (401/403);

  • network errors (Request timeout, Failed to fetch, etc.);

  • on-chain errors (contract revert) depending on business logic.

We recommend logging both HTTP status and response body to simplify debugging.


ℹ️ Meta-transactions

This package implements direct signer-based on-chain transactions.

Gasless / meta-transaction support is provided by a separate client AzothPayMetaApiClient and requires a relayer service.

⚠️ To enable meta-transactions (EIP-712, gasless UX), please contact the AzothPay team.

Meta API

📬 Support & Contacts

Last updated