mirror of
https://github.com/tgbot-collection/ytdlbot.git
synced 2024-09-20 06:55:55 +08:00
bbc357e7b5
The code has been updated to display the account balance and to ask for the transfer amount in TRX. The transfer method has also been modified to facilitate transactions in multiples of 1,000,000.
30 lines
912 B
Python
30 lines
912 B
Python
#!/usr/bin/env python3
|
|
# coding: utf-8
|
|
|
|
# ytdlbot - transfer.py
|
|
# 2023-12-07 18:21
|
|
from tronpy import Tron
|
|
from tronpy.hdwallet import seed_from_mnemonic, key_from_seed
|
|
from tronpy.keys import PrivateKey
|
|
|
|
mnemonic = "web horse smile ramp olive slush blue property world physical donkey pumpkin"
|
|
|
|
client = Tron(network="nile")
|
|
|
|
from_ = client.generate_address_from_mnemonic(mnemonic, account_path="m/44'/195'/0'/0/0")["base58check_address"]
|
|
balance = client.get_account_balance(from_)
|
|
print("my addr: ", from_, "balance: ", balance)
|
|
to = input("to: ")
|
|
amount = int(input("amount in TRX: "))
|
|
|
|
|
|
def mnemonic_to_private_key():
|
|
seed = seed_from_mnemonic(mnemonic, passphrase="")
|
|
private_key = key_from_seed(seed, account_path="m/44'/195'/0'/0/0")
|
|
return PrivateKey(private_key)
|
|
|
|
|
|
t = client.trx.transfer(from_, to, amount * 1_000_000).build().sign(mnemonic_to_private_key()).broadcast()
|
|
|
|
print(t.wait())
|