Skip to content

Instantly share code, notes, and snippets.

@nathan-websculpt
Created September 24, 2021 19:42
Show Gist options
  • Save nathan-websculpt/b1ae472676b23e05f3d7a5804a256d02 to your computer and use it in GitHub Desktop.
Save nathan-websculpt/b1ae472676b23e05f3d7a5804a256d02 to your computer and use it in GitHub Desktop.
Example usage of Escrow -- not production-ready -- for learning purposes only
// SPDX-License-Identifier: GPL-3.0
pragma solidity >=0.7.0 <0.9.0;
import "https://github.com/OpenZeppelin/openzeppelin-contracts/blob/release-v4.3/contracts/security/ReentrancyGuard.sol";
import "https://github.com/OpenZeppelin/openzeppelin-contracts/blob/release-v4.3/contracts/utils/escrow/Escrow.sol";
contract EscrowExample is ReentrancyGuard {
Escrow private immutable _escrow;
constructor() {
_escrow = new Escrow();
}
function deposit() public payable {
_escrow.deposit{ value: msg.value }(msg.sender);
}
function withdraw(address payable payee) public nonReentrant {
require(payee == msg.sender, "sender address did not match address in arguments");
_escrow.withdraw(payee);
}
function query() external view returns (uint256) {
return _escrow.depositsOf(msg.sender);
}
}
@nathan-websculpt
Copy link
Author

Used as an example in this blog

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment