jack hace 6 meses
padre
commit
3bfc30c042

+ 14 - 11
demo/query_balance/query_balance_sui.py

@@ -1,22 +1,25 @@
 from pysui import SuiConfig, SyncClient
+from pysui.sui.sui_types.scalars import SuiString
+from pysui.sui.sui_clients.common import SuiRpcResult
 
-# 1. 从私钥创建配置(新版 API)
-private_key = "suiprivkey1qrtls98pk6frpzzuajf5a53klnhd0hdtx6fwwrk65ghregk5np4j2yehv7y"  # 替换为你的私钥(Base64 或 Hex)
+private_key = "suiprivkey1qrtls98pk6frpzzuajf5a53klnhd0hdtx6fwwrk65ghregk5np4j2yehv7y"  # 替换为你的私钥
 sui_config = SuiConfig.user_config(
-    rpc_url="https://fullnode.testnet.sui.io:443",  # 可选的 RPC 地址
-    prv_keys=[private_key]  # 支持多个私钥
+    rpc_url="https://fullnode.testnet.sui.io:443",  # SUI 测试网节点地址
+    prv_keys=[private_key]  # 添加私钥
 )
 
-# 2. 创建客户端
 client = SyncClient(sui_config)
 
-# 3. 获取当前地址
+# 获取当前活跃地址
 address = sui_config.active_address
 print(f"Active Address: {address}")
 
-# 4. 查询余额(通过 RPC 直接调用)
-balance = client.get_balance(address)
-if balance.is_ok():
-    print(f"Balance: {balance.result_data.total_balance} MIST")
+# 使用 sui_getBalance RPC 方法查询余额
+response: SuiRpcResult = client._client.balance(SuiString(address))
+
+if response.is_ok():
+    balance_data = response.result_data
+    total_balance = balance_data.get("totalBalance", 0)
+    print(f"Balance: {total_balance} MIST")
 else:
-    print(f"Error: {balance.result_string}")
+    print(f"Error: {response.error}")

+ 96 - 0
project/monad/faucet.py

