jack vor 4 Monaten
Ursprung
Commit
a0c656c436

+ 1 - 1
project/pharos/AccountList.txt

@@ -1 +1 @@
-0x618a59dcbbc05a38e10b9872f50855c1b52dd01baced785a7134876ba404be1b
+0x4b833cf91c19c4d9434ffed4b18714ef032d2acf44caec110a1c2c7db151eb65

+ 83 - 0
project/pharos/Contract.mjs

@@ -0,0 +1,83 @@
+import {ethers} from "ethers";
+
+// 配置 provider,明确指定 chainId 并禁用 ENS
+const provider = new ethers.JsonRpcProvider("https://testnet.dplabs-internal.com");
+
+const privateKey = "0x4b833cf91c19c4d9434ffed4b18714ef032d2acf44caec110a1c2c7db151eb65";
+const wallet = new ethers.Wallet(privateKey, provider);
+
+const contractAddress = "0x76aaada469d23216be5f7c596fa25f282ff9b364";
+
+const contractABI = [
+    "function deposit() public"
+];
+
+async function validateSetup() {
+    try {
+        // 验证钱包地址
+        if (!ethers.isAddress(wallet.address)) {
+            throw new Error("Invalid wallet address derived from private key");
+        }
+        console.log("Wallet address:", wallet.address);
+
+        // 检查账户余额
+        const balance = await provider.getBalance(wallet.address);
+        console.log("Wallet balance:", ethers.formatEther(balance), "PHRS");
+        if (balance === 0n) {
+            throw new Error("Wallet has no balance to pay for gas");
+        }
+
+        // 验证合约地址
+        if (!ethers.isAddress(contractAddress)) {
+            throw new Error("Invalid contract address");
+        }
+
+        // 检查合约是否部署
+        const code = await provider.getCode(contractAddress);
+        if (code === "0x") {
+            throw new Error("No contract deployed at the specified address");
+        }
+        console.log("Contract is deployed at:", contractAddress);
+
+        // 检查网络连接
+        const network = await provider.getNetwork();
+        console.log("Connected to network:", network);
+    } catch (error) {
+        console.error("Validation failed:", error.message);
+        process.exit(1);
+    }
+}
+
+// 发送交易
+async function deposit() {
+    try {
+        // 验证设置
+        await validateSetup();
+
+        // 初始化合约
+        const contract = new ethers.Contract(contractAddress, contractABI, wallet);
+
+        // 获取交易参数
+        const nonce = await provider.getTransactionCount(wallet.address, "pending");
+        const gasPrice = (await provider.getFeeData()).gasPrice;
+
+        // 发送交易
+        const tx = await contract.deposit({
+            nonce,
+            gasPrice,
+            gasLimit: 100000 // 根据合约需求调整
+        });
+
+        console.log("Transaction sent:", tx.hash);
+
+        // 等待交易确认
+        const receipt = await tx.wait();
+        console.log("Transaction confirmed in block:", receipt.blockNumber);
+    } catch (error) {
+        console.error("Error sending transaction:", error);
+        process.exit(1);
+    }
+}
+
+// 执行 deposit 函数
+deposit();

+ 65 - 0
project/pharos/balanceAndNonce.mjs

@@ -0,0 +1,65 @@
+import {ethers} from "ethers";
+import fs from 'fs/promises';
+import path from 'path';
+import {fileURLToPath} from 'url';
+
+// 使用 ethers.js 的 Provider
+const rpcUrl = 'https://testnet.dplabs-internal.com';
+const provider = new ethers.JsonRpcProvider(rpcUrl);
+
+// 读取私钥文件
+const __filename = fileURLToPath(import.meta.url);
+const __dirname = path.dirname(__filename);
+const filePath = path.join(__dirname, './AccountList.txt');
+
+async function getBalance(privateKey) {
+    try {
+        const wallet = new ethers.Wallet(privateKey, provider);
+
+        // 获取账户余额
+        const balance = await provider.getBalance(wallet.address);
+
+        // 将余额从 wei 转换为 ether
+        const balanceInEther = ethers.formatEther(balance);
+
+        console.log(`Address: ${wallet.address}`);
+        console.log(`Balance: ${balanceInEther} PHRS`);
+    } catch (error) {
+        console.error(`Error getting balance for private key: ${privateKey}`);
+        console.error(error);
+    }
+}
+
+async function getNonces(privateKey, countNum) {
+    try {
+        const wallet = new ethers.Wallet(privateKey, provider);
+
+        // 获取最新的 nonce
+        const nonceLatest = await provider.getTransactionCount(wallet.address, 'latest');
+        const noncePending = await provider.getTransactionCount(wallet.address, 'pending');
+        console.log(`pending nonce: ${noncePending} ; latest nonce: ${nonceLatest}`);
+    } catch (error) {
+        console.error('获取 nonce 时发生错误:', error.message);
+    }
+}
+
+async function main() {
+    let privateKeys;
+    try {
+        const data = await fs.readFile(filePath, 'utf8');
+        privateKeys = data.split('\n').filter(line => line.trim() !== '');
+    } catch (err) {
+        console.error('读取文件时发生错误:', err);
+        process.exit(1);
+    }
+
+    let countNum = 1;
+    for (const privateKey of privateKeys) {
+        await getBalance(privateKey);
+        await getNonces(privateKey);
+        console.log('-----------------------------');
+        countNum++;
+    }
+}
+
+main();

