xclud / web3dart

Ethereum library, written in Dart.
https://pub.dev/packages/web3dart
MIT License
171 stars 94 forks source link

validate address #45

Closed ohari5336 closed 2 years ago

ohari5336 commented 2 years ago

how to check enter address valid before send coin OR token to address ?

ttb-inc commented 2 years ago
    try {
      EthereumAddress.fromHex(address);
      return true;
    } catch (e) {
      consoleLog(e.toString());
      return false;
    }
ohari5336 commented 2 years ago

Thanks for reply @ttb-inc

I want to check enter address is user wallet address OR Contract address

ttb-inc commented 2 years ago

That is not related to the web3dart package. You will have to find another API to solve it. scan brower API(ex, etherscan, ...) or Moralis API, ...

TheGreatAxios commented 2 years ago

@ohari5336 You can use my custom utility library if you would like, or take what you want and provide the necessary credit back.

The library here: https://github.com/mylilius/dart_utils does use my custom web3dart repo locally, however, you can plug the existing one in. It has a variety of utilities to streamline development including: https://github.com/mylilius/dart_utils/blob/development/lib/utils/ethereum_address.dart

It is static methods so it is called as such:

EthereumAddressUtils.isAddress(String _address); // Returns -> Bool EthereumAddressUtils.buildAddress(String _address); // Returns -> EthereumAddress

I have reverted to using the address in string format throughout the application as it is far more intuitive in my opinion, and then when I need it in hex format I can quickly convert it.

I do update my libraries quite a bit as I am actively building.