8

I am having an issue related to validating cryptocurrency wallet addresses, specifically USDT.

USDT can be validated either as a BTC or ETH address, depending on the network type.

Basically it goes like that:

  • If cryptocurrency is USDT and chain type is ERC20, validate the address against ETH address format.
  • If cryptocurrency is USDT and wallet type is OMNI, validate the address against BTC address format.

I haven't managed to find a specific validation for USDT:TRC20 addresses and I am not sure how to validate them.

GeorgeKaf
  • 599
  • 8
  • 23

4 Answers4

6

Regex for matching Tron address: T[A-Za-z1-9]{33}

Limer Boy
  • 61
  • 1
  • 2
  • 1
    Your answer could be improved with additional supporting information. Please [edit] to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Feb 09 '22 at 11:59
5

validating the address on your own is not preferred you should use an API like Tron protocol not only to check if the address is valid also to check if it's not a spam

you need to check the documentation
tronprotocol

also check how to make http request
here

also Shielded TRC-20

check this website as a reference

Omar Mahmoud
  • 2,902
  • 1
  • 14
  • 22
Abdullah Basem
  • 424
  • 2
  • 6
2

trc20 address features:

An encoded Mainnet address begins with T and is 34 bytes in length.

<?php
    function isTrc20($address){
       return substr($address,0,1)=="T" and strlen($address)==34;
    }
    if(isTrc20("TC74QG8tbtixG5Raa4fEifywgjrFs45fNz"))
       echo "yes";
    else
        echo "no";

information source : https://medium.com/tron-foundation/tron-developer-guide-account-2446633a750

sepordeh
  • 62
  • 4
  • Your answer could be improved with additional supporting information. Please [edit] to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Oct 15 '21 at 03:41
  • Won't work for invalid base58 address like TYxWg4wkS9Mq1J4jDCWIsf2NkQNNpH3cU7 – Ilya Shevyryaev Oct 08 '22 at 10:04
1

You can verify address using the embedded check sum according to tron whitepaper - section 4.2 about the address creation from public key.

Hash the public key using the SHA3-256 function (the SHA3 protocol adopted is KECCAK-256) and extract the last 20 bytes of the result. Add 41 to the beginning of the byte array and ensure the initial address length is 21 bytes. Hash the address twice using SHA3-256 function and take the first 4 bytes as verification code. Add the verification code to the end of the initial address and obtain the address in base58check format through base58 encoding. An encoded Mainnet address begins with T and is 34 bytes in length.

  1. You need to decode the address using base58
  2. last four bytes are the checksum (checkSum1)
  3. Then you need to hash the decoded address itself (without the checksum) using sha256 algorithm twice and take first 4 bytes
  4. These bytes are the actual checksum (checkSum2)
  5. The address can be treated as valid if the checkSum1 and checkSum2 are identical

You can check my gist with JS implementation if you familiar with JS

UPD: there is also API for this in tronweb

Nick
  • 144
  • 1
  • 4