@meta-payer/sdk
v1.0.0
Published
## Overview
Readme
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:
npm install @meta-payer/sdk
yarn add @meta-payer/sdkConfiguration
| 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
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
const messageToSignResponse = await metaPayerAPI.generateMessageToSign(
"WALLET_ADDRESS"
);Sign authentication message to generate the signature
const signature = await signer.signMessage(messageToSignResponse.message);Create or Login User
const loginResponse = await metaPayerAPI.createOrLoginUser({
walletAddress: messageToSignResponse.walletAddress,
nonce: messageToSignResponse.nonce,
signature,
});Get User Payload
const user = await metaPayerAPI.getMe(loginResponse.token);Contract Module Integration
Get Card Balance
const balance = await metaPayerContract.getCardBalance(
"TOKEN_CONTRACT_ADDRESS",
"WALLET_ADDRESS"
);Check if Token is Supported
const isSupported = await metaPayerContract.isTokenSupported(
"TOKEN_CONTRACT_ADDRESS"
);Approve Token
const approveResponse = await metaPayerContract.approveToken(
signer,
{ tokenContractAddress: "TOKEN_CONTRACT_ADDRESS", amount: 10 }
);Top Up Card
const topUpResponse = await metaPayerContract.topUpCard(
signer,
{
tokenContractAddress: "TOKEN_CONTRACT_ADDRESS",
amount: 10
}
);Withdraw From Card
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.
import { ContractService, APIService } from "@meta-payer/sdk";License
MIT License