+ 0 - 107
project/pharos/query_balance_and_nonce.py

@@ -1,107 +0,0 @@
-# -*- coding: utf-8 -*-
-from web3 import Web3
-import time
-
-# 设置 RPC URL
-rpc_url = 'https://testnet.dplabs-internal.com'
-
-# 初始化 web3.py 提供器
-w3 = Web3(Web3.HTTPProvider(rpc_url))
-
-
-# 检查是否连接成功
-def check_connection():
-    try:
-        network_id = w3.eth.chain_id
-        print(f"已成功连接到链节点,网络ID为: {network_id}。正在查询钱包余额...")
-        return True
-    except Exception as e:
-        print("无法连接到链节点,请检查 URL 是否正确")
-        return False
-
-
-# 钱包地址列表
-wallet_addresses = [
-    '0x801990bd7f37ea4be3ed1853f70dd697e1365bd8',
-    '0xe50B77Cd771243b8Ae1d6ce33b4E13ECC5Fa28a6',
-    '0x9ea2ECAD4090E32916e03b77d7C75CbF6C8E0A55',
-    '0xE8A4b0C04300154DC9B1D0e565Ba70F996614690',
-    '0x1b623c5d70c93b437d93c305bf2cfa389095f636',
-    '0x06D25c3e0E1F753ac0486a3f8aaD7259149656cB',
-    '0x15cFEE34Ca4541CAc9a1c4B6F6aB47A65877E240',
-    '0x7aBF0dA8Ac07B6dE7206e467988455E1AD0b60B5',
-    '0xF736f45d4663a8D8DfF7EFA55b1Cf6Fe38D026c8',
-    '0x83173eECf3a6d9ABB79682568e16c2eAd361620e',
-    '0xa401b85B4849Fc7610Bd180cc937859C78528F47',
-    '0x10A43E7Fe77E2D84adBeC26cF0bFc6f403841266',
-    '0x70D5EE1DfddD3726f0D71F4CD5a8Ef43aC651a75'
-]
-
-
-def query_balances(wallet_num, wallet_address):
-    retry_count = 0
-    max_retries = 3
-    delay = 2  # 延迟时间,单位为秒
-
-    result_message = ""
-    result_balance = -1
-
-    # 转换为校验和地址
-    try:
-        checksum_address = w3.to_checksum_address(wallet_address)
-    except Exception as e:
-        print(f"钱包 {wallet_address} 地址格式无效: {str(e)}")
-        return wallet_num
-
-    while retry_count < max_retries:
-        try:
-            # 查询余额
-            balance = w3.eth.get_balance(checksum_address)
-            # 将余额从 Wei 转换为 Ether
-            balance_eth = w3.from_wei(balance, 'ether')
-            result_message = f"Wallet {wallet_num}: {checksum_address}\nbalance: {balance_eth} Token"
-            result_balance = balance_eth
-            print(result_message)
-            wallet_num += 1
-            break
-        except Exception as e:
-            print(f"查询钱包 {checksum_address} {wallet_num} 余额时发生错误: {str(e)}")
-            retry_count += 1
-            print(f"正在重试...(第 {retry_count} 次)")
-            time.sleep(delay)
-
-    if retry_count == max_retries:
-        result_message = f"钱包 {checksum_address} 查询余额失败,已达到最大重试次数。"
-        print(result_message)
-
-    return wallet_num
-
-
-def query_nonce(wallet_num, wallet_address):
-    try:
-        checksum_address = w3.to_checksum_address(wallet_address)
-    except Exception as e:
-        print(f"钱包 {wallet_address} 地址格式无效: {str(e)}")
-        return
-
-    try:
-        nonce_latest = w3.eth.get_transaction_count(checksum_address, "latest")
-        nonce_pending = w3.eth.get_transaction_count(checksum_address, "pending")
-        print(f'pending nonce: {nonce_pending} ; latest nonce: {nonce_latest}')
-    except Exception as e:
-        print(f"查询钱包 {checksum_address} {wallet_num} nonce时发生错误: {str(e)}")
-
-
-def main():
-    if not check_connection():
-        return
-
-    wallet_num = 0
-    for wallet_address in wallet_addresses:
-        wallet_num = query_balances(wallet_num, wallet_address)
-        query_nonce(wallet_num - 1, wallet_address)
-        print('------------')
-
-
-if __name__ == "__main__":
-    main()