getLensMessage method
Implementation
Future<Map<String, String>> getLensMessage(String address) async {
try {
final Map<String, String> headers = {'Content-Type': 'application/json'};
final Map<String, dynamic> requestBody = {
'query': '''
query Challenge(\$request: ChallengeRequest!) {
challenge(request: \$request) { text }
}
''',
'variables': {
'request': {
'address': address,
},
},
};
final response = await http.post(
Uri.parse('https://api.lens.dev/'),
headers: headers,
body: jsonEncode(requestBody),
);
if (response.statusCode == 200) {
final Map<String, dynamic> responseData = jsonDecode(response.body);
final String text = responseData['data']['challenge']['text'] as String;
return {'message': text};
} else {
throw Exception('failed to get lens message');
}
} catch (error) {
throw Exception('error getting lens message => $error');
}
}