Quick answer
A smart contract is not, in itself, a contract. It is code that executes conditions automatically. The contract that binds the parties arises from consent over an object and a cause, under the Civil Code (Código Civil). If those requirements are met, the agreement is valid even when it runs on a blockchain.
A contract and code are not the same thing
The common mistake is to treat the program running on the chain as if it were the contract. It is not. The contract is the source of the right: the meeting of wills that creates obligations between the parties. The smart contract is an execution tool that turns part of that agreement into instructions which run on their own once certain conditions are met. The distinction is not academic; it tells you where to look for the governing law when something goes wrong.
Under Spanish law, a contract exists from the moment one or more persons consent to bind themselves towards another or others to give something or render a service (Civil Code (Código Civil), Art. 1254). That obligation is perfected by mere consent and binds the parties not only to what was expressly agreed, but also to the consequences that flow from good faith, usage and the law (Art. 1258). Code deployed afterwards neither adds nor removes validity from the agreement: it executes it.
What the Civil Code requires for a contract to exist
An agreement produces effects as a contract only when three requirements concur: consent of the contracting parties, a definite object that is the subject matter of the contract, and a cause for the obligation established (Civil Code (Código Civil), Art. 1261). Consent is shown by the meeting of the offer and the acceptance over the thing and the cause that are to constitute the contract (Art. 1262).
Consent
A cryptographic signature or an on-chain transaction can serve as proof that someone accepted, but it is not consent itself. If a party did not understand the scope of the agreement, was led into error, or the program's logic does not reflect what they meant to agree, consent may be vitiated regardless of whether the transaction was confirmed on the chain. A script does not cure defective consent.
Object and cause
The object must be determinate and lawful; the cause must exist and be true. A smart contract that transfers a token does not, on its own, establish what that token represents or why it is being transferred. That correspondence between what the code moves and the underlying legal transaction must be documented off-chain.
Freedom of form and evidentiary value
Spanish law starts from freedom of form: contracts are binding whatever the form in which they were entered into, provided the essential conditions for their validity concur (Civil Code (Código Civil), Art. 1278). That is why an agreement set down in programming language can be valid, just as a verbal or paper one would be.
Proof is a separate question. A blockchain record provides a trail of integrity and timestamping that is hard to alter, which strengthens its value as evidence that a transaction occurred and when. Where electronic signatures or identification systems are involved, their legal effect rests on the European framework for electronic identification and trust services (Regulation (EU) 910/2014, eIDAS), updated by the European digital identity regulation (Regulation (EU) 2024/1183, eIDAS2). The fact that something is recorded on-chain proves the technical event; it does not automatically turn that event into an enforceable right if a valid legal transaction is missing behind it.
What prevails in the event of a conflict
Here is the hard case: the contract document says one thing and the code does another. Perhaps the program contains a bug, perhaps it enforces a penalty the parties never intended, perhaps an update changed its behaviour. The governing rule applies here: the legal contract is the source of the right and the smart contract merely executes it. Where there is a conflict, what prevails must be defined in advance.
The prudent approach is for the written contract itself to include a precedence clause stating that, where the legal text and the code's behaviour diverge, the text prevails, and setting out how faulty execution is corrected and the parties are restored. Without that provision, the conflict is resolved by the general rules on interpreting and supplementing the contract, which adds uncertainty and litigation risk. The code does not decide the law; it applies it.
When code alone is not enough
There are transactions where technical execution on-chain does not produce the intended legal effect without additional acts that the law requires.
Transfer of real estate
Ownership and other rights in rem over property are acquired and transferred as a consequence of certain contracts through delivery, that is, under the doctrine of title and mode (título y modo) (Civil Code (Código Civil), Art. 609). Transferring a token that represents a property does not transfer ownership of the property: the mode is missing, and for the change to be enforceable against third parties, the corresponding entry in the Land Registry is required. An on-chain transfer does not replace title or mode.
Securities and financial instruments
Where what is tokenised are transferable securities or financial instruments, representation through distributed ledger technology systems requires an entity responsible for keeping and administering the entries, a role played in the Spanish framework by the entity responsible for registration and recording (ERIR) provided for in securities markets legislation (Ley 6/2023 (LMVSI)). Deploying a smart contract does not substitute for that function or for the authorisation that the law reserves to specific persons.
Good practices so the smart contract reflects a valid contract
The goal is not to choose between document and code, but to make both say the same thing and recognise each other.
- Binding legal document. Draft a contract that captures consent, object and cause, identifies the parties and describes the transaction. It is the source of the right.
- Precedence clause. Establish that the legal text prevails over the code's behaviour and govern the correction of execution errors.
- Traceability between text and code. Expressly link the deployed contract's address and version to the document, so it is clear which code corresponds to which agreement.
- Identification and signature. Use signature and identification mechanisms with recognised legal effect where the transaction requires it (Regulation (EU) 910/2014 and Regulation (EU) 2024/1183).
- Change governance. Define who can update or halt the contract, in what cases and with what legal consequences.
- Compliance with required form. For real estate, securities or other cases with their own legal requirements, complete the acts the law imposes off-chain.
Frequently asked questions
Is a smart contract a legally binding contract?
Not in itself. It is code that executes conditions. It will bind the parties when there is a valid agreement behind it, with consent, object and cause, under the requirements of the Civil Code (Código Civil) (Art. 1261).
Do I need a written contract if I already have the code deployed?
Spanish law allows freedom of form (Art. 1278), but the written document provides legal certainty, proof of the agreement, and lets you include a clause that defines what prevails in the event of a conflict with the code.
What happens if the code executes something different from what was agreed?
The legal contract is the source of the right. If there is a precedence clause, what was agreed in the text prevails; failing that, the general rules on interpretation and supplementation apply, with the resulting uncertainty.
Can I transfer real estate with a token alone?
No. Transferring ownership of real estate requires title and mode (Art. 609) and, against third parties, registration in the Land Registry. Moving a token does not, on its own, transfer the right in rem.
What this means for you
If you are going to tokenise an asset or automate an agreement, treat the smart contract as the execution tool and not as the contract. Draft the legal transaction first, make sure consent, object and cause concur, set out in writing what prevails in the event of a conflict, and complete the formal requirements the law imposes for the specific asset. That way the code executes a valid right instead of creating a risk that is hard to reverse.
This content is for general information and educational purposes only. It is not legal, tax or investment advice and does not replace consultation with a qualified professional. Regulation on tokenisation and crypto-assets evolves; always check the version in force of the rules cited in the BOE (boe.es) and EUR-Lex (eur-lex.europa.eu).