What I have is signed work agreement.
It specifies deliverables, cost, cost and process of scope changes, an short term maintenance agreement(with cut off date) and how the software is licensed (I only deliver software which has an open source license, MIT usually).
Licensing the software under open source lets the client have it, and frees me to reuse it for other projects. There is also a warranty clause in the license.
Twice in 20 years I have not gotten paid. Neither time I had an agreement, both were for small amounts.
But, if you have large clients, a large budget, or intellectual property is an issue then consider a lawyer, and one who has dealt with software projects before.