@@ -0,0 +1,96 @@
+# -*- coding: utf-8 -*-
+import httpx
+import asyncio
+import json
+import random
+import logging
+from typing import List
+
+# 配置日志
+logging.basicConfig(
+    level=logging.INFO,
+    format='%(asctime)s - %(levelname)s - %(message)s'
+)
+logger = logging.getLogger(__name__)
+
+
+async def send_post_request(wallet: str, timeout: float = 10.0) -> None:
+    """
+    向目标网站发送 POST 请求以领取水。
+
+    Args:
+        wallet: 钱包地址
+        timeout: 请求超时时间(秒)
+    """
+    url = "https://faucet.nerzo.xyz/monad"
+    headers = {
+        "accept": "text/x-component",
+        "accept-encoding": "gzip, deflate, br, zstd",
+        "accept-language": "zh-CN,zh;q=0.9",
+        "content-type": "text/plain;charset=UTF-8",
+        "next-action": "405d6e23437f844564e65cdd65851724c449d7f778",
+        "next-router-state-tree": '["",{"children":["(faucet)",{"children":["monad",{"children":["__PAGE__",{},"/monad","refresh"]}]}]},null,null,true]',
+        "origin": "https://faucet.nerzo.xyz",
+        "priority": "u=1, i",
+        "referer": "https://faucet.nerzo.xyz/monad",
+        "sec-ch-ua": '"Chromium";v="130", "Google Chrome";v="130", "Not?A_Brand";v="99"',
+        "sec-ch-ua-mobile": "?0",
+        "sec-ch-ua-platform": '"Windows"',
+        "sec-fetch-dest": "empty",
+        "sec-fetch-mode": "cors",
+        "sec-fetch-site": "same-origin",
+        "user-agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/130.0.0.0 Safari/537.36",
+        "x-deployment-id": "dpl_DWgqqeB8V4ASD1aCKUqWZwcPwnVd"
+    }
+    payload = json.dumps([wallet])
+
+    async with httpx.AsyncClient(timeout=timeout, proxy='http://127.0.0.1') as client:
+        retry = 3
+        while retry <= 0:
+            try:
+                response = await client.post(url, headers=headers, content=payload)
+                logger.info(f"Wallet: {wallet} | Status Code: {response.status_code} | Response: {response.text}")
+                return response
+            except httpx.RequestError as e:
+                logger.error(f"Wallet: {wallet} | Request failed: {e}")
+                retry -= 1
+
+                if retry <= 0:
+                    return None
+
+
+async def main(wallet_list: List[str], min_delay: float = 2.0, max_delay: float = 3.0) -> None:
+    """
+    批量处理钱包地址,发送 POST 请求,并添加随机延时。
+
+    Args:
+        wallet_list: 钱包地址列表
+        min_delay: 最小延时(秒)
+        max_delay: 最大延时(秒)
+    """
+    for i, wallet in enumerate(wallet_list, 1):
+        logger.info(f"Processing wallet {i}/{len(wallet_list)}: {wallet}")
+        await send_post_request(wallet)
+        # 在最后一个钱包之前添加随机延时
+        if i < len(wallet_list):
+            delay = random.uniform(min_delay, max_delay)
+            logger.info(f"Waiting for {delay:.2f} seconds before next request")
+            await asyncio.sleep(delay)
+
+
+if __name__ == "__main__":
+    wallet_list = [
+        '0xe50B77Cd771243b8Ae1d6ce33b4E13ECC5Fa28a6',
+        '0x9ea2ECAD4090E32916e03b77d7C75CbF6C8E0A55',
+        '0xE8A4b0C04300154DC9B1D0e565Ba70F996614690',
+        '0x1b623c5d70c93b437d93c305bf2cfa389095f636',
+        '0x06D25c3e0E1F753ac0486a3f8aaD7259149656cB',
+        '0x15cFEE34Ca4541CAc9a1c4B6F6aB47A65877E240',
+        '0x7aBF0dA8Ac07B6dE7206e467988455E1AD0b60B5',
+        '0xF736f45d4663a8D8DfF7EFA55b1Cf6Fe38D026c8',
+        '0x83173eECf3a6d9ABB79682568e16c2eAd361620e',
+        '0xa401b85B4849Fc7610Bd180cc937859C78528F47',
+        '0x10A43E7Fe77E2D84adBeC26cF0bFc6f403841266',
+        '0x70D5EE1DfddD3726f0D71F4CD5a8Ef43aC651a75'
+    ]
+    asyncio.run(main(wallet_list))

+ 73 - 0
project/monad/monadscore_query.py

