From Solidity To Dart : how reproduce an Solidity Address type construction in Dart

187 views Asked by At

I have not managed to convert a line of code I have in one a Smart Contract of the back end of my DAPP into the Dart syntax for the front end part of it.

SOLIDITY : address account = address(uint160(uint256(keccak256(abi.encodePacked(entityName))))) with entityName as String

FLUTTER / DART : I need to build the address from the same input entityName as String

Thanks in advance for your help. Regards.

SOLIDITY

I used REMIX to go step by step in the account building from the Solidity perspective :

bytes memory step01 = abi.encodePacked(entityName);
bytes32 step02 = keccak256(step01);
uint256 step03 = uint256(step02);
uint160 step04 = uint160(step03);
address account = address(step04);

Example with entityName = "KDA01", I get :


    "step01": {
    "length": "0xa",
    "value": "0x4b44413031",
    "type": "bytes"
    },

    "step02": {
    "value": "0xFFB214D8B437E7A805C5296021BE52AE31DD542BA4D974640EE2B560EB606A48",
    "type": "bytes32"
    }, 

    "step03": {
    "value": "115654419043518107807063691682277524886430192415013772206851754554299764468296",
    "type": "uint256"
    },

    "step04": {
    "value": "192641039507767147859536397911767366369328261704",
    "type": "uint160"
    },

    "account": {
    "value": "0x21BE52AE31DD542BA4D974640EE2B560EB606A48",
    "type": "address"
    }

DART

in my Flutter project I have tried different things, unsuccessfully. here is the last one :

// from 'KDA01' to '0x4b44413031' : OK

final internalAddressKDA_step01b = HEX.encode(internalAddressKDA_step01a);/*   result:4b44413031'

// from '0x4b44413031' to '0xFFB214D8B437E7A805C5296021BE52AE31DD542BA4D974640EE2B560EB606A48' : KO

    final Uint8List internalAddressKDA_step02b1 =     Uint8List.fromList(internalAddressKDA_step02a1);/* result:[52, 98, 52, 52, 52, 49, 51, 48, 51, 49]
    final digest = KeccakDigest(256);
    final internalAddressKDA_step02c1 = digest.process(internalAddressKDA_step02b1);/* result:[255, 227, 18, 191, 77, 239, 163, 74, 246, 222, 221, 249, 185, 28, 232, 195, 163, 178, 25, 205, 85, 0, 40, 179, 100, 22, 231, 99, 144, 98, 82, 72]
    final internalAddressKDA_step02d6 = hex.encode(internalAddressKDA_step02c1);/* result:ffe312bf4defa34af6deddf9b91ce8c3a3b219cd550028b36416e76390625248```


this doesn't match with FFB214D8B437E7A805C5296021BE52AE31DD542BA4D974640EE2B560EB606A48, from the REMIX step by step.
0

There are 0 answers