Join our Newsletter — 33% off our NHI Course
Home› Guides› Smart Contract Security for Beginners: How Blockchain Code…
Guide Application Security

Smart Contract Security for Beginners: How Blockchain Code Gets Hacked and Protected

PDF for newsletter subscribers · free to read online

← All guides
By NHI Mgmt Group, under the editorial direction of Lalit Choda Updated 28 November 2026 11 min read
On this page

Smart contract security is keeping the programs that run on a blockchain from being tricked into losing money.

This guide is for students, new developers and crypto users who want to know how blockchain code gets hacked. It covers security only and gives no investment advice. You do not need to write code: if you use crypto apps, your money may sit inside smart contracts.

In short

  • A smart contract is a program on a blockchain that holds and moves money by fixed rules.
  • Its code is public, anyone can use it, and it is usually hard to change once it is live.
  • Common problems are steps done in the wrong order, buttons anyone can press, bad price data and stolen admin keys.
  • Defences include testing, independent reviews, bug rewards, shared admin keys and an emergency pause.

What you will learn

  • Explain what a smart contract is in one sentence.
  • Spot the four common ways smart contracts get attacked.
  • Check the basic safety signs before you trust a crypto app.
  • Ask a project the right questions about reviews and admin keys.
Shared online record (blockchain)
a public record of transactions copied across many computers, which is very hard to change afterwards.
Blockchain program (smart contract)
code stored on a blockchain that runs by fixed rules when someone uses it.
Control key (admin key)
a secret key that lets its holder change settings or upgrade a contract.

What is smart contract security?

Think of a vending machine. You put in the right coins, press a button and the machine hands over a drink. Nobody behind the counter needs to approve it. The rules are built into the machine.

A smart contract works the same way. It is a program stored on a blockchain (a shared online record) that follows its rules whenever someone uses it. The Ethereum project itself describes the vending machine as a good picture of a smart contract.[1] Contracts can hold money, swap one token for another or lend and borrow.

Smart contract security means making sure those rules cannot be bent. Everything inside a contract is public, including values marked "private" in the code.[2] Anyone can try any button in any order. Once a contract is live, its code usually cannot be changed directly.[3]

Where the comparison stops working: a broken vending machine loses a few drinks, and the owner can open it and fix it. A flawed smart contract can lose everything it holds in one go, and there is often no back panel to open.

Why does it matter?

Smart contracts often hold large sums, and payments made through them are usually final. One open security list counts more than 1.42 billion US dollars in reported losses across the incidents it studied.[4]

If you use crypto apps

What could happen: money you put into an app is drained through a flaw in its contract, and it cannot be recovered.

Check this: look for published security reviews, a bug reward scheme and who controls the admin keys.

Next: Crypto Wallets and Keys for Beginners

If you are learning to build on a blockchain

What could happen: a small mistake in the order of two lines lets someone take more than their share.

Check this: use well-reviewed shared code where you can, and test on a practice network first.

Next: Smart Contract Auditor for Beginners

If you run a crypto project

What could happen: one person's admin key is stolen, and the thief upgrades your contract to send funds to themselves.

Check this: require several people to approve admin actions, and add a delay before changes take effect.

Next: Key Management for Beginners

What does it look like?

Real contracts are written in code. Here are the rules of a made-up savings pot, written in plain words, with four weak spots marked.

Example only. All values are made up.

Contract: Community Savings Pot (EXAMPLE, not real code)
Rule 1: anyone can put tokens in
Rule 2: you can take out only what you put in
Rule 3: send the tokens first, update the balance after  (1)
Rule 4: setFee() can be used by: anyone                  (2)
Rule 5: token price comes from: one small market only    (3)
Admin key: held by one person, key EXAMPLE-0000-FAKE     (4)
  1. Wrong order. A caller may be able to ask again before the balance is updated, and take more than their share.
  2. An open door. A rule meant for the owner can be used by anyone.
  3. Weak price data. A single small market is easier to push up or down for a moment.
  4. In a real file, this line would contain the address of a single key that can change everything.

Why this is risky: the code is public, so attackers can read these weak spots as easily as you can. Each one is a known way in for attackers.[3][5]

The safer way: update the balance before sending, and lock owner-only rules to the owner. Use more than one price source, and share admin control between several people.

How does it work?

Here is the life of a smart contract, and where security fits in.

  1. Write. A developer writes the contract's rules in code, ideally reusing shared code that many people have already reviewed.[5]
  2. Test. They test it on a practice network and use tools that look for known mistakes.
  3. Review. An independent team reads the code and reports problems. This is called an audit. Audits help, but they may not catch every bug.[5]
  4. Go live. The contract is published to the blockchain. From now on its code is public and usually cannot be changed directly.[3]
  5. Watch and reward. The team watches for odd activity and pays a reward, called a bug bounty, to people who report flaws safely.[5]
  6. Upgrade with care. Some contracts can be swapped for a new version through a go-between contract, called a proxy. Whoever holds the upgrade key holds a lot of power, so it should need several approvals and a delay.[3]
Diagram titled The life of a smart contract, with five boxes in a row. Box 1, Write: rules in code, reuse reviewed parts. Box 2, Test: practice network and checking tools. Box 3, Review: an independent audit; helps, may not catch everything. Box 4, Go live: public and usually hard to change. Box 5, Watch: bug rewards, alerts, a shared-key pause. A green bar underneath says most fixes are cheapest before the contract goes live.
Figure 1. Security work happens before and after a contract goes live, but fixes are easiest before.

Most attacks fall into a few families. Figure 2 shows four of the most common, in plain words.

Diagram titled Four common ways smart contracts get attacked, with four boxes. Wrong order, called reentrancy: money is sent before the balance is updated, so a caller may ask again. Open door, called access control: an owner-only button can be pressed by anyone. Bad price data, called oracle manipulation: a price feed is pushed up or down for a moment. Stolen admin key: one person's key is taken and used to change the contract. A green bar underneath says order steps carefully, lock owner buttons, use several price sources and share admin keys.
Figure 2. Four common ways a smart contract gets attacked, and the habit that helps with each.

The first three are flaws in the rules. In reentrancy, another contract calls back in before the first request has finished, often to drain funds. In an access control flaw, an important rule is left open to anyone. In oracle manipulation, attackers skew the price data a contract relies on, often with a very short-term loan.[5] The fourth is about keys, not code, and is covered by the practitioner guide.

A worked example

Kemal Novak is a fictional computer science student. Thistle Nursery, a small plant shop, asks him to build a reward scheme. Customers would earn tokens with each visit and swap them for discounts.

Kemal writes a first version in a weekend. Before he publishes it, he remembers the vending machine. Anyone in the world will be able to press every button, in any order.

So he tests it on a practice network first. A checking tool flags that his "send tokens" step comes before the balance update. He swaps the order, so the balance changes first.

Next, he reads his own rules as a stranger would. The rule that sets the reward rate has no lock on it. He limits it to the shop's account.

He then thinks about keys. Only he holds the admin key, and he will graduate next year. He sets it up so that two of three people must approve any change: himself, the shop owner and the shop's accountant.

A friend from his course reads the code and spots nothing else. Kemal is honest with the shop. A friendly review is not a full audit, so he suggests keeping only small amounts in the scheme.

The shop launches with low limits. A year later, a new developer takes over, and the shared key makes the handover smooth.

Myths and mistakes

What people thinkWhat is true
Code on a blockchain is secure by design.The blockchain records what the code does. If the code has a flaw, the blockchain faithfully records the loss too.
An audited project is safe.Audits help, but they may not catch every bug, and later changes need fresh review.[5]
Marking a value "private" hides it.Everything in a contract is publicly visible, even values marked private.[2]
We can just fix bugs after launch.Most contracts cannot be changed directly once live. Upgrade routes exist, but they add risk of their own.[3]
Hacks are always about clever code.Weak control of admin keys can let someone make changes they should not, even when the code itself is fine.[3]

