Building a simple escrow smart contract in Solidity
In this article, I walk through a simple escrow smart contract written in Solidity. The goal of this project is to demonstrate core smart contract concepts such as ETH handling, access control, and safe fund transfers.
What Is an Escrow Contract?
An escrow contract is a neutral agreement where funds are locked until certain conditions are met.,
In this example:
A payer deploys the contract and sends ETH
A payee is the recipient of the funds
An arbiter decides when the funds should be released
This pattern is commonly used in freelancing, marketplaces, and trust-minimized payments.
Contract Overview
The contract stores:
payer: the address that deploys and funds the contractpayee: the address that will receive the fundsarbiter: the address authorized to release the fundsamount: the ETH locked in escrowreleased: a flag to prevent double spending
The Solidity Code
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.19;
contract Escrow {
address public payer;
address public payee;
address public arbiter;
uint256 public amount;
bool public released;
constructor(address _payee, address _arbiter) payable {
payer = msg.sender;
payee = _payee;
arbiter = _arbiter;
amount = msg.value;
}
function releaseFunds() external {
require(msg.sender == arbiter, "Only arbiter can release");
require(!released, "Already released");
released = true;
(bool success, ) = payable(payee).call{value: amount}("");
require(success, "Transfer failed");
}
}
How the Contract Works
The payer deploys the contract and sends ETH during deployment
The ETH is stored in the contract
Only the arbiter can call
releaseFundsOnce released, the ETH is sent to the payee
The
releasedflag prevents the funds from being sent twice
Why call Is Used Instead of transfer
Older Solidity contracts often used transfer(), but it is now discouraged due to gas limitations. This contract uses:
call{value: amount}("")
This is the recommended approach for sending ETH safely.
What This Project Demonstrate
Basic smart contract structure
ETH transfers
Access control using
requireState management
Writing safe, modern solidity
CONCLUSION
This project is intentionally simple but practical. It serves as a foundation for more advanced escrow systems, dispute resolution mechanisms, and DeFi-style contracts.
The full source code is available on GitHub; Simple escrow.sol