Basic Setup

Basic setup of Azoth SDK – creating provider, signer, and SDK instance.

Creating a Provider and Signer

First, you need to set up an Ethereum provider and (optionally) a signer:

import { ethers } from 'ethers';

// Read-only provider
const provider = new ethers.JsonRpcProvider('https://polygon-rpc.com');

// For transactions, you need a signer
// Option 1: Using a private key (server-side)
const privateKey = 'YOUR_PRIVATE_KEY'; // Never hardcode this in production!
const signer = new ethers.Wallet(privateKey, provider);

// Option 2: Using a browser wallet like MetaMask (client-side)
// This assumes window.ethereum is available
const provider = new ethers.BrowserProvider(window.ethereum);
const signer = await provider.getSigner();

Creating an Azoth SDK Instance

Once you have a provider or signer, you can create an Azoth SDK instance:

import { 
  AzothSDK, 
  RatePeriod, 
  formatInput, 
  formatOutput, 
  convertRateToPeriod 
} from '@azothpay/sdk';

// With a signer (for transactions)
const azoth = AzothSDK.create(signer, 'polygon', 'USDT');

// Or with just a provider (for read-only operations)
const readOnlyAzoth = AzothSDK.create(provider, 'polygon', 'USDT');

Parameters

  • provider or signer: An ethers.js Provider or Signer

  • network: Blockchain network to use (default: 'polygon')

    • Available: 'polygon', 'bsc', 'avalanche', 'base', 'scroll', 'arbitrum', 'mainnet', 'sei', 'zksync'

  • tokenSymbol: Stablecoin to use (default: 'USDT')

    • Available: 'USDT', 'USDC', 'PYUSD' (availability varies by network)

  • contractVersion: Optional contract version (defaults to the latest for the selected network)

Last updated