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" (there is another similar cause of action called "promissory estoppel" which is an express agreement supported by reliance rather than consideration).
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.