simolus3 / web3dart

Ethereum library, written in Dart.
MIT License
442 stars 270 forks source link

No checksum address method found #159

Closed Flaming19 closed 3 years ago

Flaming19 commented 3 years ago

checkAddressChecksum

web3.utils.checkAddressChecksum(address)

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

simolus3 commented 3 years ago

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
}
Flaming19 commented 3 years ago

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]

simolus3 commented 3 years ago

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.

Flaming19 commented 3 years ago

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.

simolus3 commented 3 years ago

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

Flaming19 commented 3 years ago

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

simolus3 commented 3 years ago

What's wrong with this then?

import 'package:web3dart/web3dart.dart';

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

Great, Thankyou very much for your help.