We introduce a numerical method, based on modified hat functions, for solving a class of fractional optimal control problems. In our scheme, the control and the fractional derivative of the state function are considered as linear combinations of the modified hat functions. The fractional derivative is considered in the Caputo sense while the Riemann-Liouville integral operator is used to give approximations for the state function and some of its derivatives. To this aim, we use the fractional order integration operational matrix of the modified hat functions and some properties of the Caputo derivative and Riemann-Liouville integral operators. Using results of the considered basis functions, solving the fractional optimal control problem is reduced to the solution of a system of nonlinear algebraic equations. An error bound is proved for the approximate optimal value of the performance index obtained by the proposed method. The method is then generalized for solving a class of fractional optimal control problems with inequality constraints. The most important advantages of our method are easy implementation, simple operations, and elimination of numerical integration. Some illustrative examples are considered to demonstrate the effectiveness and accuracy of the proposed technique.Recently, numerical methods based on modified hat functions have shown to provide an effective way for solving fractional differential equations [15,16]. Here, for the first time in the literature, we introduce such a method for solving a general class of fractional optimal control problems. More precisely, in this work we begin by considering the following fractional optimal control problem (FOCP):