@@ -0,0 +1,73 @@
+from playwright.sync_api import sync_playwright
+import time
+
+
+def get_wallet_detail(wallet_address: str, page):
+    # 定义输入框和按钮的选择器
+    input_selector = '#root > div > div > div.min-h-screen.overflow-hidden.sm\\:ml-0 > div:nth-child(3) > div > div > div.flex.flex-col.space-y-4 > input'
+    button_selector = '#root > div > div > div.min-h-screen.overflow-hidden.sm\\:ml-0 > div:nth-child(3) > div > div > div.flex.flex-col.space-y-4 > button.px-4.py-2.text-white.font-semibold.rounded-md.bg-purple-600.cursor-pointer.hover\\:bg-purple-700'
+
+    try:
+        # 等待输入框出现并确保其可交互
+        page.wait_for_selector(input_selector, state='visible', timeout=10000)
+        # 清除输入框内容(如果有默认值)
+        page.fill(input_selector, '')
+        # 填入钱包地址
+        page.fill(input_selector, wallet_address)
+
+        # 等待按钮出现并确保其可点击
+        page.wait_for_selector(button_selector, state='visible', timeout=10000)
+        # 点击按钮
+        page.click(button_selector)
+    except Exception as e:
+        print(f"查询钱包 {wallet_address} 时出错: {str(e)}")
+
+
+def run():
+    with sync_playwright() as p:
+        # 启动一个 Chromium 浏览器,headless=False 确保可见
+        browser = p.chromium.launch(
+            headless=False,
+            args=["--start-maximized"]
+        )
+
+        wallet_list = [
+            '0xe50B77Cd771243b8Ae1d6ce33b4E13ECC5Fa28a6',
+            '0x9ea2ECAD4090E32916e03b77d7C75CbF6C8E0A55',
+            '0xE8A4b0C04300154DC9B1D0e565Ba70F996614690',
+            '0x1b623c5d70c93b437d93c305bf2cfa389095f636',
+            '0x06D25c3e0E1F753ac0486a3f8aaD7259149656cB',
+            '0x15cFEE34Ca4541CAc9a1c4B6F6aB47A65877E240',
+            '0x7aBF0dA8Ac07B6dE7206e467988455E1AD0b60B5',
+            '0xF736f45d4663a8D8DfF7EFA55b1Cf6Fe38D026c8',
+            '0x83173eECf3a6d9ABB79682568e16c2eAd361620e',
+            '0xa401b85B4849Fc7610Bd180cc937859C78528F47',
+            '0x10A43E7Fe77E2D84adBeC26cF0bFc6f403841266',
+            '0x70D5EE1DfddD3726f0D71F4CD5a8ef43aC651a75'
+        ]
+
+        context = browser.new_context(no_viewport=True)
+
+        for i, wallet in enumerate(wallet_list):
+            page = context.new_page()
+            page.goto("https://repute.monadscore.xyz/")
+            print(f"已打开第 {i + 1} 个标签页")
+            time.sleep(1)
+            page.add_style_tag(content="body { transform: scale(0.8);}")
+            print(f'正在查询钱包 {i} : {wallet}')
+            get_wallet_detail(wallet, page)
+
+        time.sleep(3600)
+
+        context.close()
+        browser.close()
+
+
+def main():
+    while True:
+        run()
+        time.sleep(5)
+
+
+if __name__ == "__main__":
+    main()

+ 18 - 17
project/monad/query_balance_and_nonce.py

@@ -21,22 +21,23 @@ def check_connection():
 
 
 # 钱包地址列表
-# wallet_addresses = [
-#     '0xe50B77Cd771243b8Ae1d6ce33b4E13ECC5Fa28a6',
-#     '0x9ea2ECAD4090E32916e03b77d7C75CbF6C8E0A55',
-#     '0xE8A4b0C04300154DC9B1D0e565Ba70F996614690',
-#     '0x1b623c5d70c93b437d93c305bf2cfa389095f636',
-#     '0x06D25c3e0E1F753ac0486a3f8aaD7259149656cB',
-#     '0x15cFEE34Ca4541CAc9a1c4B6F6aB47A65877E240',
-#     '0x7aBF0dA8Ac07B6dE7206e467988455E1AD0b60B5',
-#     '0xF736f45d4663a8D8DfF7EFA55b1Cf6Fe38D026c8',
-#     '0x83173eECf3a6d9ABB79682568e16c2eAd361620e',
-#     '0xa401b85B4849Fc7610Bd180cc937859C78528F47',
-#     '0x10A43E7Fe77E2D84adBeC26cF0bFc6f403841266',
-#     '0x70D5EE1DfddD3726f0D71F4CD5a8Ef43aC651a75'
-# ]
-
-wallet_addresses = ['0xa401b85B4849Fc7610Bd180cc937859C78528F47']
+wallet_addresses1 = [
+    '0xe50B77Cd771243b8Ae1d6ce33b4E13ECC5Fa28a6',
+    '0x9ea2ECAD4090E32916e03b77d7C75CbF6C8E0A55',
+    '0xE8A4b0C04300154DC9B1D0e565Ba70F996614690',
+    '0x1b623c5d70c93b437d93c305bf2cfa389095f636',
+    '0x06D25c3e0E1F753ac0486a3f8aaD7259149656cB',
+    '0x15cFEE34Ca4541CAc9a1c4B6F6aB47A65877E240',
+    '0x7aBF0dA8Ac07B6dE7206e467988455E1AD0b60B5',
+    '0xF736f45d4663a8D8DfF7EFA55b1Cf6Fe38D026c8',
+    '0x83173eECf3a6d9ABB79682568e16c2eAd361620e',
+    '0xa401b85B4849Fc7610Bd180cc937859C78528F47',
+]
+
+wallet_addresses2 = [
+    '0x10A43E7Fe77E2D84adBeC26cF0bFc6f403841266',
+    '0x70D5EE1DfddD3726f0D71F4CD5a8Ef43aC651a75'
+]
 
 
 def query_balances(wallet_num, wallet_address):
