On Tron Blockchain, a wallet could be inactivated as it doesn’t appear on the chain yet. The way to activate a Tron Wallet is to send a 1 TRX to it, so that the wallet/transaction is recorded on the Tron Blockchain.
How to Check if a String is a Valid TRON wallet?
We can use the TronWeb to validate if a given string is a valid TRON wallet address (although it can be inactive):
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 | // Function to check if a TRON wallet address is valid // param: address to check if it is valid tron wallet // param: tron network is "mainnet", "shasta" or "nile" // param: AppKey is the TronGrid APP KEY function isValidAddress(address, network, AppKey) { network = network.toLowerCase(); let url = null; if (network === "mainnet") { url = "https://api.trongrid.io"; } else if (network === "shasta") { url = "https://api.shasta.trongrid.io"; } else if (network === "nile") { url = "https://nile.trongrid.io"; } const tronWebParam = { fullHost: url, }; if (AppKey != null && typeof AppKey !== "undefined" && network === "mainnet") { tronWebParam["headers"] = { "TRON-PRO-API-KEY": AppKey }; } const tronWeb = new TronWeb(tronWebParam); return tronWeb.isAddress(address); } |
// Function to check if a TRON wallet address is valid // param: address to check if it is valid tron wallet // param: tron network is "mainnet", "shasta" or "nile" // param: AppKey is the TronGrid APP KEY function isValidAddress(address, network, AppKey) { network = network.toLowerCase(); let url = null; if (network === "mainnet") { url = "https://api.trongrid.io"; } else if (network === "shasta") { url = "https://api.shasta.trongrid.io"; } else if (network === "nile") { url = "https://nile.trongrid.io"; } const tronWebParam = { fullHost: url, }; if (AppKey != null && typeof AppKey !== "undefined" && network === "mainnet") { tronWebParam["headers"] = { "TRON-PRO-API-KEY": AppKey }; } const tronWeb = new TronWeb(tronWebParam); return tronWeb.isAddress(address); }
How to Check if a wallet is Valid and Activated?
We can also use the following Javascript (NodeJs) function to check if an address is valid and activated. This is done by using the tronweb.trx.getAccount to obtain the information from the Tron Blockchain. If it succeeds, then the address is valid and activated.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 | // Function to check if a TRON wallet address is valid and activated // param: address is the given tron wallet address tring // param: network is "mainnet", "shasta" or "nile" // param: AppKey is the TronGrid APP KEY async function isValidAndActivated(address, network, AppKey) { network = network.toLowerCase(); let url = null; if (network === "mainnet") { url = "https://api.trongrid.io"; } else if (network === "shasta") { url = "https://api.shasta.trongrid.io"; } else if (network === "nile") { url = "https://nile.trongrid.io"; } const tronWebParam = { fullHost: url, }; if (AppKey != null && typeof AppKey !== "undefined" && network === "mainnet") { tronWebParam["headers"] = { "TRON-PRO-API-KEY": AppKey }; } const tronWeb = new TronWeb(tronWebParam); try { // Check if the address is a valid TRON address if (!tronWeb.isAddress(address)) { return false; // Invalid address } // Fetch account information const accountInfo = await tronWeb.trx.getAccount(address); if (accountInfo && accountInfo.address) { return true; // Address is activated // use the following if you require the account balance non-zero // return accountInfo.balance > 0; } else { return false; // Address is not activated } } catch (error) { console.error('Error checking address:', error); return false; // Something went wrong } } |
// Function to check if a TRON wallet address is valid and activated // param: address is the given tron wallet address tring // param: network is "mainnet", "shasta" or "nile" // param: AppKey is the TronGrid APP KEY async function isValidAndActivated(address, network, AppKey) { network = network.toLowerCase(); let url = null; if (network === "mainnet") { url = "https://api.trongrid.io"; } else if (network === "shasta") { url = "https://api.shasta.trongrid.io"; } else if (network === "nile") { url = "https://nile.trongrid.io"; } const tronWebParam = { fullHost: url, }; if (AppKey != null && typeof AppKey !== "undefined" && network === "mainnet") { tronWebParam["headers"] = { "TRON-PRO-API-KEY": AppKey }; } const tronWeb = new TronWeb(tronWebParam); try { // Check if the address is a valid TRON address if (!tronWeb.isAddress(address)) { return false; // Invalid address } // Fetch account information const accountInfo = await tronWeb.trx.getAccount(address); if (accountInfo && accountInfo.address) { return true; // Address is activated // use the following if you require the account balance non-zero // return accountInfo.balance > 0; } else { return false; // Address is not activated } } catch (error) { console.error('Error checking address:', error); return false; // Something went wrong } }
Tron Blockchain Posts
Here are some popular posts regarding the Tron Blockchain:- Beware of the Malicious Transactions on TRON Blockchain
- NodeJs Function to Check if a Tron Wallet Address is Valid and Activated
- Introduction to Shielded Contracts on Blockchain (EVM, TVM)
- Passive Income: Staking TRX on Tron Blockchain and Earn Voting Rewards (4.8% APR)
- 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) —
GD Star Rating
loading...
522 wordsloading...
Last Post: Teaching Kids Programming - Split the Numbers into Two Distinct Arrays
Next Post: Teaching Kids Programming - Existence of a Substring in a String and Its Reverse