getContractTokenData method

Future<CoinGeckoResult<Coin?>> getContractTokenData({
  1. required String id,
  2. required String contractAddress,
})

Get coin info from contract address.

id sets asset platform identifier.

contractAddress is token's contract address.

Query: /coins/{id}/contract/{contract_address}

Implementation

Future<CoinGeckoResult<Coin?>> getContractTokenData({
  required String id,
  required String contractAddress,
}) async {
  final response = await _dio.get(
    '/coins/$id/contract/$contractAddress',
  );
  if (response.statusCode == 200) {
    final data = Coin.fromJson(response.data);
    return CoinGeckoResult(data);
  } else {
    return CoinGeckoResult(
      null,
      errorCode: response.statusCode ?? null,
      errorMessage: '${response.statusMessage} - ${response.data.toString()}',
      isError: true,
    );
  }
}