This work presents a novel blockchain-based energy trading mechanism for electric vehicles consisting of day-ahead and real-time markets. In the day-ahead market, electric vehicle users submit their bidding price to participate in the double auction mechanism. Subsequently, the smart match mechanism will be conducted by the charging system operator, to meet both personal interests and social benefits. After clearing the trading result, the charging system operator uploads the trading contract made in the day-ahead market to the blockchain. In the real-time market, the charging system operator checks the trading status and submits the updated trading results to the blockchain. This mechanism encourages participants in the double auction to pursue higher interests, in addition to rationally utilize the energy unmatched in the auction and to achieve the improvement of social welfare. Case studies are used to demonstrate the effectiveness of the proposed model. For buyers and sellers who successfully participate in the day-ahead market, the total profit increase for buyer and seller are 22.79% and 53.54%, respectively, as compared to without energy trading. With consideration of social welfare in the smart match mechanism, the peak load reduces from 182 to 146.5 kW, which is a 19.5% improvement.