Skip to content

Commit

Permalink
Added first draft of contract, deploy script, and README
Browse files Browse the repository at this point in the history
  • Loading branch information
luloxi committed Dec 28, 2023
1 parent 90216a2 commit 69076fa
Show file tree
Hide file tree
Showing 3 changed files with 106 additions and 5 deletions.
55 changes: 54 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,57 @@
# 🏗 Scaffold-ETH 2
# 💸 EasyPay 💸

💸 dApp for requesting payments in a currency (like USD, ETH and BTC), and accept different type of valid tokens that share a common value using [Chainlink Price Feeds](https://docs.chain.link/data-feeds/price-feeds).

🐣 Project being developed by [Newbie's Lounge](https://lulox.notion.site/Newbie-s-Lounge-68ea7c4c5f1a4ec29786be6a76516878)
👷‍♀️ To view current development tasks, [join this Trello board](https://trello.com/invite/b/s0vot1BA/ATTI366c508087a404ccf9343def4d76d1ce6F7899AA/newbies-lounge).
🧰 To chat with other buidlers about this project, [join our Telegram group](https://t.me/+FwCZPG51UhwzOTZh)
🛠️ To collaborate, [fork and pull](https://github.com/susam/gitpr) a request to this repo.

## Quickstart

To get started with EasyPay, follow the steps below:

1. 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:

```
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:

```
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:

```
yarn start
```

Visit your app on: `http://localhost:3000`. You can interact with your smart contract using the contract component or the example ui in the frontend. You can tweak the app config in `packages/nextjs/scaffold.config.ts`.

Run smart contract test with `yarn hardhat:test`

- Edit your smart contract `EasyPay.sol` in `packages/hardhat/contracts`
- Edit your frontend in `packages/nextjs/pages`
- Edit your deployment scripts in `packages/hardhat/deploy`

🏗 Project created using [Scaffold-ETH 2](https://scaffoldeth.io/)

## 🏗 About Scaffold-ETH 2

🧪 An open-source, up-to-date toolkit for building decentralized applications (dapps) on the Ethereum blockchain. It's designed to make it easier for developers to create and deploy smart contracts and build user interfaces that interact with those contracts.

Expand Down
48 changes: 48 additions & 0 deletions packages/foundry/contracts/EasyPay.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.22;

/**
@dev Struct to store payment requests
@variables amount: Amount of USD requested
@variables receiver: Address of payment receiver
@variables completed: Boolean to determine if payment was succesfully made
*/
struct PayRequest {
uint256 amount;
address receiver;
bool completed;
}

contract EasyPay {
uint256 requests;
/**
@dev Mapping to store PayRequest structs mapped to a unique requestId
*/
mapping(uint256 requestId => PayRequest) public payRequests;

function requestPayment(uint256 _amount) public {
requests++;
payRequests[requests] = PayRequest(_amount, msg.sender, false);
}

function pay(uint256 _requestId) public payable {
require(payRequests[_requestId].receiver != address(0), "Request doesn't exist or was made by a dumb human!" );
require(payRequests[_requestId].amount <= msg.value, "Ether sent must be equal or greater than requested amount!");
require(payRequests[_requestId].completed == false, "Request has already been paid!");
payRequests[_requestId].completed = true;
// Call returns a boolean value indicating success or failure.
// This is the current recommended method to use to transfer ETH.
(bool sent, ) = payRequests[_requestId].receiver.call{value: msg.value}("");
require(sent, "Failed to send Ether, try again next block!");
}

// Function in case a payment is received where msg.data must be empty
receive() external payable {
require(msg.sender == address(0), "Are you stupid or what? Take care of your ETH!");
}

// Fallback function is called when msg.data is not empty
fallback() external payable {
require(msg.sender == address(0), "Are you stupid or what? Take care of your ETH!");
}
}
8 changes: 4 additions & 4 deletions packages/foundry/script/Deploy.s.sol
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
//SPDX-License-Identifier: MIT
pragma solidity ^0.8.19;

import "../contracts/YourContract.sol";
import "../contracts/EasyPay.sol";
import "./DeployHelpers.s.sol";

contract DeployScript is ScaffoldETHDeploy {
Expand All @@ -15,12 +15,12 @@ contract DeployScript is ScaffoldETHDeploy {
);
}
vm.startBroadcast(deployerPrivateKey);
YourContract yourContract = new YourContract(
vm.addr(deployerPrivateKey)
EasyPay easyPay = new EasyPay(
// vm.addr(deployerPrivateKey)
);
console.logString(
string.concat(
"YourContract deployed at: ",
"EasyPay deployed at: ",
vm.toString(address(yourContract))
)
);
Expand Down

0 comments on commit 69076fa

Please sign in to comment.