npm package: @meta-payer/sdk
Description: ## Overview
Latest version: 1.0.0

# Meta Payer SDK Documentation

## Overview

The Meta Payer SDK (`@meta-payer/sdk`) is a powerful tool designed for seamless integration and interaction with the Meta Payer system. It offers methods to interface with both API and smart contract modules, allowing users to perform actions such as authentication, account top-ups, withdrawals, subscription creation, and more.

## Installation

You can install the Meta Payer SDK in your project using npm or yarn:

```bash
npm install @meta-payer/sdk

yarn add @meta-payer/sdk
```

## Configuration

| Network  | RPC URL                                   | Chain ID | Contract Address                              |
|----------|-------------------------------------------|---------:|-----------------------------------------------|
| testnet  | `https://bsc-testnet.public.blastapi.io`  |       97 | `0x84196b81F5B59aEe3ac522dc80B0edE493d7B4F2`  |
| mainnet  | `https://bsc-dataseed.binance.org`        |       56 | `                                          `  |


## Supported Stable Tokens

| Network  | Token Address                                | Token Name |
|----------|----------------------------------------------|------------|
| testnet  | `0xcc33adE421C91d7dCa5829D7D5b5Fe7216971a5A` | USDC       |
| mainnet  | `                                          ` | USDC       |


### Initialization

```typescript
import { MetaPayerSDK, Env } from "@meta-payer/sdk";

const { metaPayerAPI, metaPayerContract, metaPayerConfig } = MetaPayerSDK({
  apiKey: "YOUR_API_KEY", // Replace with your API key
  env: Env.TestNet, // Specify the environment (TestNet, MainNet) Testnet is the default
  metaPayerContractAddress: "META_PAYER_CONTRACT_ADDRESS", // Uses the default config if not provided
});
```

## Usage

### API Module Integration

Generate Message to sign for user authentication

```typescript
const messageToSignResponse = await metaPayerAPI.generateMessageToSign(
  "WALLET_ADDRESS"
);
```

Sign authentication message to generate the signature

```typescript
const signature = await signer.signMessage(messageToSignResponse.message);
```

Create or Login User

```typescript
const loginResponse = await metaPayerAPI.createOrLoginUser({
  walletAddress: messageToSignResponse.walletAddress,
  nonce: messageToSignResponse.nonce,
  signature,
});
```

Get User Payload

```typescript
const user = await metaPayerAPI.getMe(loginResponse.token);
```

### Contract Module Integration

Get Card Balance

```typescript
const balance = await metaPayerContract.getCardBalance(
  "TOKEN_CONTRACT_ADDRESS",
  "WALLET_ADDRESS"
);
```

Check if Token is Supported

```typescript
const isSupported = await metaPayerContract.isTokenSupported(
  "TOKEN_CONTRACT_ADDRESS"
);
```

Approve Token

```typescript
const approveResponse = await metaPayerContract.approveToken(
  signer,
  { tokenContractAddress: "TOKEN_CONTRACT_ADDRESS", amount: 10 }
);
```

Top Up Card

```typescript
const topUpResponse = await metaPayerContract.topUpCard(
  signer,
  { 
    tokenContractAddress: "TOKEN_CONTRACT_ADDRESS", 
    amount: 10 
  }
);
```

Withdraw From Card

```typescript
const withdrawResponse = await metaPayerContract.withdrawCard(
  signer,
  {
  tokenContractAddress: "TOKEN_CONTRACT_ADDRESS",
  amount: 10,
  }
);
```

## Types

To facilitate type safety and ensure seamless integration, we've exported the `ContractService` and `APIService` classes. You can now import these classes directly from the SDK to use their typings in your project.

```typescript
import { ContractService, APIService } from "@meta-payer/sdk";
```

## License

MIT License