FuelAddress.fromString constructor

FuelAddress.fromString(
  1. String s
)

Implementation

factory FuelAddress.fromString(String s) {
  try {
    if (s.startsWith(_hrp)) {
      final decoded = bech32m.decode(s);
      return FuelAddress(
        bech32Address: s,
        b256Address: hex.encode(bech32m.fromWords(decoded.words)),
      );
    } else {
      final bytes = hex.decode(removeHexPrefix(s));
      final words = bech32m.toWords(Uint8List.fromList(bytes));
      return FuelAddress(
        bech32Address: bech32m.encode(Decoded(prefix: _hrp, words: words)),
        b256Address: s,
      );
    }
  } catch (e) {
    throw Exception('Invalid Fuel address $s: $e');
  }
}