setNodeUrl method

  1. @override
Future<bool> setNodeUrl({
  1. required String nodeUrl,
  2. bool queryNetworkId = true,
})
override

Set the target node that the API to send requests to. Example: https://api.chainweb.com If queryNetworkId is true, this will fetch the networkId from the node's config and store it for future use. Returns true if it was able to get the networkId from the node.

Implementation

@override
Future<bool> setNodeUrl({
  required String nodeUrl,
  bool queryNetworkId = true,
}) async {
  // Remove trailing slash if present
  _nodeUrl = nodeUrl.endsWith('/')
      ? nodeUrl.substring(0, nodeUrl.length - 1)
      : nodeUrl;

  if (queryNetworkId) {
    try {
      // Get the networkId from the node's config
      http.Response response = await http.get(Uri.parse('$_nodeUrl/config'));
      Map<String, dynamic> config = jsonDecode(response.body);
      _networkId = config['chainwebVersion'];
    } catch (_) {
      return false;
    }
  }

  return queryNetworkId;
}