The best way to create an electromagnet can be achieved by following these steps:
1- You just wrap an insulated wire around a material that has ferromagnetic properties
2- You then apply an electric current.
As simple as this, now you have your electromagnet.