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.
Solidity
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{ 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); } } |
Recommended Posts:
- Steps to Execute Solidity Smart Contract using Remix IDE
- Creating a Smart Contract that Returns Address and Balance of Owner using Solidity
- What is Smart Contract in Solidity?
- What is Wallet Smart Contract?
- Smart Contract to Store Employee Details
- How to use MetaMask to Deploy a Smart contract in Solidity (Blockchain)?
- How to use GANACHE Truffle Suite to Deploy a Smart Contract in Solidity (Blockchain)?
- Interacting With Ethereum Smart Contract Using Web3js
- Deploying Smart Contract on Test/Main Network Using Truffle
- Solidity - Abstract Contract
- Blockchain | Smart Contracts
- How to use GANACHE Truffle Suite to Deploy a Smart Contract in Solidity (Blockchain)?
- Interacting With Ethereum Smart Contract Using Web3js
- Deploying Smart Contract on Test/Main Network Using Truffle
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.

