Skip to content

Commit

Permalink
Merge pull request #3 from swellander/fix/deploy-script
Browse files Browse the repository at this point in the history
Merged "Fix/deploy script" and waiting for small renaming fix to Easy2Pay for consistency with build's new name
  • Loading branch information
luloxi committed Dec 30, 2023
2 parents 4a9a3c6 + 7b93852 commit d522c93
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 31 deletions.
40 changes: 26 additions & 14 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,31 +11,33 @@

To get started with EasyPay, follow the steps below:

1. Clone this repo & install dependencies
1. Make sure you have the [foundry toolkit installed](https://book.getfoundry.sh/getting-started/installation).

2. Clone this repo & install dependencies

```
git clone https://github.com/luloxi/EasyPay.git
cd EasyPay
yarn install
```

2. Run a local network in the first terminal:
3. Run a local network in the first terminal:

```
yarn chain
```

This command starts a local Ethereum network using Hardhat. The network runs on your local machine and can be used for testing and development. You can customize the network configuration in `hardhat.config.ts`.

3. On a second terminal, deploy the test contract:
4. On a second terminal, deploy the test contract:

```
yarn deploy
```

This command deploys a test smart contract to the local network. The contract is located in `packages/hardhat/contracts` and can be modified to suit your needs. The `yarn deploy` command uses the deploy script located in `packages/hardhat/deploy` to deploy the contract to the network. You can also customize the deploy script.

4. On a third terminal, start your NextJS app:
5. On a third terminal, start your NextJS app:

```
yarn start
Expand Down Expand Up @@ -63,16 +65,26 @@ Run smart contract test with `yarn hardhat:test`

## Contents

- [Requirements](#requirements)
- [Quickstart](#quickstart)
- [Deploying your Smart Contracts to a Live Network](#deploying-your-smart-contracts-to-a-live-network)
- [Deploying your NextJS App](#deploying-your-nextjs-app)
- [Interacting with your Smart Contracts: SE-2 Custom Hooks](#interacting-with-your-smart-contracts-se-2-custom-hooks)
- [Disabling Type & Linting Error Checks](#disabling-type-and-linting-error-checks)
- [Disabling commit checks](#disabling-commit-checks)
- [Deploying to Vercel without any checks](#deploying-to-vercel-without-any-checks)
- [Disabling Github Workflow](#disabling-github-workflow)
- [Contributing to Scaffold-ETH 2](#contributing-to-scaffold-eth-2)
- [💸 EasyPay 💸](#-easypay-)
- [Quickstart](#quickstart)
- [🏗 About Scaffold-ETH 2](#-about-scaffold-eth-2)
- [Contents](#contents)
- [Requirements](#requirements)
- [Quickstart](#quickstart-1)
- [Deploying your Smart Contracts to a Live Network](#deploying-your-smart-contracts-to-a-live-network)
- [Deploying your NextJS App](#deploying-your-nextjs-app)
- [Interacting with your Smart Contracts: SE-2 Custom Hooks](#interacting-with-your-smart-contracts-se-2-custom-hooks)
- [useScaffoldContractRead:](#usescaffoldcontractread)
- [useScaffoldContractWrite:](#usescaffoldcontractwrite)
- [useScaffoldEventSubscriber:](#usescaffoldeventsubscriber)
- [useScaffoldEventHistory:](#usescaffoldeventhistory)
- [useDeployedContractInfo:](#usedeployedcontractinfo)
- [useScaffoldContract:](#usescaffoldcontract)
- [Disabling type and linting error checks](#disabling-type-and-linting-error-checks)
- [Disabling commit checks](#disabling-commit-checks)
- [Deploying to Vercel without any checks](#deploying-to-vercel-without-any-checks)
- [Disabling Github Workflow](#disabling-github-workflow)
- [Contributing to Scaffold-ETH 2](#contributing-to-scaffold-eth-2)

## Requirements

Expand Down
26 changes: 13 additions & 13 deletions packages/foundry/contracts/EasyPay.sol
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ struct PayRequest {
bool completed;
}

contract Easy2Pay {
contract EasyPay {
address public owner;

uint256 requests;
Expand All @@ -23,17 +23,17 @@ contract Easy2Pay {
mapping(uint256 requestId => PayRequest) public payRequests;

// Custom errors
error Easy2Pay__RequestDoesNotExist();
error Easy2Pay__InsufficientEther(
error EasyPay__RequestDoesNotExist();
error EasyPay__InsufficientEther(
uint256 requestedAmount,
uint256 actualAmount
);
error Easy2Pay__PaymentAlreadyCompleted();
error Easy2Pay__FailedToSendEther();
error Easy2Pay__UnauthorizedAccess();
error EasyPay__PaymentAlreadyCompleted();
error EasyPay__FailedToSendEther();
error EasyPay__UnauthorizedAccess();

modifier onlyOwner() {
if (msg.sender != owner) revert Easy2Pay__UnauthorizedAccess();
if (msg.sender != owner) revert EasyPay__UnauthorizedAccess();
_;
}

Expand All @@ -50,30 +50,30 @@ contract Easy2Pay {
PayRequest storage request = payRequests[_requestId];

if (request.receiver == address(0))
revert Easy2Pay__RequestDoesNotExist();
revert EasyPay__RequestDoesNotExist();

if (request.amount > msg.value)
revert Easy2Pay__InsufficientEther(request.amount, msg.value);
revert EasyPay__InsufficientEther(request.amount, msg.value);

if (request.completed) revert Easy2Pay__PaymentAlreadyCompleted();
if (request.completed) revert EasyPay__PaymentAlreadyCompleted();

request.completed = true;

// Call returns a boolean value indicating success or failure.
// This is the current recommended method to use to transfer ETH.
(bool sent, ) = request.receiver.call{value: msg.value}("");

if (!sent) revert Easy2Pay__FailedToSendEther();
if (!sent) revert EasyPay__FailedToSendEther();
}

// Function in case a payment is received where msg.data must be empty
receive() external payable {
if (msg.sender != address(0)) revert Easy2Pay__FailedToSendEther();
if (msg.sender != address(0)) revert EasyPay__FailedToSendEther();
}

// Fallback function is called when msg.data is not empty
fallback() external payable {
if (msg.sender != address(0)) revert Easy2Pay__FailedToSendEther();
if (msg.sender != address(0)) revert EasyPay__FailedToSendEther();
}

function setOwner(address _newOwner) public onlyOwner {
Expand Down
6 changes: 2 additions & 4 deletions packages/foundry/script/Deploy.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,11 @@ contract DeployScript is ScaffoldETHDeploy {
);
}
vm.startBroadcast(deployerPrivateKey);
EasyPay easyPay = new EasyPay(
// vm.addr(deployerPrivateKey)
);
EasyPay easyPay = new EasyPay();
console.logString(
string.concat(
"EasyPay deployed at: ",
vm.toString(address(yourContract))
vm.toString(address(easyPay))
)
);
vm.stopBroadcast();
Expand Down

0 comments on commit d522c93

Please sign in to comment.