4.2.1 is the latest iOS that you can install on an iPhone 3G.
Update can be done only by connecting the iPhone 3G to the
computer with the supplied cable and using iTunes to do the
update. Over the air or wifi updates are available only in iPhones
using iOS 5 or later.
Update should not erase your contacts. But as with any OS update,
backup first. Your contacts should already be in the appropriate
program on your computer/in iCloud/in Google contacts. If they are
not already synced somewhere, do so before attempting to update.
Same for your pictures and anything else that exists only on your
iPhone without backup elsewhere.