Page cover

Code Examples

Practical code examples for interacting with Dollar Infinite via JavaScript (ethers.js recommended).

Common prerequisites for all examples:

javascript

const ethers = require('ethers');

// Basic configuration
const provider = new ethers.providers.JsonRpcProvider('https://bsc-dataseed.binance.org/');
const wallet = new ethers.Wallet(process.env.PRIVATE_KEY, provider); // use .env or hardware wallet

const VAULT_ADDRESS = '0x...'; // real Vault address (get from official site or BSCScan)
const USDT_ADDRESS = '0x55d398326f99059fF775485246999027B3197955';

// Minimal ABI (get complete from BSCScan)
const VAULT_ABI = [
  'function deposit(uint256 amount, uint8 lockDays) external',
  'function withdraw(uint256 positionId) external',
  'function getUserPositions(address user) external view returns (tuple(uint256 id, uint256 amount, uint8 lockDays, uint256 startTime, uint256 endTime, uint256 rewards)[])',
  'function getPendingRewards(uint256 positionId) external view returns (uint256)'
];

const vault = new ethers.Contract(VAULT_ADDRESS, VAULT_ABI, wallet);

Example 1: Approve USDT and Deposit (100 USDT, 10 days)

javascript

Example 2: Check Positions and Pending Rewards

javascript

Example 3: Withdraw (Withdraw matured position)

javascript

Example 4: Claim Affiliate Commissions (if available)

javascript

Usage Tips

  • Security: Never expose PRIVATE_KEY in frontend code or GitHub

  • Error Handling: Always use try/catch and parse revert reasons

  • Events: Monitor events like 'Deposited', 'Withdrawn' with provider.on()

  • Testing: Use small amounts ($10-50) to validate integration

  • Complete ABI: Always get from BSCScan to avoid errors

Warning: These are educational examples. Adapt to your case and verify official addresses/ABIs.

β†’ Next: AI Bot Overview

Last updated