@@ -98,7 +99,7 @@ def main():
         return
 
     wallet_num = 1
-    for wallet_address in wallet_addresses:
+    for wallet_address in wallet_addresses2:
         wallet_num = query_balances(wallet_num, wallet_address)
         query_nonce(wallet_num - 1, wallet_address)
         print('------------')

+ 12 - 7
project/monad/swap.py

@@ -32,9 +32,13 @@ file_path = os.path.join(os.path.dirname(__file__), 'AccountList.txt')
 
 
 def get_random_amount():
-    # 生成随机交易金额 0.00000000****(最后4位随机数)
-    random_tail = random.randint(1000, 9999)
-    return Web3.to_wei(f"0.0000000000{random_tail}", "ether")
+    # 生成随机交易金额 例如 0.00000000****(最后4位随机数)
+    # 小数位数也是随机, 14 - 18 位
+
+    random_tail = str(random.randint(1000, 9999))
+    random_bit = random.randint(14, 18)
+    random_balance = f"0.{random_tail.zfill(random_bit)}"
+    return Web3.to_wei(random_balance, "ether")
 
 
 def get_random_contract_data():
@@ -71,7 +75,6 @@ async def execute_contract(account, minimum_balance):
         # 检查钱包余额,不能小于 minimum_balance
         check_wallet_balance(balance, minimum_balance)
 
-        # 质押金额
         amount_to_stake = get_random_amount()
         print(f"Amount to contract: {Web3.from_wei(amount_to_stake, 'ether')}")
 
@@ -80,12 +83,14 @@ async def execute_contract(account, minimum_balance):
 
         # 构建交易
         nonce = w3.eth.get_transaction_count(account.address)
+        now_gas = Web3.from_wei(w3.eth.gas_price, 'ether')
+        print(f"Now Gas Fee is: {now_gas}")
         tx = {
             "to": Web3.to_checksum_address(address),
             "value": amount_to_stake,
             "data": data_hash,
             "gas": 100000,
-            "gasPrice": Web3.to_wei(50, "gwei"),
+            "gasPrice": w3.eth.gas_price,
             "nonce": nonce,
             "chainId": w3.eth.chain_id
         }
@@ -116,10 +121,10 @@ async def execute_contract(account, minimum_balance):
 
 
 async def run_multiple_staking(private_keys):
-    last_times = 1000
+    last_times = 9999
     min_delay = 10
     max_delay = 20
-    minimum_balance = 25
+    minimum_balance = 24
 
     for private_key in private_keys:
         account = w3.eth.account.from_key(private_key.strip())

+ 1 - 0
project/zama/faucet.py

@@ -0,0 +1 @@
+# -*- coding: utf-8 -*-

+ 88 - 0
test/test_contract.py

