I heard Messenger of Allah ﷺ saying: "Before Allah created the creations, He wrote a Book (wherein He has written): "My Mercy has preceded my Anger.' And that is written with Him over the Throne." (see Hadith 3194)
أَنَّهُ سَمِعَ أَبَا هُرَيْرَةَ ؓ يَقُولُ سَمِعْتُ رَسُولَ اللَّهِ ﷺ يَقُولُ إِنَّ اللَّهَ كَتَبَ كِتَابًا قَبْلَ أَنْ يَخْلُقَ الْخَلْقَ إِنَّ رَحْمَتِي سَبَقَتْ غَضَبِي فَهْوَ مَكْتُوبٌ عِنْدَهُ فَوْقَ الْعَرْشِ