Skip to content
Related Articles

Related Articles

What is Escrow Smart Contract?

Improve Article
Save Article
  • Difficulty Level : Easy
  • Last Updated : 11 May, 2022
Improve Article
Save Article

Escrow is the third party which holds the asset(asset can be money, bond, stocks) on the presence of two parties. Escrow will release the fund when certain conditions are met.
For Example, “A” is a seller and wants to sell his car, “B” is a buyer who wants to buy “A”‘s car so they will contact Escrow “C”(an arbiter) which hold the asset until “B” receives the car. When this condition will be met, Escrow will release the fund to “A”. This solves the issue of trust and prevents any discrepancy.
Lets the write a smart contract for the Escrow using solidity language. 
Here Smart contract will hold the asset, which will be released on when conditions are fulfilled.


pragma solidity 0.6.0;     
// Defining a Contract
contract escrow{
    // Declaring the state variables
    address payable public buyer;
    address payable public seller;
    address payable public arbiter;
    mapping(address => uint) TotalAmount;
    // Defining a enumerator 'State'
    enum State{
        // Following are the data members
        awate_payment, awate_delivery, complete 
    // Declaring the object of the enumerator
    State public state;
    // Defining function modifier 'instate'
    modifier instate(State expected_state){
        require(state == expected_state);
   // Defining function modifier 'onlyBuyer'
    modifier onlyBuyer(){
        require(msg.sender == buyer || 
                msg.sender == arbiter);
    // Defining function modifier 'onlySeller'
    modifier onlySeller(){
        require(msg.sender == seller);
    // Defining a constructor
    constructor(address payable _buyer, 
                address payable _sender) public{
        // Assigning the values of the 
        // state variables
        arbiter = msg.sender;
        buyer = _buyer;
        seller = _sender;
        state = State.awate_payment;
    // Defining function to confirm payment
    function confirm_payment() onlyBuyer instate(
      State.awate_payment) public payable{
        state = State.awate_delivery;
    // Defining function to confirm delivery
    function confirm_Delivery() onlyBuyer instate(
      State.awate_delivery) public{
        state = State.complete;
    // Defining function to return payment
    function ReturnPayment() onlySeller instate(

My Personal Notes arrow_drop_up
Related Articles

Start Your Coding Journey Now!