1
def register(update: Update, context: CallbackContext):
    """Register the user and generate a ETH address."""
    user_id = update.message.from_user.id
    if update.message.chat.type != 'private':
        update.message.reply_text('This command can only be used in a private chat.')
        return
    # Check if user is already registered
    cursor.execute('SELECT * FROM users WHERE user_id = %s', (user_id,))
    result = cursor.fetchone()
    if result is not None:
        update.message.reply_text('You are already registered.')
        return
    # Generate new ETH address and private key
    account = w3.eth.account.create()
    address = account.address
    private_key = account.privateKey.hex()
    # Check if address is valid
    if not Web3.isAddress(address):
        update.message.reply_text('Error: Invalid ETH address generated. Please try again.')
        return
    # Insert new address and private key into database
    cursor.execute('INSERT INTO addresses (user_id, address, private_key) VALUES (%s, %s, %s)', (user_id, address, private_key))
    db.commit()
    # Insert new user into database
    username = update.message.from_user.username
    cursor.execute('INSERT INTO users (user_id, username) VALUES (%s, %s)', (user_id, username))
    db.commit()
    # Send confirmation message
    message = f'You have been registered with the following ETH address:\n\n{address}\n\nPlease use this address to deposit ETH or ERC20 tokens to your account.'
    context.bot.send_message(chat_id=user_id, text=message)

How can I fix this ?

Try to fix this but still cannot fix we got error for:
AttributeError: 'LocalAccount' object has no attribute 'privateKey'

1
  • We need more information about what all of these objects are and it would be better if you provide a MRE. But generally if you some errors like this: double check that you are using the right attribute name Commented Oct 12, 2023 at 9:04

1 Answer 1

0

Since Web3 6.0 released, LocalAccount.privateKey has been renamed to LocalAccount._private_key.

For further info, refer to Web3 6.0 released notes.

Sign up to request clarification or add additional context in comments.

1 Comment

thanks for answer and give detailed we try for fix this. thankyou

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.