The House, in a backhand slap at states calling for a rein on federal spending, yesterday rejected an attempt to preserve $2.3 billion in federal revenue-sharing grants to the states.

The vote was unusually close, 1965 to 190, raising questions about whether the House will prevail in conference with the Senate, which has voted to continue the present revenue-sharing program intact.

Yesterday's action upheld a recommendation by the House Budge Committee, which deleted the states' money on grounds that they no longer need it.

Rep. Robert N. Giaimo (D-Conn.), the committee's chairman, told the House that, with most states now running surpluses, it is time to cut back. Years age, he said, states "were hurting. But now the situation is reversed."

The proposal to preserve the revenue-sharing funds was sponsored by Rep. Barber Conable (R-N.Y.), who argued that eliminating them would force many states into deficit and result in higher property taxes.

When revenue sharing was initiated in 1972, states were included primarily as a political gesture to help push the plan through Congress. The program now totals $6.9 billion a year, with a third going to states and two-thirds to localities.

Giaimo told the House yesterday that Congress "may have made a deal" with the states when the program was enacted, "but I don't think it's legal contract." He said the federal government is now "in trouble" financially and cannot afford it.

State legislatures have been pressuring Congress to balance the federal budget, and almost three dozen states have passed resolutions calling for a constitutional amendment to prohibit a federal deficit. House leaders have opposed any such move.

The chamber also rejected a compromise proposal by Rep. Olympia J. Snowe (R-Maine) that would have restored revenue sharing grants for states in exchange for a 5 percent cut in a broad range of other federal grant programs. That vote was 237 to 147.

The House is well behind schedule on the fiscal 1980 budget resolution and probably will not complete work until late in the week. The Senate already has passed its own version. Under the five-year-old congressional budget process, the two houses must agree on a compromise by May 15.