8wDlpd.png
8wDFp9.png
8wDEOx.png
8wDMfH.png
8wDKte.png

每次运行此脚本时,我都会遇到错误:Python 说:AttributeError:'PrivateKey' 对象没有属性'address'

pdp 2月前

43 0

我正在尝试运行由 AI 生成的以下脚本,但是当尝试运行该脚本时,我收到以下错误:= RESTART:C:\Users\me\Python311\Scripts\Trading.pyTraceback(大多数...

我正在尝试运行由 AI 生成的以下脚本,但是当我尝试运行该脚本时出现以下错误:

= RESTART: C:\Users\me\Python311\Scripts\Trading.py
Traceback (most recent call last):
  File "C:\Users\me\Python311\Scripts\Trading.py", line 78, in <module>
    account = client.get_account(priv_key.address)
AttributeError: 'PrivateKey' object has no attribute 'address'


以下是我代码的完整源代码。我还附上了原始粘贴箱的链接。然而,当尝试在 IDLE 上运行它时,出现了错误。

以下是使用的提示:

  1. 为 Tron 区块链上的 SunPump 平台构建狙击机器人
  2. 在狙击之前通过 SolidityScan 检查合约分数来调整代码
  3. 调整代码以仅拦截 SunPump 上具有活跃评论部分的令牌
  4. 调整代码以自动从 SunPump 获取合约地址并仅狙击具有 100% 粘合曲线的代币
  5. 检查推特分数, https://app.tweetscout.io/ 只狙击分数超过 50 的代币6.调整代码并设置 25% 的买卖滑点、最低 10K 流动性和 100 TRX 的购买量

完整代码:

import requests
from tronpy import Tron
from tronpy.keys import PrivateKey
from datetime import datetime, timedelta
 
# API URLs
SUNPUMP_API_URL = "https://api.sunpump.io/v1/tokens"  # Example SunPump API endpoint
SOLIDITYSCAN_API_URL = "https://api.solidityscan.com/v1/contract/score"  # Example SolidityScan URL
TWEETSCOUT_API_URL = "https://app.tweetscout.io/api/v1/twitter/score"  # Example TweetScout URL
 
# Configuration
MIN_CONTRACT_SCORE_THRESHOLD = 80
MIN_TWITTER_SCORE_THRESHOLD = 50
MIN_LIQUIDITY_THRESHOLD = 10_000  # Minimum liquidity in TRX
BUY_AMOUNT_TRX = 100  # Amount to buy in TRX
SLIPPAGE_TOLERANCE_BUY = 0.25  # 25% slippage tolerance for buying
SLIPPAGE_TOLERANCE_SELL = 0.25  # 25% slippage tolerance for selling
 
# Function to get the contract score from SolidityScan
def get_contract_score(contract_address):
    response = requests.get(f"{SOLIDITYSCAN_API_URL}?address={contract_address}")
    if response.status_code == 200:
        score_data = response.json()
        return score_data.get("score", 0)
    else:
        print(f"Error fetching score: {response.status_code}")
        return 0
 
# Function to check active comments on SunPump
def check_sunpump_active_comments(token_id):
    response = requests.get(f"{SUNPUMP_API_URL}/{token_id}/comments")
    if response.status_code == 200:
        comments_data = response.json()
        recent_comments = [
            comment for comment in comments_data.get('comments', [])
            if datetime.strptime(comment['timestamp'], '%Y-%m-%dT%H:%M:%S') > datetime.now() - timedelta(days=1)
        ]
        return len(recent_comments) > 0
    else:
        print(f"Error fetching comments: {response.status_code}")
        return False
 
# Function to get tokens with 100% bonding curve from SunPump
def get_tokens_with_100_bonding_curve():
    response = requests.get(SUNPUMP_API_URL)
    if response.status_code == 200:
        tokens = response.json().get('tokens', [])
        tokens_with_100_bonding_curve = [
            token for token in tokens
            if token.get('bonding_curve', 0) == 100
        ]
        return tokens_with_100_bonding_curve
    else:
        print(f"Error fetching tokens: {response.status_code}")
        return []
 
# Function to check the Twitter score via TweetScout
def get_twitter_score(token_name):
    response = requests.get(f"{TWEETSCOUT_API_URL}?name={token_name}")
    if response.status_code == 200:
        score_data = response.json()
        return score_data.get("score", 0)
    else:
        print(f"Error fetching Twitter score: {response.status_code}")
        return 0
 
# Function to check if the token has sufficient liquidity
def check_liquidity(contract_address):
    # Example placeholder for liquidity check; replace with actual logic
    liquidity = 20_000  # Example liquidity fetched from some source
    return liquidity >= MIN_LIQUIDITY_THRESHOLD
 
# Set up connection to Tron node
client = Tron()
 
# Set up your wallet
priv_key = PrivateKey(bytes.fromhex('MY PRIVATE KEY HERE'))
account = client.get_account(priv_key.address)
 
# Step 1: Get tokens with 100% bonding curve from SunPump
tokens = get_tokens_with_100_bonding_curve()
 
# Process each token
for token in tokens:
    contract_address = token['contract_address']
    token_id = token['id']
    token_name = token['name']
 
    print(f"Checking token: {token_name}, Contract Address: {contract_address}")
 
    # Step 2: Check the contract's score via SolidityScan
    contract_score = get_contract_score(contract_address)
    print(f"Contract Score: {contract_score}")
 
    # Step 3: Check if the token has an active comments section on SunPump
    has_active_comments = check_sunpump_active_comments(token_id)
 
    # Step 4: Check the Twitter score via TweetScout
    twitter_score = get_twitter_score(token_name)
    print(f"Twitter Score: {twitter_score}")
 
    # Step 5: Check liquidity
    sufficient_liquidity = check_liquidity(contract_address)
    print(f"Sufficient Liquidity: {sufficient_liquidity}")
 
    if contract_score >= MIN_CONTRACT_SCORE_THRESHOLD and has_active_comments and twitter_score >= MIN_TWITTER_SCORE_THRESHOLD and sufficient_liquidity:
        print(f"All criteria met for {token_name}. Proceeding with sniping...")
 
        # Step 6: Calculate slippage-adjusted amount to buy
        amount_to_buy = BUY_AMOUNT_TRX * (1 - SLIPPAGE_TOLERANCE_BUY)
 
        # Step 7: Call the function you're interested in sniping (adjust for your contract)
        tx = (
            contract.functions.yourFunctionName(amount_to_buy)  # Adjust to the contract's buy function
            .with_owner(account.address)
            .fee_limit(1_000_000)  # Adjust fee limit accordingly
            .build()
            .sign(priv_key)
        )
 
        # Step 8: Send the transaction
        result = tx.broadcast().wait()
 
        print(f'Transaction result for {token_name}: {result}')
 
        # After buying, optionally perform sell logic with 25% slippage tolerance
        # sell_amount = ...
        # Implement sell logic here if necessary
 
    else:
        print(f"Skipping {token_name}: Does not meet all criteria.")
 


帖子版权声明 1、本帖标题:每次运行此脚本时,我都会遇到错误:Python 说:AttributeError:'PrivateKey' 对象没有属性'address'
    本站网址:http://xjnalaquan.com/
2、本网站的资源部分来源于网络,如有侵权,请联系站长进行删除处理。
3、会员发帖仅代表会员个人观点,并不代表本站赞同其观点和对其真实性负责。
4、本站一律禁止以任何方式发布或转载任何违法的相关信息,访客发现请向站长举报
5、站长邮箱:yeweds@126.com 除非注明,本帖由pdp在本站《python》版块原创发布, 转载请注明出处!
最新回复 (0)
  • 我认为问题与以下内容有关。请记住,我删除了我的私钥 # 设置你的钱包 priv_key = PrivateKey(bytes.fromhex('MY PRIVATE KEY HERE')) account = client.get_account(priv_key.address)

  • 您的评论是正确的,您提到的那行代码似乎就是问题所在。查看 tronpy 的文档 ,PrivateKey 类似乎没有 \'address\' 属性。从我在文档中看到的内容来看,这有点难以判断,但 PrivateKey 类的各种方法似乎都会返回密钥本身,因此密钥可能存储在变量中 priv_key ,无需放在 .address 末尾。

    (我会看看是否可以稍后对 tronpy 包进行一些实验,然后更有信心地回答它应该如何工作,但如果有帮助,或者您遇到了什么新错误,请告诉我)

  • 谢谢,如果我能让它工作就太好了。尝试了很多东西……你的建议引发了以下错误:== RESTART:C:/Users/x/Python311/Scripts/Tradingtest.py = Traceback(最近一次调用最后一次):文件\'C:/Users/x/Python311/Scripts/Tradingtest.py\',第 78 行,account = client.get_account(priv_key) 文件 \'C:\Users\x\Python311\Lib\site-packages\tronpy\tron.py\',第 722 行,位于 get_account 中

  • 继续.......... ret = self.provider.make_request(\'wallet/getaccount\', {\'address\': keys.to_base58check_address(addr), \'visible\': True}) 文件\'C:\Users\x\Python311\Lib\site-packages\tronpy\keys_init_.py\', 第 101 行, 在 to_base58check_address 中 raise BadAddress(repr(raw_addr)) tronpy.exceptions.BadAddress: '我的私钥在这里'

返回
作者最近主题: