Book a free call

How to Deploy a Smart Contract on Ethereum

Deploying a smart contract on Ethereum means publishing its code to the network so anyone can call it. Here is the full process, from writing to verification.

Hertiv engineering teamReviewed by a senior engineer
9 min read
How to Deploy a Smart Contract on Ethereum
On this page

Short answer

Deploying a smart contract on Ethereum means publishing compiled contract code to the network in a transaction, which gives the contract an address that anyone can call. The process has five stages: write the contract in Solidity, compile it, test it on a local network and a testnet, deploy it from a wallet funded with ETH, and verify the source code on a block explorer so others can read it.

What does deploying a smart contract mean?

Deploying a smart contract on Ethereum means publishing compiled contract code to the network in a transaction, which gives the contract an address that anyone can call. Before deployment, a contract is just code on your computer. After deployment, it lives on Ethereum, runs exactly as written, and cannot be changed unless the code itself allows upgrades.

The deployment transaction is an ordinary Ethereum transaction with one difference: instead of sending ETH to an address, it carries the contract's bytecode, and the network creates a new address for it. That address is the contract's permanent home. Every later interaction, whether a token transfer or a vote in a DAO, is a transaction sent to that address.

Deployment costs gas, paid in ETH, and the cost depends on the size of the contract and the gas price at the time. A small contract can cost a few dollars' worth of ETH; a large one can cost far more. That is why testing comes first: a bug found after deployment cannot be fixed by editing the code, only by deploying a new contract and moving users to it.

StageWhat happensWhere
WriteContract code in SolidityEditor or IDE
CompileCode becomes bytecodeRemix, Hardhat or Foundry
TestUnit tests and testnet trialsLocal network, Sepolia
DeployBytecode published in a transactionEthereum mainnet
VerifySource code published on explorerEtherscan

Most teams deploy to a testnet first, then to mainnet with real funds. The steps are the same in both cases; only the network and the value at risk change. If you are deciding whether to build in-house or with a partner, smart contract development covers what a production build involves.

What do you need before you deploy?

Before you deploy, you need a wallet funded with ETH, a development environment, a testnet to practise on, and a clear idea of what the contract should and should not do. Rushing any of these is how contracts get deployed with bugs that cannot be fixed.

The wallet holds the ETH that pays for deployment and the private key that signs the transaction. Use a dedicated deployer wallet, not your main wallet, and keep its key offline when it is not in use. The deployer address becomes the contract's owner in many designs, so whoever controls it controls the contract's admin functions.

The development environment is where you write, compile and test. The common choices are Remix, a browser IDE that needs no setup, Hardhat, a JavaScript-based framework, and Foundry, a faster toolchain written in Rust. Remix suits a first contract and a quick test; Hardhat and Foundry suit a real project with tests, scripts and a team.

You also need a testnet. Sepolia is the current Ethereum testnet, and its ETH has no value, so you can deploy and break things for free. Get test ETH from a faucet, deploy the same contract you plan to put on mainnet, and run the same transactions a user would run. If the contract behaves differently from what you expected, you want to find out on Sepolia, not on mainnet.

Finally, write down the contract's rules before you write the code: who can call each function, what happens when an input is wrong, and how the contract can be paused or upgraded if it has to be. A contract with no admin functions cannot be fixed; a contract with too many admin functions is a trust problem. Decide that balance before deployment, not after.

How do you write and compile a contract?

You write a smart contract in Solidity, the most common language for Ethereum, and compile it into bytecode that the Ethereum Virtual Machine can run. The code defines the contract's storage, its functions, and the rules that guard them.

A simple contract has a few parts: state variables that hold data on-chain, a constructor that runs once at deployment, functions that read or change the data, and events that log what happened. The compiler checks the syntax and produces two things: the bytecode that gets deployed, and the ABI, a description of the contract's functions that wallets and apps use to call it.

ToolWhat it isBest for
RemixBrowser IDE, no installFirst contracts, quick tests
HardhatJavaScript frameworkTeam projects, plugins
FoundryFast Rust toolchainHeavy testing, gas checks
TruffleOlder frameworkExisting Truffle projects

Compilation also runs the optimiser, which rewrites the bytecode to use less gas. Turning it on usually saves money on deployment and on every later call, but it can make debugging harder, so keep it on for production builds and off while you are still writing tests.

Keep the contract small. Every line of code is a line that can hold a bug and a line that costs gas to deploy. Split a large system into several small contracts that call each other, and use audited libraries for standard parts such as tokens and access control instead of writing them from scratch. The OpenZeppelin library is the usual choice for those building blocks.

How do you test a contract before mainnet?

You test a contract before mainnet by writing unit tests, running them on a local network, and then deploying to the Sepolia testnet and using the contract the way a real user would. Each stage catches a different kind of mistake.

Unit tests check each function in isolation. A test deploys the contract to a local network, calls a function with a known input, and checks the result and the state change.

Good tests cover the normal path and the failures: what happens when someone sends too little, calls a function they should not call, or passes an edge-case value. Aim to cover the functions that move money or change permissions first, because those are the ones that hurt when they break.

A local network runs on your own machine and gives you instant, free transactions. Hardhat and Foundry both include one. It is the place to run the full test suite quickly and to check gas usage, because every transaction reports how much gas it used. If a function costs far more than you expected, find out why before it costs real ETH.

Sepolia is the next stage. It is a public testnet that behaves like mainnet, with real block times and real network conditions, but its ETH is free from a faucet. Deploy the contract there, run the same steps a user would run, and check the result on the Sepolia explorer. This is also where you test the front end, the wallet connection and any off-chain services that talk to the contract.

For anything that will hold real value, add an audit before mainnet. An audit is a review by security specialists who read the code and try to break it. It does not guarantee safety, but it catches the classes of bug that tests miss, such as reentrancy and access control mistakes. See smart contract audit versus penetration testing for how the two reviews differ.

How do you deploy it, step by step?

You deploy a smart contract by compiling it, connecting a funded wallet, sending the deployment transaction, and waiting for it to be confirmed. The steps below use the standard flow, which is the same in Remix, Hardhat and Foundry, with different buttons.

  1. Compile the contract. Run the compiler and check there are no errors or serious warnings. Save the bytecode and the ABI that the compiler produces.
  2. Connect a funded wallet. Connect the deployer wallet to the tool you are using. Check the network is Ethereum mainnet and the wallet holds enough ETH for the deployment and a margin for price movement.
  3. Set the constructor arguments. If the contract's constructor takes arguments, such as a token name or an owner address, enter them now. A wrong constructor argument means deploying again.
  4. Send the deployment transaction. The tool shows the estimated gas cost. Confirm the transaction in the wallet and note the transaction hash.
  5. Wait for confirmation. The transaction is mined into a block, and the receipt contains the new contract address. Wait for a few confirmations before treating the deployment as final.
  6. Verify the source code. Publish the source on Etherscan so anyone can read the code behind the address. Verification matches the deployed bytecode against the source you provide.
  7. Test the live contract with a small call. Call a read-only function first, then a small state-changing call if one is safe. Check the result on the explorer before announcing the address.

Write the contract address down in the project's records, along with the transaction hash, the deployer address and the exact source code that was deployed. If the team later needs to prove what was deployed, those four items are the evidence. Keep the deployer key safe, because it may be the only key that can call the contract's admin functions.

Example (hypothetical): deploying a simple token

Example (hypothetical): a team deploys a simple ERC-20 token on Ethereum. The contract is small, and the deployment uses 1,200,000 units of gas. Assume the gas price is 20 gwei, where 1 gwei is 0.000000001 ETH.

The fee is 1,200,000 times 20 gwei, which is 24,000,000 gwei, or 0.024 ETH. Assume ETH is worth $2,000, so the deployment costs about $48. That is the one-off cost of publishing the contract; each later transaction, such as a transfer or a mint, costs its own gas on top.

If the gas price doubles to 40 gwei, the same deployment costs 0.048 ETH, or about $96 at the same ETH price. If the contract were twice as large, it would use roughly twice the gas. That is why teams deploy when the network is quiet and keep contracts small: both choices cut the bill directly.