@@ -0,0 +1,88 @@
+from web3 import Web3
+import json
+
+# Monad 测试网 RPC URL
+rpc_url = "https://testnet-rpc.monad.xyz"
+
+# 连接到 Monad 测试网
+w3 = Web3(Web3.HTTPProvider(rpc_url))
+
+# 检查是否成功连接
+if not w3.is_connected():
+    raise Exception("无法连接到 Monad 测试网")
+
+# 合约地址和 ABI(仅保留 transfer 和 decimals)
+contract_address = w3.to_checksum_address("0x760AfE86e5de5fa0Ee542fc7B7B713e1c5425701")
+abi = json.loads('''[
+    {"inputs":[{"internalType":"address","name":"dst","type":"address"},{"internalType":"uint256","name":"wad","type":"uint256"}],"name":"transfer","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","type":"function"},
+    {"inputs":[],"name":"decimals","outputs":[{"internalType":"uint8","name":"","type":"uint8"}],"stateMutability":"view","type":"function"}
+]''')
+
+# 初始化合约
+contract = w3.eth.contract(address=contract_address, abi=abi)
+
+# 你的钱包私钥和地址
+private_key = "b898cf63a5ec89105ba755ef3b7533c25ea9130ab50fb0db14779fb6efd4f9c6"  # 替换为你的私钥
+account = w3.eth.account.from_key(private_key)
+wallet_address = account.address
+
+# 辅助函数:签名并发送交易
+def send_transaction(tx):
+    """
+    签名并发送交易
+    参数:
+        tx: 交易字典
+    返回:
+        交易回执
+    """
+    try:
+        tx['from'] = wallet_address
+        tx['nonce'] = w3.eth.get_transaction_count(wallet_address)
+        tx['gas'] = 100000  # Gas 限额,适用于简单的 transfer
+        tx['gasPrice'] = w3.eth.gas_price
+        signed_tx = w3.eth.account.sign_transaction(tx, private_key)
+        tx_hash = w3.eth.send_raw_transaction(signed_tx.raw_transaction)
+        return w3.eth.wait_for_transaction_receipt(tx_hash)
+    except Exception as e:
+        raise Exception(f"发送交易失败: {str(e)}")
+
+# 转账代币
+def transfer(recipient, amount):
+    """
+    转账代币给指定地址
+    参数:
+        recipient: 接收者地址
+        amount: 转账的代币数量(以代币单位为准,例如 10 表示 10 个代币)
+    """
+    try:
+        # 验证接收者地址
+        if not w3.is_address(recipient):
+            raise ValueError("接收者地址无效")
+        recipient = w3.to_checksum_address(recipient)
+
+        # 获取小数位并转换金额
+        decimals = contract.functions.decimals().call()
+        if not isinstance(amount, (int, float)) or amount < 0:
+            raise ValueError("转账金额必须是非负数")
+        amount_wei = int(amount * 10**decimals)  # 转换为最小单位
+
+        # 构建交易
+        tx = contract.functions.transfer(recipient, amount_wei).build_transaction({
+            'chainId': w3.eth.chain_id,
+            'gas': 100000,  # 显式指定 Gas 限额
+            'gasPrice': w3.eth.gas_price,
+            'nonce': w3.eth.get_transaction_count(wallet_address),
+        })
+
+        # 发送交易
+        receipt = send_transaction(tx)
+        print(f"转账成功,交易哈希: {receipt.transactionHash.hex()}")
+
+    except Exception as e:
+        print(f"转账失败: {str(e)}")
+
+# 示例用法
+if __name__ == "__main__":
+    # 转账 10 个代币给指定地址
+    recipient_address = "0x760AfE86e5de5fa0Ee542fc7B7B713e1c5425701"  # 0x904d6CEf48D78448E332B90f66e23a5aAedC1A47
+    transfer(recipient_address, 0.000000005231854)  # 修改此处的 10 为你想要转账的代币数量

+ 144 - 0
test/test_contract1.py

