Solar-powered sensor nodes have incentive to spend extra energy, especially when the battery is fully charged, because this energy surplus would be wasted otherwise. In this paper, we consider the problem of utilizing such energy surplus to adaptively adjust the redundancy level of erasure codes used in communication, so that the delivery reliability is improved while the network lifetime is still conserved. We formulate the problem as maximizing the end-to-end packet delivery probability under energy constraints. This formulated problem is hard to solve because of the combinatorics involved and the special curvature of its objective function. By exploiting its inherent properties, we propose an effective solution called SolarCode, which has a constant approximation ratio. We evaluate SolarCode in the context of our solar-powered sensor network testbed. Experiments show that SolarCode is successful in utilizing energy surplus and leads to higher data delivery reliability.