Skip to main content

Command Palette

Search for a command to run...

Building a simple escrow smart contract in Solidity

Updated
2 min read

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 contract

  • payee: the address that will receive the funds

  • arbiter: the address authorized to release the funds

  • amount: the ETH locked in escrow

  • released: 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

  1. The payer deploys the contract and sends ETH during deployment

  2. The ETH is stored in the contract

  3. Only the arbiter can call releaseFunds

  4. Once released, the ETH is sent to the payee

  5. The released flag 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 require

  • State 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