0

I created an escrow contract, which typically has 3 major external functions; 'fund', 'refundBuyer' and 'release'.

Only the buyer, can call these functions, he funds the contract with 'fund', if he receives his goods from the seller, he calls the 'release' and the contracts sends the money to the seller.

In case where there's a dispute, the buyer can initiate the 'refundBuyer' call and the contract refunds their money

this is the code below

pragma solidity >=0.7.0 <0.9.0; import "@openzeppelin/contracts/security/ReentrancyGuard.sol"; /** * @title EscrowSol * @dev Manages fund transfers between two parties */ //creating our contract and inheriting the oppenzelin reentrancy contract EscrowSol is ReentrancyGuard { enum State {AWAITING_PAYMENT, AWAITING_DELIVERY, COMPLETE, REFUND} State public currState; // Wallet address of the payer address public funder; // Wallet address of the intended beneficiary address public beneficiary; //creating a modifier to ensure that only buyer can call a particular method modifier onlyBuyer() { require(msg.sender == funder, "Only buyer can call this method"); _; } //initial the buyer and seller addresses in the constructor function constructor (address payable _buyer, address payable _seller) { funder = _buyer; beneficiary = _seller; } /// Lockup a certain crypto value. /// @param counterpart the address of the intended beneficiary /// @dev lockup crypto for the counterpart function fund(address counterpart) onlyBuyer payable external{ require(currState == State.AWAITING_PAYMENT, "Already Paid"); currState = State.AWAITING_DELIVERY;//After sending the funds into the smart contract, the state should change to AWAITING DELIVERY beneficiary = counterpart; funder = msg.sender; } /// Release all locked funds. /// @dev The deal is done, let only the payer release fund. function release() onlyBuyer payable external{ require(currState == State.AWAITING_DELIVERY, "cannot confirm delivery");//while calling this method, the state must be in awaiting delivery, which means the funds are already paid by the buyer and is in the contract if (msg.sender==funder){ // Transfer all the funds to the beneficiary payable(beneficiary).transfer(address(this).balance); } currState = State.COMPLETE;//After successfully settling both parties, the currentState changes to complete } function refundBuyer() onlyBuyer external { require(currState == State.AWAITING_DELIVERY, "REFUND BUYER");//while calling this method, the state must be in awaiting delivery, which means the funds are already paid by the buyer and is in the contract payable(funder).transfer(address(this).balance);//transfer the funds in the contract to the sellers currState = State.REFUND;//After successfully settling both parties, the currentState changes to complete } /// Return the locked value. /// @dev anyone should be able to see the actually locked crpto value . /// @return the crypto value function getBalance() external view returns (uint) { return address(this).balance; } } ``` Now, i have deployed the contract and tested the fund and release feature, but if i try to fund again, so i can test out the 'refundBuyer', It throws an error on remix. Same thing happens if i did the fund and refund call first, it will go through. But when i try to fund again, it throws the same error below [![enter image description here][1]][1] [1]: https://i.sstatic.net/yB9hM.png Does it mean that buyer can only interact with the contract once ? or there's something i'm missing 
1
  • Please clarify your specific problem or provide additional details to highlight exactly what you need. As it's currently written, it's hard to tell exactly what you're asking. Commented Dec 3, 2022 at 15:59

1 Answer 1

0

What ‘transaction tests’ are failing, and what errors are you getting?

Obviously, you wouldn’t be able to fund the contract under the owner’s address and use that same address to release the funds, because of your modifiers.

Some questions: what client are you using? Are you switching accounts when you try to use different functions?

1
  • solved the issue, i only needed to return the state to 0. Thanks Commented Dec 4, 2022 at 19:47

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.