Abstract. In a sensor network of n nodes in which k of them have sensed interesting data, we perform in-network erasure coding such that each node stores a linear combination of all the network data with random coefficients. This scheme greatly improves data resilience to node failures: as long as there are k nodes that survive an attack, all the data produced in the sensor network can be recovered with high probability. The in-network coding storage scheme also improves data collection rate by mobile mules and allows for easy scheduling of data mules. We show that using spatial gossip we can compute the erasure codes for the entire network with a total of near linear message transmissions, thus improving substantially the communication cost in previous scheme [5]. We also extend the scheme to allow for online data reconstruction, by interleaving spatial gossip steps with mule collection. We present simulation results to demonstrate the performance improvement using erasure codes.