simolus3/web3dart

No checksum address method found

Closed this issue · 8 comments

checkAddressChecksum

web3.utils.checkAddressChecksum(address)

this method is not found in this library, Is there any way to get this in flutter?

I don't know what exactly checkAddressChecksum does (the docs are kind of lacking), but you can do this:

try {
  EthereumAddress.fromHex(yourString, enforceEip55: true)
  // valid!
} on ArgumentError {
  // Not valid
}

https://web3js.readthedocs.io/en/v1.2.11/web3-utils.html#checksum

{EthereumAddress.fromHex(yourString, enforceEip55: true) is something else.}

This method gives us correct Address of any token from chain.
Example : token0 Id from BSCscan or from pancakeswap Abi response is 0xfeea0bdd3d07eb6fe305938878c0cadbfa169042 but this is not correct[All characters in lower case], correct one is 0xFeea0bDd3D07eb6FE305938878C0caDBFa169042. This method return use correct token0 id.

web3.utils.toChecksumAddress('0xfeea0bdd3d07eb6fe305938878c0cadbfa169042');[all lower case Id]
response > "0xFeea0bDd3D07eb6FE305938878C0caDBFa169042" [Real token0 id]

But that upper/lowercase thing is just about eip55, right? That would be caught by EthereumAddress.fromHex then.

If you want to convert to a checksum address you could use EthereumAddress.hexEip55 then.

I used EthereumAddress.fromHex with enforceEip55: true, but it is not working.

Correct token address can be get from chain only by toChecksumAddress method. If you have any example, Please share with me.

What is your input data? A string where you want to check that is has the right upper/lowercase chars according to the hashsum?

Input Data is [0xfeea0bdd3d07eb6fe305938878c0cadbfa169042] and right upper/lowercase is [0xFeea0bDd3D07eb6FE305938878C0caDBFa169042]

What's wrong with this then?

import 'package:web3dart/web3dart.dart';

void main() {
  final address =
      EthereumAddress.fromHex('0xfeea0bdd3d07eb6fe305938878c0cadbfa169042');
  print(address.hexEip55); // 0xFeea0bDd3D07eb6FE305938878C0caDBFa169042
}

Great,
Thankyou very much for your help.