Myocardial infarction (MI) has a 5-year mortality rate of more than 50% due to the lack of effective treatments. Interactions between cardiomyocytes and the MI microenvironment (MIM) can determine the progression and fate of infarcted myocardial tissue. Here, a specially designed Melanin-based composite nanomedicines (MCN) is developed to effectively treat MI by reprogramming the MIM. MCN is a nanocomposite composed of polydopamine (P), Prussian blue (PB) and cerium oxide (Ce
x
O
y
) with a Mayuan-like structure, which reprogramming the MIM by the efficient conversion of detrimental substances (H
+
, reactive oxygen species, and hypoxia) into beneficial status (O
2
and H
2
O). In coronary artery ligation and ischemia reperfusion models of male mice, intravenously injecting MCN specifically targets the damaged area, resulting in restoration of cardiac function. With its promising therapeutic effects, MCN constitutes a new agent for MI treatment and demonstrates potential for clinical application.