This paper proposes a novel framework, SmartCoder-R1, based on Qwen2.5-Coder-7B, to address vulnerabilities arising during smart contract generation. SmartCoder-R1 is trained to generate secure and explainable smart contracts through a series of steps: Continual Pretraining (CPT), Long Chain-of-Thought Supervised Fine-Tuning (L-CoT SFT), and Security-Aware Group Relative Policy Optimization (S-GRPO). It outperforms 17 existing models on 756 real-world function benchmarks, and the quality of the generated inferences is also highly evaluated.