Of course. For example, the law guarantees that I don't have to perform labor for someone else if I don't want to. An employment contract obligates me to.
Similarly, it's entirely possible to enter into a contract limiting your freedom of speech.
The entire point of a contract is to promise to do, or not to do, something that you could have freely chosen to do or not to do under the law without any contract.