The Wayback Machine - https://web.archive.org/web/20240901013345/https://www.geeksforgeeks.org/what-is-escrow-smart-contract/
Open In App

What is Escrow Smart Contract?

Last Updated : 20 Feb, 2023
Comments
Improve
Suggest changes
Like Article
Like
Save
Share
Report
News Follow

Escrow is the third party that holds the asset(asset can be money, bond, or stocks) in 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, and “B” is a buyer who wants to buy “A”‘s car so they will contact Escrow “C”(an arbiter) which holds 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.

Let us write a smart contract for the Escrow using solidity language. 
 

Example: In the below example the third party will hold the asset, which will be released on when conditions are fulfilled.

Solidity




// SPDX-License-Identifier: GPL-3.0
pragma solidity >=0.4.22 <0.9.0; 
/// @title A contract for demonstrate Escrow Smart Contract
/// @author Jitendra Kumar
/// @notice For now, this contract just show how to third party manages the assets of buyer and seller
contract escrow{
 
    // Declaring the state variables
    address payable public buyer;
    address payable public seller;
    address payable public arbiter;
     
    // 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){
         
        // Assigning the values of the
        // state variables
        arbiter = payable(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{
        seller.transfer(address(this).balance);
        state = State.complete;
    }
 
    // Defining function to return payment
    function ReturnPayment() onlySeller instate(
        State.awate_delivery)public{
        buyer.transfer(address(this).balance);
    }
}


Output :  

Remix Output



Similar Reads

How to use GANACHE Truffle Suite to Deploy a Smart Contract in Solidity (Blockchain)?
There are various processes involved in deploying a smart contract using Ganache and Truffle Suite: 1. Install Ganache first. Ganache is a personal blockchain for Ethereum development. You must first download and install it. It is available for download from https://www.trufflesuite.com/ganache, the official website. 2. Install Truffle Suite: The n
4 min read
Steps to Execute Solidity Smart Contract using Remix IDE
Remix IDE is generally used to compile and run Solidity smart contracts. Below are the steps for the compilation, execution, and debugging of the smart contract. Step 1: Open Remix IDE on any of your browsers, select on New File and click on Solidity to choose the environment. Step 2: Write the Smart contract in the code section, and click the Comp
1 min read
Creating a Smart Contract that Returns Address and Balance of Owner using Solidity
Problem: Create a smart contract named MyContract having a state variable as owner. Create a constructor to fetch the address of the owner from msg and hold it into the state variable owner. Also, create a function getBalance() to show the current balance of the owner. Solution: Every smart contract is owned by an address called as owner. A smart c
2 min read
What is Smart Contract in Solidity?
Solidity's code is encapsulated in contracts which means a contract in Solidity is a collection of code (its functions) and data (its state) that resides at a specific address on the Ethereum blockchain. A contract is a fundamental block of building an application on Ethereum. Now let's look at the code example for making smart contract : Example #
4 min read
What is Wallet Smart Contract?
Wallets are just like your bank account, through which we can receive money, send money, and can check the balance. Important terms:uint- unsigned integer.address- It is a unique set of the string provided for the transaction.msg.sender- Address of the current user.msg.value- Cost put by the current user.public- Visibility of the function.view- Thi
4 min read
Smart Contract to Store Employee Details
Solidity is a high-level language. The structure of smart contracts in solidity is very similar to the structure of classes in object-oriented languages. The solidity file has an extension .sol. What are Smart Contracts? Solidity’s code is encapsulated in contracts which means a contract in Solidity is a collection of code (its functions) and data
3 min read
How to use MetaMask to Deploy a Smart contract in Solidity (Blockchain)?
Smart contracts are self-executing contracts. They were first proposed by Nick Szabo in the 90s. They are set of rules and protocols which two parties agree upon and have to follow. One of the main features is that they are immutable once deployed on the blockchain. It is widely used in the Ethereum blockchain. The main language used for writing sm
3 min read
Deploying Smart Contract on Test/Main Network Using Truffle
A Smart Contract is a computer program that directly and automatically controls the transfer of digital assets between the parties under certain conditions. A smart contract works in the same way as a traditional contract while also automatically enforcing the contract. Smart contracts are programs that execute exactly as they are set up(coded, pro
5 min read
Interacting With Ethereum Smart Contract Using Web3js
Ethereum is a cryptocurrency platform in the market just like Bitcoin. It is an open-source &amp; decentralized blockchain featuring working on smart contracts. It has its own cryptocurrency known as ether. The smart contracts in Ethereum are written in solidity. TestRPC The Ethereum TestRPC is like a manual emulator for blockchain. It provides blo
4 min read
Life Cycle of Smart Contract
The life cycle of Smart Contracts in the Blockchain Ecosystem involves four Stages. Unlike a blockchain's lifecycle that begins with defining the issue, you want to solve with your blockchain product and ends with a blockchain that resolves the issue, a smart contract on the blockchain undergoes different phases. These four phases are the formation
4 min read
Solidity - Deploy a Smart Contract for Marks Management System
Solidity is a high-level language. The structure of smart contracts in solidity is very similar to the structure of classes in object-oriented languages. The solidity file has an extension .sol. What are Smart Contracts?Solidity’s code is encapsulated in contracts which means a contract in Solidity is a collection of code (its functions) and data (
3 min read
How to Simply Deploy a Smart Contract on Ethereum?
Smart contracts are blocks of code that reside on the blockchain. It is like an Ethereum account but there is a critical difference between an external account and a smart contract. Unlike a smart contract, an external account can connect to multiple Ethereum networks (Goerli testnet, mainnet, etc.) whereas a smart contract is only specific to one
7 min read
Setting Up Smart Contract Development Environment
A development environment is an environment in which all the resources and tools are available which are used to develop a program or software product. Here, an attempt to create a development environment that is a collection of the processes and tools that are used to develop smart contracts. There are mainly two choices available to set up the en
5 min read
Deploy a Smart Contract on Ethereum with Python, Truffle and web3py
This article discusses deploying a Smart Contract on Ethereum with Python, Truffle, and web3py. Prerequisite: In order to write a simple smart contract, deploy it to a personal Ethereum blockchain, and call the contract using Python3, install the below software on a PC: 1. Python3 v3.5.3 or later versions: Install python following the instructions
6 min read
Decentralized Bank Smart Contract in Solidity
Solidity is an Object-oriented Programming Language for implementing Smart Contracts. It's a High-Level Statically Typed Language like C. The solidity file has an extension .sol. The article focuses on discussing the decentralized bank smart contract in Solidity. In the below example, the aim is to deploy a Smart Contract for Decentralized Bank Sys
3 min read
Make HTTP Request Using Your Solidity Smart Contract
Smart contracts are self-executing digital programs that are designed to automate the enforcement of the terms of a contract. Solidity is a programming language used to write these smart contracts on the Ethereum blockchain. One of the challenges with smart contracts is their inability to interact with the outside world, including making HTTP reque
10 min read
How to Test a Smart Contract for Ethereum?
Public Blockchains like Ethereum are immutable, it is difficult to update the code of a smart contract once it has been deployed. To guarantee security, smart contracts must be tested before they are deployed to Mainnet. There are several strategies for testing contracts, but a test suite comprised of various tools and approaches is suitable for de
15+ min read
How to Test a Smart Contract with Remix?
The Remix IDE is an open-source development environment for building, testing, and deploying smart contracts on the Ethereum blockchain. One of the most notable features of Remix IDE is its integration with the Solidity programming language. Solidity is a contract-oriented language that is specifically designed for building smart contracts on Ether
7 min read
How to Calling Smart Contract Functions with Web3.js?
Have you wondered how smart contracts interact with the front end? So, the answer is the web3.js library. First, briefly discuss some terms related to web3.js and learn about them. Web3.js: Web3. js is a collection of libraries that allow users to interact between smart contracts and the front end. It is used to develop websites that can interact w
4 min read
Unlock the Power of Solidity: Exploring the Essential Keywords for Smart Contract Development
Solidity is a smart contract programming language built solely to develop smart contracts that can be deployed on blockchains. C++ and JavaScript inspired it, an Object Oriented and High-Level language (HLL), that helps developers define the behaviour and rules for a Decentralized Application (Dapp). Smart contract facilitates autonomous, secure, a
13 min read
Steps to Create, Test and Deploy Ethereum Smart Contract
Smart contracts are self-execution programs stored on a blockchain that are automatically executed when predefined conditions are met. They allow the participants on the blockchain to transact with each other without a trusted central authority. After creating a smart contract, the next step is to deploy the smart contract onto a blockchain for exe
7 min read
Integrating your Smart Contract with Frontend
In this article, we are going to learn how to connect a smart contract to the front end. To keep the process less complex and focus on the integration process, the smart contract in itself is kept simple. You can easily introduce multiple complex functions once you understand the basics. For this tutorial, we are simply putting a campaign on the lo
14 min read
What is a NFT Smart Contract?
NFT Smart contracts play an important role in the blockchain space across many use cases. In particular, NFT smart contracts are becoming increasingly important as the metaverse and Web3 attract more interest. NFT smart contracts are specialized blockchain contracts that facilitate the creation, ownership, transfer, and management of NFTs. This art
8 min read
Solidity - Abstract Contract
Abstract contracts are contracts that have at least one function without its implementation or in the case when you don't provide arguments for all of the base contract constructors. Also in the case when we don't intend to create a contract directly we can consider the contract to be abstract. An instance of an abstract cannot be created. Abstract
3 min read
How to Deploy Contract From NodeJS using Web3?
This article focuses on discussing deploying a contract from NodeJS using web3. The following topics will be covered in this article: Introduction to web3js modules.How to generate ABI and bytecode using web3js.Compilation and deployment of smart contracts using web3js.Software requirements: Nodejs.Ganache.Text editor - VS Code1. Introduction to we
6 min read
How to Get the Deployed Contract Address in Truffle?
To get the deployed smart contract address in the truffle follow the below steps: Initialize the truffle project in Vs-code.Deploy the smart contract. If the smart contract is successfully compiled and deployed, one can find the deployed smart contract address in the build .json files. The deployed smart contract address can also be located in the
3 min read
Difference Between Dapps, Crypto Wallets and Smart Contracts
This article focuses on discussing the differences between dApps, digital wallets, and smart contracts. The following topics will be discussed here: What are dApps?What Are Crypto Wallets?What Are Smart Contracts?dApps vs Digital Wallets vs Smart Contracts.Let's start discussing each of these topics in detail: What are dApps?A decentralized applica
6 min read
Smart Contracts and IoT
Smart contracts are a type of computer protocol that facilitates, verifies, or enforces the negotiation or performance of a contract. Nick Szabo first presented the idea of smart contracts in 1996. The code and the agreements contained therein exist across a decentralized, peer-to-peer network and are enforced by the network of computers that run t
8 min read
How to deploy Smart Contracts using Ethers.js and Node.js on Goerli Testnet Blockchain from Back-end ?
In this article, we will be deploying smart contracts on blockchain from back-end, so that we do not have to require hardhat or truffle frameworks and their commands to deploy a smart contract or if somebody doesn't want to use these frameworks. Since we have to run manual commands of these frameworks in the terminal to deploy Smart Contracts. We c
9 min read
Timestamp Dependency in Smart Contracts
During the development of the smart contract, the programmers need to know the exact time to be able to execute some actions in the smart contract. Therefore., they use a timestamp generated by the node executing the smart contract. This article focuses on discussing the timestamp dependence vulnerability. The following topics of timestamp dependen
6 min read