This is an example:
https://dolmenweb.it/viewers/openlayer/examples/wmts-ign.html
This is the code for OkMap:
var resolutions = []; var matrixIds = []; var proj3857 = ol.proj.get('EPSG:3857'); var maxResolution = ol.extent.getWidth(proj3857.getExtent()) / 256; for (var i = 0; i < 18; i++) {matrixIds[i] = i.toString(); resolutions[i] = maxResolution / Math.pow(2, i);} map.addLayer(new ol.layer.Tile({source: new ol.source.WMTS({url: 'https://wxs.ign.fr/<CLES>/geoportail/wmts/', layer: 'GEOGRAPHICALGRIDSYSTEMS.MAPS', matrixSet: 'PM', format: 'image/jpeg', projection: 'EPSG:3857', tileGrid: new ol.tilegrid.WMTS({origin: [-20037508, 20037508], resolutions: resolutions, matrixIds: matrixIds}), style: 'normal', attributions: '<a href="https://www.ign.fr/" target="_blank"><img src="https://wxs.ign.fr/static/logos/IGN/IGN.gif" title="IGN" alt="IGN"></a>'})}));