Account Generation Process in ETH or Tron Blockchain
Tron Blockchain, similar to ETH Blockchain, has the following Wallet Generation Process:
- Generate a 256-bit Random Number as private key
- Convert Private Key to secp256k1 uncompressed public key aka 512-bit public key
- Using Keccak256 to compute the hash value of Public Key, and convert to Hex String
- Get the last 40 characters of the Hex String, and prefix with “0x” in ETH or “TL” in Tron.
Using Python SDK to generate the Wallet in Tron Blockchain
First, make sure you have “tronpy” installed via “pip3 install tronpy”. Then run the following Python code to get the private key and wallet Address on Tron Blockchain:
1 2 3 4 5 6 7 8 | from tronpy import Tron, Contract from tronpy.keys import PrivateKey priv_key = PrivateKey.random() print("Private Key is ", priv_key) account = priv_key.public_key.to_base58check_address() print("Accuont Address is ", account) |
from tronpy import Tron, Contract from tronpy.keys import PrivateKey priv_key = PrivateKey.random() print("Private Key is ", priv_key) account = priv_key.public_key.to_base58check_address() print("Accuont Address is ", account)
The private key generation is based on the Random function that generates a 256-bit bytes – it is in theory possible for a collision thus the account hacked – however, extremely unlikely.
1 2 3 | def random(cls) -> "PrivateKey": """Generate a random private key.""" return cls(bytes([random.randint(0, 255) for _ in range(32)])) |
def random(cls) -> "PrivateKey": """Generate a random private key.""" return cls(bytes([random.randint(0, 255) for _ in range(32)]))
The account existence could be checked by simply assuming non-zero balance on Tron Blockchain.
Creating Tron Wallets/Accounts on Shasta TestNet
We can call the API directly to Shasta TestNet to get accounts/private keys instantly via Web API:
1 2 3 4 5 | import requests url = "https://api.shasta.trongrid.io/wallet/generateaddress" response = requests.request("GET", url) print(response.text) |
import requests url = "https://api.shasta.trongrid.io/wallet/generateaddress" response = requests.request("GET", url) print(response.text)
Example of the Returned Account Details via JSON:
1 2 3 4 5 | { "privateKey":"a3c8cfa7c5adb2e9fcb7fb1a915f8336238a6223da415e1e6515926cc45efdef", "address":"TAL2JTQepe2pc8RBucFZkVCW7UmbzgJr3M", "hexAddress":"4103efcda1877de247db47d32a36e895b6f1f8c187" } |
{ "privateKey":"a3c8cfa7c5adb2e9fcb7fb1a915f8336238a6223da415e1e6515926cc45efdef", "address":"TAL2JTQepe2pc8RBucFZkVCW7UmbzgJr3M", "hexAddress":"4103efcda1877de247db47d32a36e895b6f1f8c187" }
However, the API has been deactivated for now on main-net for security concerns.
Tron Blockchain
- TRON Blockchain: How to Send the USDT (TRC-20) Transacton using Python tronpy?
- How to Get Balance of TRX or USDT/USDD/USDC (TRC-20) Smart Contract Tokens on TRON Blockchain?
- Function to Return the USDT/USDD/USDC Contract Address on Tron Blockchain (Main Net, Nile, Shasta)
- How to Send/Transfer USDT/USDD/USDC on Tron Blockchain using Tronweb?
- Javascript Function to Send Trx on Tron Blockchain based on TronWeb
- How to Generate an Account on Tron Blockchain using Python SDK?
- How to Claim the Witness (Super Representative) Voting Rewards on Tron Blockchain using Node Js (Javascript)?
- Automate Freeze Balance on Tron Blockchain using NodeJs with TronWeb/TronGrid
- Python Tool of Base58 Decode Check
- TRON Blockchain: How to Check the Number of Peers the Tron Node is Connected to?
- TRON Blockchain: How to Check If a Node is synchronized and Fully Functional?
- How to Activate a TRON (TRX) Blockchain Wallet Address?
- Delayed Swap due to Numeric Underflow Bug by using Tron’s triggerSmartContract Method
–EOF (The Ultimate Computing & Technology Blog) —
loading...
Last Post: Go Lang Programming Exercise: Single-Row Keyboard
Next Post: Teaching Kids Programming - Two Pointer Algorithm to Rescue People in Rocketship