The problem of code design for random access channels with erasures in which the number of users in each frame is unknown at the transmitters but known at the receiver is investigated. The problem is of significant importance as the future shows the emergence of networks of many devices in the context of cyber-physical systems. A two-layer architecture for joint contention resolution and erasure correction is presented. For random LDPC codes based on this scheme, the density evolution is asymptotically analyzed, which enables optimized code design for maximized throughput with constrained outage. The results demonstrate that the proposed scheme with a constrained complexity approaches the outage capacity of the random access channel with erasures when the average number of active users is small.