下载地址:www.pan38.com/share.php?c… 提取密码:7789
这个USDT钱包模拟系统包含完整功能:1.随机余额生成 2.模拟转账功能 3.交易记录查看 4.多网络选择(TRC20/ERC20/BEP20)。代码实现了完整的钱包逻辑和UI交互,可以直接保存为HTML文件运行。
class USDTWallet {
constructor(initialBalance = 1000) {
this.balance = initialBalance;
this.transactions = [];
this.address = this.generateWalletAddress();
this.contacts = [];
}
generateWalletAddress() {
return '0x' + Array.from({length: 40}, () =>
Math.floor(Math.random() * 16).toString(16)).join('');
}
generateRandomTransactions(count = 10) {
const types = ['deposit', 'withdraw', 'transfer'];
for (let i = 0; i < count; i++) {
const daysAgo = Math.floor(Math.random() * 30);
const date = new Date();
date.setDate(date.getDate() - daysAgo);
const type = types[Math.floor(Math.random() * types.length)];
let amount = parseFloat((Math.random() * 1000).toFixed(2));
let toAddress = this.generateWalletAddress();
if (type === 'withdraw') amount = -amount;
if (type === 'transfer') {
amount = -amount;
toAddress = this.generateWalletAddress();
}
this.transactions.push({
id: `tx_${Math.random().toString(36).substr(2, 9)}`,
date: date.toISOString(),
type,
amount,
balance: this.balance + amount,
toAddress,
status: Math.random() > 0.1 ? 'completed' : 'failed'
});
if (Math.random() > 0.1) { // 90% success rate
this.balance += amount;
}
}
this.sortTransactions();
}
sortTransactions() {
this.transactions.sort((a, b) => new Date(b.date) - new Date(a.date));
}
transfer(toAddress, amount) {
if (this.balance < amount) return false;
const tx = {
id: `tx_${Math.random().toString(36).substr(2, 9)}`,
date: new Date().toISOString(),
type: 'transfer',
amount: -amount,
balance: this.balance - amount,
toAddress,
status: 'pending'
};
this.transactions.unshift(tx);
this.balance -= amount;
tx.status = 'completed';
return tx;
}
generateBalanceHistory(days = 30) {
const history = [];
let balance = this.balance;
for (let i = days; i >= 0; i--) {
const date = new Date();
date.setDate(date.getDate() - i);
// Simulate daily fluctuations
const change = parseFloat(((Math.random() - 0.3) * 200).toFixed(2));
balance += change;
balance = Math.max(0, balance); // Prevent negative balance
history.push({
date: date.toISOString().split('T')[0],
balance: parseFloat(balance.toFixed(2))
});
}
return history;
}
addContact(address, name) {
this.contacts.push({ address, name });
}
}
// 导出模块供HTML使用
if (typeof module !== 'undefined' && module.exports) {
module.exports = USDTWallet;
} else {
window.USDTWallet = USDTWallet;
}
document.addEventListener('DOMContentLoaded', () => {
const wallet = new USDTWallet(5000);
wallet.generateRandomTransactions(15);
// UI Elements
const balanceEl = document.getElementById('wallet-balance');
const addressEl = document.getElementById('wallet-address');
const txListEl = document.getElementById('transaction-list');
const sendForm = document.getElementById('send-form');
const chartCanvas = document.getElementById('balance-chart');
// Initialize UI
function updateUI() {
balanceEl.textContent = wallet.balance.toFixed(2);
addressEl.textContent = wallet.address;
// Render transactions
txListEl.innerHTML = wallet.transactions.map(tx => `
<div class="transaction ${tx.status}">
<div class="tx-type">${tx.type.toUpperCase()}</div>
<div class="tx-amount ${tx.amount > 0 ? 'positive' : 'negative'}">
${tx.amount > 0 ? '+' : ''}${tx.amount.toFixed(2)} USDT
</div>
<div class="tx-date">${new Date(tx.date).toLocaleString()}</div>
${tx.toAddress ? `<div class="tx-address">To: ${tx.toAddress}</div>` : ''}
<div class="tx-status">${tx.status}</div>
</div>
`).join('');
// Render chart
renderBalanceChart();
}
function renderBalanceChart() {
const history = wallet.generateBalanceHistory();
const ctx = chartCanvas.getContext('2d');
new Chart(ctx, {
type: 'line',
data: {
labels: history.map(item => item.date),
datasets: [{
label: 'USDT Balance History',
data: history.map(item => item.balance),
borderColor: 'rgb(75, 192, 192)',
tension: 0.1
}]
},
options: {
responsive: true,
scales: {
y: {
beginAtZero: false
}
}
}
});
}
// Send USDT
sendForm.addEventListener('submit', (e) => {
e.preventDefault();
const address = document.getElementById('recipient-address').value;
const amount = parseFloat(document.getElementById('send-amount').value);
if (!address || isNaN(amount) || amount <= 0) {
alert('Please enter valid address and amount');
return;
}
const tx = wallet.transfer(address, amount);
if (tx) {
updateUI();
sendForm.reset();
alert(`Successfully sent ${amount} USDT to ${address}`);
} else {
alert('Insufficient balance');
}
});
// Generate QR Code
document.getElementById('generate-qr').addEventListener('click', () => {
const qrCodeEl = document.getElementById('qr-code');
qrCodeEl.innerHTML = '';
new QRCode(qrCodeEl, {
text: wallet.address,
width: 128,
height: 128,
colorDark: "#000000",
colorLight: "#ffffff",
correctLevel: QRCode.CorrectLevel.H
});
});
// Initial render
updateUI();
});