In U.S. law, when one does work when there is an intent that the person doing it be paid but there is no specific agreement as to price, there is a legal entitlement to compensation for the fair market value of the work.
Doctrinally, this does not really follow from contract law in the strict sense, because there is not a meeting of the minds as to all essential terms of the agreement of the parties.
This is called "quantum meruit" a.k.a. "restitution" a.k.a. "unjust enrichment", a.k.a. "quasi-contract" a.k.a. an "implied in fact contract" a.k.a. "implied in law contract" (there is another similar cause of action called "promissory estoppel" which is an express agreement supported by reliance rather than consideration). See, e.g., Candace Kovacic-Fleischer, "Quantum Meruit and the Restatement (Third) of Restitution and Unjust Enrichment" 27(127) Review of Litigation (2007 as a conference paper, printed in 2012):
Thirty years ago, Professor Graham Douthwaite said that restitution
can "arise in a bedazzling variety of situations" and that
practitioners usually are not aware of "the restitutionary
implications or potential" of their clients' problems. He said that
the lack of understanding can be attributed confusion in its
terminology and application. The confusion has continued and can also
be attributed to the age of the Restatement of Restitution, which was
published in 1937. The field should be made more accessible since the
American Law Institute is drafting a new Restatement of Restitution
and Unjust Enrichment, the Restatement (Third). The new Restatement is
bringing clarity and precision to the field of restitution and unjust
enrichment. This paper evolved from a brief talk given at the Remedies
Workshop of the American Association of Law Schools Annual Meeting in
January, 2007. I focus on the clarity that the Third Restatement is
bringing to the confusing area known as quantum meruit. This paper
will describe some of the confusion that existed, and continues to
exist, in quantum meruit litigation. It will then discuss how the
Third Restatement's approach should eliminate much of the confusion.
Keywords: restitution; Restatement of the Law of Restitution;
Restatement (Third) of the Law of Restitution and Unjust Enrichment:
quantum meruit; contract implied in fact; contract implied in law;
quasi contract
This principle also exists in civil law countries (dating back to the Roman law era) from which U.S. common law has somewhat reluctantly borrowed the concept (a reluctance reflected in the varied names for the concept).
On the other hand, if there is not an intent that the person doing work be paid, then it is a gratuitous provision of services and no right to secure payment.
Generally speaking, it is the intent of the person doing the work, if it is not clarified, and the understanding of the person for whom the work is done of the intent of the person doing the work, as discernible from an outside observer, which is relevant, to the extent that the situation is not clarified. Purely subject intent isn't what matters, intent reasonably inferable from context and conduct is what matters.
One of the classic examples is a case where painters come to your house and paint it for you, because they actually were hired to paint the house next door and made a mistake regarding the address. The owner of the house knows that this is what is happening and fails to correct them. The home owner is liable to the painters for the fair market value of their services even though they had no contract.
Another classic example, dating back to Roman law, involves a farmer who is temporarily unable to work on his farm because he is ill and taking to another family member's home or is drafted to serve in war and can't return in time to plant or harvest, for example. A neighbor working the farm for the absent farmer is entitled to compensation for the work done for the benefit of the neighbor without having a purely gratuitous intent.
In a more modern example, this can be a basis of compensation when contract formation is impossible. For example, if an unconscious person is put in an ambulance and then transported to an ER where the person receives necessary life saving surgery, the ambulance provider and ER professionals are entitled to payment on this basis.
This can also be applied when for some reason that doesn't justify a total lack of compensation, a contract fails to be formed, perhaps because it is not in writing when the law requires that, or because a party lacked the capacity to agree to a contract.
It is sometimes used as a basis for a remedy when the person for whom services are to be performed on a commission, or contingent fee basis that based a contractual right to compensation upon completion of the performance is prevented from completing the performance in a way that quantifies the compensation by the person for whom the work was to be done.