apip.io Wallet SDK - BTC ETH USDT/USDC Payment Gateway with Contract Event Monitoring
npm install @apip-io/walletapip.io Payment Gateway - BTC ETH USDT/USDC Payment Gateway SDK for Node.js
``bash`
npm install @apip-io/wallet
`javascript
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 文件中添加:
`env`
APIP_URL=https://apip.io/api/
APIP_APP_ID=your_app_id_here
APIP_APP_KEY=your_app_key_here
#### 创建钱包
`javascript
// 创建所有协议的钱包
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');
`
#### 查询余额
`javascript`
await apip.balance('test_label');
#### 导入钱包
`javascript`
await apip.import('bsc20', 'test_label', '0xwalletaddress', 'private_key');
#### 提现
`javascript
// 使用热钱包提现
await apip.withdraw('1.00', '0x0000towallet', 'bsc20_usdt');
// 指定发送钱包来提现
await apip.withdraw('1.00', '0x0000towallet', 'bsc20_usdt', '0x000from_wallet');
`
#### 获取汇总数据
`javascript
// 获取单个数据
await apip.data('bsc20_usdt');
// 支持多个协议多个币种
await apip.data('bnb,bsc20_usdt');
`
#### 汇总钱包
`javascript
// 汇总指定币种
await apip.collect('bsc20_usdt');
// 支持多个协议多个币种
await apip.collect('bnb,bsc20_usdt');
// 使用默认参数 (bsc20_usdt,trc20_usdt)
await apip.collect();
`
#### 验证回调签名
在处理支付回调时,验证签名和请求参数:
`javascript`
// 在回调处理函数中
try {
apip.validate(request.body);
// 签名验证通过,继续处理
} catch (error) {
// 签名验证失败
console.error('Invalid callback:', error.message);
}
#### 格式化以太坊数量 (uint256 -> 普通数值)
`javascript`
apip.formatUints('1000000000000000000', 18); // '1'
apip.formatUints('1000000', 6); // '1'
#### 转换为 uint256 格式 (普通数值 -> uint256)
`javascript``
apip.toUints('1', 18); // '1000000000000000000'
apip.toUints('1.5', 6); // '1500000'
MIT