Yes,this is very important that you erase all your data when you are selling your iPhone to another person or you are giving your iPhone to another person.But you will you face some problem while erasing the data from iPhone.When you will try to erase all the data then it will freeze you in the "Apple logo screen",which is very problematic.
May be you are thinking that restoring should be the best solution.But in this case you will be unable to do it .Cause Apple put another layer of security. This layer of security validates any and all restores with a ECID value.Which checks whether the firmware is tempered and in this case it will be jailbroke.So,it will not restore it to the firmware 3.0.So,what to do?
But you have also got solution.The solutions are below and for your convenience those are step by step:
1.Update the firmware at first and for the safety precaution what you need to do first is to save the phone's ECID with Saruki's server.
Example:If you are using firmware 3.0 or 3.1 then upgrade it with the latest version and do the steps above.You will be successful.
Please let me know via comments if it works!