The numbers are assumptions, not prices. Gas prices move with network demand, and the ETH price moves on its own, so a deployment that costs $48 today can cost far more or far less tomorrow. Check the current gas price before sending the transaction, and set a limit you are willing to pay. For the token itself, the steps for the standard itself are covered in how to create an ERC-20 token.

What are the common mistakes?

The most common mistakes are deploying untested code, getting the constructor arguments wrong, and forgetting that a deployed contract cannot be edited.

  • Deploying without tests. A contract that was never tested on a local network or a testnet is a guess, not a product. Run the tests, then deploy to Sepolia, then deploy to mainnet.
  • Wrong constructor arguments. A token with the wrong name, the wrong supply or the wrong owner address has to be deployed again. Double-check the arguments before sending the transaction.
  • No verification on the explorer. An unverified contract hides its code from users, which looks suspicious and makes debugging harder. Verify the source on Etherscan right after deployment.
  • Using the wrong network. Sending a mainnet deployment transaction while the wallet is on a testnet, or the reverse, wastes time and can confuse the team. Check the network name before confirming.
  • Leaving admin keys in one place. If a single key controls the contract and it is lost or stolen, the contract is stuck or compromised. Use a multisig or a hardware wallet for admin keys.
  • Skipping the audit for contracts that hold value. Tests catch what you thought to check. An audit catches what you did not think to check. For anything holding real funds, that review is worth the cost.

Key takeaways

  • Deploying a smart contract publishes its bytecode to Ethereum and gives it a permanent address
  • Write in Solidity, compile to bytecode, and keep contracts small and simple
  • Test on a local network and on Sepolia before touching mainnet
  • Deployment costs gas in ETH, and the cost rises with contract size and gas price
  • Verify the source on Etherscan so users can read the code behind the address
  • A deployed contract cannot be edited, so test and audit before you deploy

Frequently asked questions

How much does it cost to deploy a smart contract on Ethereum?

It depends on the size of the contract and the gas price at the time. A small contract might use around a million units of gas, which at 20 gwei is 0.02 ETH. Gas prices and the ETH price both move, so check the current gas price before sending the transaction rather than relying on a figure from a guide.

What language are smart contracts written in?

Most Ethereum smart contracts are written in Solidity, which is the language the Ethereum ecosystem standardised on. Vyper is a smaller alternative with a simpler design. Both compile to bytecode that the Ethereum Virtual Machine runs.

Do I need ETH to deploy a smart contract?

Yes. Deployment is a transaction, and transactions on Ethereum cost gas paid in ETH. The deployer wallet must hold enough ETH to cover the deployment fee, plus a margin in case the gas price rises while the transaction is waiting.

What is the difference between deploying on a testnet and mainnet?

The steps are the same, but the value at risk is different. A testnet such as Sepolia uses free test ETH and is for practice and testing, while mainnet uses real ETH and the deployed contract handles real value. Always deploy to a testnet first.

Can I change a smart contract after deploying it?

Not by editing it. A deployed contract's code is fixed. To change behaviour you deploy a new contract and move users to it, or you use an upgradeable proxy pattern, where a proxy contract points at an implementation that can be replaced. Upgradeability has its own risks and should be a deliberate design choice.

What does verifying a contract on Etherscan do?

Verification publishes the contract's source code on the explorer and checks it matches the deployed bytecode. Anyone can then read the code, which builds trust, and the explorer can show function names instead of raw data. It is a standard step after every deployment.

Found this useful? Share it.
Hertiv engineering team

Written from projects we build for clients: blockchain systems in production. Every post is reviewed by a senior engineer before publishing and updated when practice changes.

About HertivHow we work

Planning a smart contract or a dApp? Talk to Hertiv.

A senior engineer replies within one business day. Or see our Smart Contract Development service.

Book a free call

Keep reading

All posts

Tell us what you want to build

A senior engineer reads every request and replies within one business day with questions, a rough range, or a call link.

  • NDA on request before any details
  • You own all code, models and IP
  • US, UK and EU time-zone overlap

Your email app should open with your message ready to send. If it does not, write to [email protected].

Prefer email? Write to [email protected]
Estimate costBook a call