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'
Since Web3 6.0 released, LocalAccount.privateKey
has been renamed to LocalAccount._private_key
.