getCreate2Address function

EthereumAddress getCreate2Address(
  1. String from,
  2. String salt,
  3. String initCodeHash
)

Implementation

EthereumAddress getCreate2Address(
    String from, String salt, String initCodeHash) {
  if (hexToBytes(initCodeHash).length != 32) {
    throw ArgumentError("initCodeHash must be 32 bytes $initCodeHash");
  }

  var startBytes = hexToBytes('0xff');
  var factoryBytes = hexToBytes(from);
  var saltBytes = keccak256(hexToBytes(salt));
  var initCodeHashBytes = hexToBytes(initCodeHash);

  return EthereumAddress(keccak256(Uint8List.fromList(
          startBytes + factoryBytes + saltBytes + initCodeHashBytes))
      .sublist(12));
}