πThis smart contract in Solidity is an escrow contract that facilitates a transaction between a π€ buyer, a π€ seller and a βοΈ referee. The contract passes through three states: π awaiting payment, π awaiting delivery and β complete. The buyer sends a payment π° to the contract, then once delivery has been confirmed by the buyer or referee, the seller receives payment. The contract allows you to check the current state of the transaction with the "getState()" function.
// SPDX-License-Identifier: MITpragmasolidity ^0.8.18;contract Escrow {addresspayablepublic buyer;addresspayablepublic seller;addresspayablepublic arbiter;enumState { await_payment, await_delivery, complete } State public state;eventConfirmPayement(uint balance,uint timestamp,State state);eventConfirmDelivery(uint balance,uint timestamp,State state);modifierinState(State_state) {require(state==_state,"Invalid contract state"); _; }constructor(address payable _buyer,address payable _seller) { arbiter =payable(msg.sender);require(_buyer!=_seller && _buyer!=arbiter && _seller!=arbiter); buyer = _buyer; seller = _seller; state = State.await_payment; }functionconfirmPayement() externalpayableinState(State.await_payment) {require(msg.value!=0);require(msg.sender == buyer,"Only buyer can send payments"); state = State.await_delivery;emitConfirmPayement(msg.value,block.timestamp, state); }functionconfirmDelivery() externalinState(State.await_delivery) {require(msg.sender==arbiter || msg.sender==buyer,"Only buyer or arbiter can call this function");uint balance =address(this).balance; seller.transfer(balance); state = State.complete;emitConfirmDelivery(balance,block.timestamp,state); }functiongetState() externalviewreturns(State){return state; }}