A smart contract is a small program stored on a blockchain that runs exactly as written whenever someone calls it. It can hold and move digital assets automatically, like escrow or a token swap, without a middleman. What it cannot do is know anything outside the blockchain by itself, understand intent, or fix its own bugs, and its mistakes usually cannot be undone.
The name is misleading. A smart contract is not smart and is often not a contract in the legal sense. It is closer to a vending machine: put in the right input, get the programmed output, every time, whether or not that output is what anyone actually wanted.
How a smart contract actually runs
A developer writes the contract in a programming language, compiles it, and publishes it to a blockchain in a transaction of its own. From then on the contract has an address, just like a wallet, and can hold assets. Its code is public. Anyone can read it, and anyone can call its functions by sending a transaction to that address.
When you call a function, for example "swap these tokens for those", every node that processes the block runs the same code with the same inputs and must reach the same result. That repetition is what makes the outcome trustworthy: no single company can quietly change the answer. It is also why running code on a public blockchain costs a fee, often called gas, and why complex contracts are expensive to use.
Because everyone must get the same answer, a contract cannot simply look up a website, check the weather or read a bank balance. Those answers might differ between nodes or change over time. Anything from the outside world has to be brought in by someone and written onto the chain.
The vending machine comparison holds up well here. The machine does not know whether you are thirsty, whether the coin was stolen, or whether you pressed the wrong button. It checks the coin, checks the button, and drops the can. Smart contracts are like that, with much more money inside and no attendant to call.
What smart contracts do well
Escrow without a middleman. Funds lock until agreed conditions on the chain are met, then release automatically to the right party.
Issuing and managing tokens. Rules for how many tokens exist and how they move are enforced by code that everyone can inspect.
Swapping assets. Automated exchanges let people trade directly against a pool of assets held by a contract, without an order book run by a company.
Shared wallets requiring several approvals. A multi-signature contract only moves funds when, say, two of three directors sign, which helps companies and families avoid a single point of failure.
Transparent rules. Every rule is public and runs the same for everyone, which removes some types of favouritism and quiet rule changes.
Round-the-clock operation. There are no office hours and no holidays. The contract answers whenever it is called.
Composability. Contracts can call other contracts, so developers can build on existing pieces, much as apps build on shared services.
Audit trails. Every call is recorded on the blockchain, which is useful when parties later disagree about what happened.
What smart contracts cannot do
Know real-world facts by themselves. Prices, delivery confirmations or weather data must be supplied by an "oracle", a service that writes outside data onto the chain. If the oracle is wrong or manipulated, the contract acts on bad data.
Understand intent. If you approve the wrong amount or call the wrong function, the contract does exactly what you asked, not what you meant.
Fix their own bugs. A deployed contract usually cannot be edited. Flaws have been exploited to drain large sums, and the money rarely comes back.
Guarantee legal enforceability. Code running on a blockchain does not automatically count as a valid contract under Vietnamese or any other law. Lawyers still matter.
Keep secrets. Data on a public chain is visible to everyone. Contracts that need confidentiality need extra design work.
Be both upgradeable and fully trustless. Many contracts include admin keys that let a team upgrade the code. That helps fix bugs but means you are trusting whoever holds those keys.
Protect you from signing something harmful. Your wallet will happily sign a malicious approval. The contract has no idea you were tricked.
Token approvals: the permission most people forget they gave
To let an application move your tokens, you usually sign an "approval" that says this contract may spend up to a certain amount of a certain token from your address. Many apps ask for an unlimited approval so you do not have to sign again next time. It is convenient, and it stays in force long after you stopped using the app.
If that contract is later exploited, or if it was malicious from the start, the attacker can pull tokens from every wallet that ever granted it an approval. Many people who lose funds this way had not touched the app for months. They never sent anything; they simply forgot a permission.
The defence is boring but effective. Approve only the amount you need when the wallet allows it. Use a separate wallet with small balances for trying new apps. Every few months, use a reputable approval-checking tool, reached by typing its address yourself, to review and revoke approvals you no longer need. Revoking costs a small fee, which is cheap insurance.
How a business should judge a "smart contract" proposal
Vendors sometimes pitch smart contracts for supply chains, loyalty points or payments. Before signing anything, walk through these questions with your team.
- Ask what problem it solves that a normal database cannot. If everyone involved already trusts one party to keep records, a blockchain may add cost without adding value.
- Identify every oracle. Where does outside data come from, who controls it, and what happens if it is wrong?
- Ask who holds admin keys. Upgradeable contracts mean someone can change the rules. Find out who, how, and with how many approvals.
- Request the audit reports. An independent audit reduces risk but does not remove it. Check the date and whether the audited code is the code actually deployed.
- Plan for failure. What happens to funds and data if the contract has a bug or the vendor disappears?
- Check the legal side. Ask a lawyer whether the arrangement is enforceable and how it interacts with current rules on digital assets in Vietnam.
Frequently asked questions
Is a smart contract legally binding?
Not automatically. Whether code-based arrangements are enforceable depends on the law of each country, so businesses should pair them with a normal written agreement reviewed by a lawyer.
What is an oracle in blockchain?
An oracle is a service that brings outside information, such as a price or a delivery event, onto the blockchain so contracts can use it. It is often the weakest point, because the contract trusts whatever the oracle reports.
Can a smart contract be changed after it is deployed?
Basic contracts cannot. Upgradeable designs can, but only through admin keys held by someone, which reintroduces trust in that person or team.
Does an audit mean a contract is safe?
An audit lowers risk but does not eliminate it; audited contracts have still been exploited. Check what was audited, when, and whether later changes were reviewed.
How do I revoke token approvals?
Use a reputable approval-checking tool or your wallet's built-in permission page, reached by typing the address yourself, then revoke what you no longer use. Each revoke is a small on-chain transaction with a fee.