@apip-io/wallet
v1.0.3
Published
apip.io Wallet SDK - BTC ETH USDT/USDC Payment Gateway with Contract Event Monitoring
Maintainers
Readme
@apip-io/wallet
apip.io Payment Gateway - BTC ETH USDT/USDC Payment Gateway SDK for Node.js
安装
npm install @apip-io/wallet使用方法
初始化
import { Apip } from '@apip-io/wallet';
// 从环境变量或配置中获取
const apip = new Apip({
uri: process.env.APIP_URL || 'https://apip.io/api/',
app_id: process.env.APIP_APP_ID,
app_key: process.env.APIP_APP_KEY
});环境变量配置
在 .env 文件中添加:
APIP_URL=https://apip.io/api/
APIP_APP_ID=your_app_id_here
APIP_APP_KEY=your_app_key_hereAPI 方法
创建钱包
// 创建所有协议的钱包
await apip.create('test_label');
// 创建指定协议
await apip.create('test_label', 'erc20');
// 支持多个协议多个币种
await apip.create('test_label', 'bsc20,erc20');
await apip.create('test_label', 'bnb,bsc20');查询余额
await apip.balance('test_label');导入钱包
await apip.import('bsc20', 'test_label', '0xwalletaddress', 'private_key');提现
// 使用热钱包提现
await apip.withdraw('1.00', '0x0000towallet', 'bsc20_usdt');
// 指定发送钱包来提现
await apip.withdraw('1.00', '0x0000towallet', 'bsc20_usdt', '0x000from_wallet');获取汇总数据
// 获取单个数据
await apip.data('bsc20_usdt');
// 支持多个协议多个币种
await apip.data('bnb,bsc20_usdt');汇总钱包
// 汇总指定币种
await apip.collect('bsc20_usdt');
// 支持多个协议多个币种
await apip.collect('bnb,bsc20_usdt');
// 使用默认参数 (bsc20_usdt,trc20_usdt)
await apip.collect();验证回调签名
在处理支付回调时,验证签名和请求参数:
// 在回调处理函数中
try {
apip.validate(request.body);
// 签名验证通过,继续处理
} catch (error) {
// 签名验证失败
console.error('Invalid callback:', error.message);
}工具方法
格式化以太坊数量 (uint256 -> 普通数值)
apip.formatUints('1000000000000000000', 18); // '1'
apip.formatUints('1000000', 6); // '1'转换为 uint256 格式 (普通数值 -> uint256)
apip.toUints('1', 18); // '1000000000000000000'
apip.toUints('1.5', 6); // '1500000'许可证
MIT