What can I do this week?

  • Before using a crypto app, look for its published audits and bug reward scheme.
  • Find out who holds the app's admin keys and whether changes need several approvals.
  • If you build, test every contract on a practice network before going live.
  • Read the Ethereum project's page on smart contract safety.
  • Keep only amounts you can afford to lose in new or unreviewed contracts.

Checklist

  • The contract reuses well-reviewed shared code where possible.
  • Balances are updated before money is sent out.
  • Owner-only rules are locked to the owner.
  • Prices come from more than one trusted source.
  • The code has been tested and independently reviewed before going live.
  • Admin actions need several approvals and a delay.
  • A bug reward scheme is in place.
  • Someone watches the contract for odd activity and knows how to pause it.

Common questions

Can a hacked smart contract be fixed?

Sometimes, but usually not directly. Most contracts cannot be changed once live. Some are built to be upgraded through a go-between contract, and some have an emergency pause. Stolen funds are hard to trace and often cannot be recovered, so prevention matters most.

What is a smart contract audit?

It is an independent review of the contract's code by specialists who look for flaws before launch. A good audit report lists what was checked and what was found. It is a snapshot, so any later change to the code needs reviewing again.

Is my crypto wallet a smart contract?

Usually not. A standard wallet is an app or device that holds your keys. When you use a crypto app, though, your wallet often sends money into that app's smart contracts. That is when the contract's security starts to matter to you.

Do I need to learn to code to judge a project?

No. Anyone can check a few signs. Look for published audits and a bug reward scheme. See how long the contract has been live, and whether admin keys need several approvals. Good signs do not make a project safe, but missing signs are a warning.

Where next?

Ready for the detail? Read the practitioner guide: Smart Contract Security Guide. It goes further into the main flaw families, testing and review methods, and how to protect upgrade and admin keys.

Also useful:

Related NHI Mgmt Group resources: Crypto Scams for Beginners · Blockchain and Distributed Ledger Security Guide

Key terms

Smart contract
Code stored on a blockchain that runs by fixed rules when someone uses it.
Blockchain
A shared public record of transactions that is very hard to change afterwards.
Reentrancy
A flaw where a caller gets back into a contract before its first request has finished.
Oracle
A data feed that brings outside information, such as prices, into a smart contract.
Smart contract audit
An independent review of contract code to find flaws, ideally before launch.
Bug bounty
A reward paid to people who find and safely report security flaws.
Proxy contract
A go-between contract that passes requests on, so the code behind it can be swapped.
Private key
The secret key that proves you control an account and lets you approve actions.

Sources and further reading

  1. Introduction to smart contracts. ethereum.org. https://ethereum.org/en/developers/docs/smart-contracts/, accessed 28 Nov 2026.
  2. Security Considerations. Solidity documentation. https://docs.soliditylang.org/en/latest/security-considerations.html, accessed 28 Nov 2026.
  3. Upgrading smart contracts. ethereum.org. https://ethereum.org/en/developers/docs/smart-contracts/upgrading/, accessed 28 Nov 2026.
  4. OWASP Smart Contract Top 10 (2025). OWASP Foundation. https://owasp.org/www-project-smart-contract-top-10/, accessed 28 Nov 2026.
  5. Smart contract security. ethereum.org. https://ethereum.org/en/developers/docs/smart-contracts/security/, accessed 28 Nov 2026.

PDF for subscribers

Take this guide with you

Every section, table and checklist in one PDF, with links to the sources and related guides. Subscribe to our weekly NHI & AI Identity Journal and we’ll email you a download link.

Free weekly newsletter

Subscribe to the NHI & AI Identity Journal

The latest on NHI and Agentic AI security – articles, research, breaches, news and events every week.

Bonus 33% off our NHI Course when you subscribe.

PDF Downloads for Newsletter Subscribers

Get the guide

Enter your details and we’ll email you a download link.

The full guide is free to read online. The PDF is a thank you for subscribing.

Fill in all fields marked * and tick both boxes to continue.