Follow these steps to write a bass line for a melody
1. Start and end with the tonic note.
2. Avoid similar motion and use contrary motion to melody and it makes the music sound interesting.
3. Avoid leaps and use auxiliary notes when there are long notes in melody
4. A strong cadence is always a success. So make sure to use notes of dominant chord in the penultimate bar.
5. Call your bass guitarist!