@@ -0,0 +1,144 @@
+# -*- coding: utf-8 -*-
+from web3 import Web3
+import random
+import time
+import os
+
+# Monad 测试网 RPC URL
+provider_url = "https://testnet-rpc.monad.xyz"
+w3 = Web3(Web3.HTTPProvider(provider_url))
+
+# 合约地址、合约方法哈希值及描述
+contract_data = [
+    {
+        "address": "0x64Aff7245EbdAAECAf266852139c67E4D8DBa4de",
+        "data_hash": "0x7ff36ab5",
+        "description": "TEST"
+    }
+]
+
+# 读取私钥文件
+file_path = os.path.join(os.path.dirname(__file__), 'AccountList.txt')
+
+
+def get_random_amount():
+    # 生成随机交易金额 例如 0.00000000****(最后4位随机数)
+    # 小数位数也是随机, 14 - 18 位
+
+    random_tail = str(random.randint(1000, 9999))
+    random_bit = random.randint(14, 18)
+    random_balance = f"0.{random_tail.zfill(random_bit)}"
+    return Web3.to_wei(random_balance, "ether")
+
+
+def get_random_contract_data():
+    # 随机获取合约地址、合约方法哈希值及描述
+    if not contract_data:
+        print("The contract data array is empty, the contract cannot be selected, and the program exits.")
+        exit(1)
+    return random.choice(contract_data)
+
+
+def check_wallet_balance(balance, minimum_balance):
+    # 如果钱包余额小于等于最小余额
+    if balance <= Web3.to_wei(minimum_balance, "ether"):
+        print("The wallet balance is invalid.")
+        exit(1)
+
+
+async def execute_contract(account, minimum_balance):
+    try:
+        # 随机选择一个合约地址、合约方法哈希值及描述
+        contract_info = get_random_contract_data()
+        address = contract_info["address"]
+        data_hash = contract_info["data_hash"]
+        description = contract_info["description"]
+        print(f"Selected contract: {description}")
+        print(f"Selected contract address: {address}")
+        print(f"Selected contract dataHash: {data_hash}")
+
+        # 检查原生代币余额
+        balance = w3.eth.get_balance(account.address)
+        before_balance = Web3.from_wei(balance, "ether")
+        print(f"Native balance: {before_balance}")
+
+        # 检查钱包余额,不能小于 minimum_balance
+        check_wallet_balance(balance, minimum_balance)
+
+        amount_to_stake = get_random_amount()
+        print(f"Amount to contract: {Web3.from_wei(amount_to_stake, 'ether')}")
+
+        if balance < amount_to_stake:
+            raise Exception("Insufficient balance for contract execution.")
+
+        # 构建交易
+        nonce = w3.eth.get_transaction_count(account.address)
+        tx = {
+            "to": Web3.to_checksum_address(address),
+            "value": amount_to_stake,
+            "data": data_hash,
+            "gas": 100000,
+            "gasPrice": w3.eth.gas_price,
+            "nonce": nonce,
+            "chainId": w3.eth.chain_id
+        }
+
+        # 签名并发送交易
+        signed_tx = w3.eth.account.sign_transaction(tx, account.key)
+        tx_hash = w3.eth.send_raw_transaction(signed_tx.raw_transaction)
+        print(f"Contract Execution hash: {tx_hash.hex()}")
+
+        # 等待交易确认
+        receipt = w3.eth.wait_for_transaction_receipt(tx_hash)
+        execute_status = receipt["status"]
+        if execute_status == 1:
+            print("Contract Execution status: seccessful")
+        elif execute_status == 0:
+            print("Contract Execution status: failed")
+        else:
+            print("Contract Execution status: unknown")
+
+        # 检查交易后的余额
+        balance_staking = w3.eth.get_balance(account.address)
+        after_balance = Web3.from_wei(balance_staking, "ether")
+        print(f"Native balance after transaction: {after_balance}")
+        print(f"The cost of this transaction: {float(before_balance) - float(after_balance)}")
+
+    except Exception as e:
+        print(f"Error executing contract: {e}")
+
+
+async def run_multiple_staking(private_keys):
+    last_times = 9999
+    min_delay = 10
+    max_delay = 20
+    minimum_balance = 0.01
+
+    for private_key in private_keys:
+        account = w3.eth.account.from_key(private_key.strip())
+        print(f"Processing wallet with address: {account.address}")
+
+        for i in range(last_times):
+            if last_times > 1:
+                print(f"Starting Contract attempt {i + 1}")
+            await execute_contract(account, minimum_balance)
+            print(f"Completed Contract attempt {i + 1}")
+            if i < last_times - 1:
+                delay = random.uniform(min_delay, max_delay)
+                print(f"Waiting for {delay} seconds...")
+                print('------------------------------------------------------------')
+                time.sleep(random.uniform(min_delay, max_delay))
+
+
+async def main():
+    try:
+        await run_multiple_staking(['3991542110242368f4770716be904b0ca6d44a8dbe4501771833b1a3642198d1'])
+    except Exception as err:
+        print(f'读取文件时发生错误: {err}')
+        exit(1)
+
+
+if __name__ == "__main__":
+    import asyncio
+
+    asyncio.run(main())