Sorry - there is no special way to make your Tamagotchi immortal.
Whatever you've heard, whatever code or tip - you still have to feed 'em and play games or snack/treat them to keep their hearts full.
If they empty their hearts and you don't re-fill them, they will eventually die...
Best, etc.
TamaMum