Skip to content

Commit

Permalink
update contract name
Browse files Browse the repository at this point in the history
  • Loading branch information
Paul-Sizon committed May 28, 2024
1 parent b1f52b5 commit 36d0ca7
Show file tree
Hide file tree
Showing 7 changed files with 39 additions and 110 deletions.
74 changes: 0 additions & 74 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,77 +12,3 @@ Next steps for project:
<a href="https://docs.scaffoldeth.io">Documentation</a> |
<a href="https://scaffoldeth.io">Website</a>
</h4>

🧪 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.

⚙️ Built using NextJS, RainbowKit, Hardhat, Wagmi, Viem, and Typescript.

-**Contract Hot Reload**: Your frontend auto-adapts to your smart contract as you edit it.
- 🪝 **[Custom hooks](https://docs.scaffoldeth.io/hooks/)**: Collection of React hooks wrapper around [wagmi](https://wagmi.sh/) to simplify interactions with smart contracts with typescript autocompletion.
- 🧱 [**Components**](https://docs.scaffoldeth.io/components/): Collection of common web3 components to quickly build your frontend.
- 🔥 **Burner Wallet & Local Faucet**: Quickly test your application with a burner wallet and local faucet.
- 🔐 **Integration with Wallet Providers**: Connect to different wallet providers and interact with the Ethereum network.

![Debug Contracts tab](https://github.com/scaffold-eth/scaffold-eth-2/assets/55535804/b237af0c-5027-4849-a5c1-2e31495cccb1)

## Requirements

Before you begin, you need to install the following tools:

- [Node (>= v18.17)](https://nodejs.org/en/download/)
- Yarn ([v1](https://classic.yarnpkg.com/en/docs/install/) or [v2+](https://yarnpkg.com/getting-started/install))
- [Git](https://git-scm.com/downloads)

## Quickstart

To get started with Scaffold-ETH 2, follow the steps below:

1. Clone this repo & install dependencies

```
git clone https://github.com/scaffold-eth/scaffold-eth-2.git
cd scaffold-eth-2
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 `Debug Contracts` page. You can tweak the app config in `packages/nextjs/scaffold.config.ts`.

Run smart contract test with `yarn hardhat:test`

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

## Documentation

Visit our [docs](https://docs.scaffoldeth.io) to learn how to start building with Scaffold-ETH 2.

To know more about its features, check out our [website](https://scaffoldeth.io).

## Contributing to Scaffold-ETH 2

We welcome contributions to Scaffold-ETH 2!

Please see [CONTRIBUTING.MD](https://github.com/scaffold-eth/scaffold-eth-2/blob/main/CONTRIBUTING.md) for more information and guidelines for contributing to Scaffold-ETH 2.
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import "hardhat/console.sol";
* It also allows the owner to withdraw the Ether in the contract
* @author BuidlGuidl
*/
contract YourContract {
contract BitTipContract {
address payable public platformOwner;
uint8 public platformFeePercentage;

Expand Down
18 changes: 9 additions & 9 deletions packages/hardhat/deploy/00_deploy_your_contract.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@ import { DeployFunction } from "hardhat-deploy/types";
import { Contract } from "ethers";

/**
* Deploys a contract named "YourContract" using the deployer account and
* Deploys a contract named "BitTipContract" using the deployer account and
* constructor arguments set to the deployer address
*
* @param hre HardhatRuntimeEnvironment object.
*/
const deployYourContract: DeployFunction = async function (hre: HardhatRuntimeEnvironment) {
const deployBitTipContract: DeployFunction = async function (hre: HardhatRuntimeEnvironment) {
/*
On localhost, the deployer account is the one that comes with Hardhat, which is already funded.
Expand All @@ -22,23 +22,23 @@ const deployYourContract: DeployFunction = async function (hre: HardhatRuntimeEn
const { deployer } = await hre.getNamedAccounts();
const { deploy } = hre.deployments;

await deploy("YourContract", {
from: "0x70997970C51812dc3A010C7d01b50e0d17dc79C8",
await deploy("BitTipContract", {
from: "0x2Ca3355E6e09e54bE4A70F44d6709DABA08fC786",
// Contract constructor arguments
args: [2],
args: [1],
log: true,
// autoMine: can be passed to the deploy function to make the deployment process faster on local networks by
// automatically mining the contract deployment transaction. There is no effect on live networks.
autoMine: true,
});

// Get the deployed contract to interact with it after deploying.
const yourContract = await hre.ethers.getContract<Contract>("YourContract", deployer);
const bittipContract = await hre.ethers.getContract<Contract>("BitTipContract", deployer);

};

export default deployYourContract;
export default deployBitTipContract;

// Tags are useful if you have multiple deploy files and only want to run one of them.
// e.g. yarn deploy --tags YourContract
deployYourContract.tags = ["YourContract"];
// e.g. yarn deploy --tags BitTipContract
deployBitTipContract.tags = ["BitTipContract"];
42 changes: 21 additions & 21 deletions packages/hardhat/test/YourContract.ts
Original file line number Diff line number Diff line change
@@ -1,44 +1,44 @@
import { expect } from "chai";
import { ethers } from "hardhat";
import { YourContract } from "../typechain-types";
import { BitTipContract } from "../typechain-types";

describe("YourContract", function () {
let yourContract: YourContract;
describe("BitTipContract", function () {
let bittipContract: BitTipContract;
let owner: any;
let addr1: any;
let addr2: any;

before(async () => {
[owner, addr1, addr2] = await ethers.getSigners();
const yourContractFactory = await ethers.getContractFactory("YourContract");
yourContract = (await yourContractFactory.deploy(2)) as YourContract;
await yourContract.waitForDeployment();
const bittipContractFactory = await ethers.getContractFactory("BitTipContract");
bittipContract = (await bittipContractFactory.deploy(2)) as BitTipContract;
await bittipContract.waitForDeployment();
});

describe("Deployment", function () {
it("Should set the right owner", async function () {
expect(await yourContract.platformOwner()).to.equal(owner.address);
expect(await bittipContract.platformOwner()).to.equal(owner.address);
});

it("Should set the right initial fee percentage", async function () {
expect(await yourContract.platformFeePercentage()).to.equal(2);
expect(await bittipContract.platformFeePercentage()).to.equal(2);
});
});

describe("Fee Percentage", function () {
it("Should allow the owner to change the fee percentage", async function () {
await yourContract.setPlatformFeePercentage(5);
expect(await yourContract.platformFeePercentage()).to.equal(5);
await bittipContract.setPlatformFeePercentage(5);
expect(await bittipContract.platformFeePercentage()).to.equal(5);
});

it("Should not allow non-owner to change the fee percentage", async function () {
await expect(yourContract.connect(addr1).setPlatformFeePercentage(5)).to.be.revertedWith(
await expect(bittipContract.connect(addr1).setPlatformFeePercentage(5)).to.be.revertedWith(
"Only the platform owner can perform this action."
);
});

it("Should not allow setting fee percentage above 100", async function () {
await expect(yourContract.setPlatformFeePercentage(101)).to.be.revertedWith(
await expect(bittipContract.setPlatformFeePercentage(101)).to.be.revertedWith(
"Fee percentage cannot exceed 100."
);
});
Expand All @@ -52,7 +52,7 @@ describe("YourContract", function () {
const initialCreatorBalance = await ethers.provider.getBalance(addr1.address);
const initialTipperBalance = await ethers.provider.getBalance(addr2.address);

const tx = await yourContract.connect(addr2).tipCreator(addr1.address, "", { value: tipAmount });
const tx = await bittipContract.connect(addr2).tipCreator(addr1.address, "", { value: tipAmount });
const receipt = await tx.wait();
const gasUsed = receipt!.gasUsed;
const gasPrice = tx.gasPrice || receipt!.gasPrice;
Expand All @@ -62,7 +62,7 @@ describe("YourContract", function () {
const finalCreatorBalance = await ethers.provider.getBalance(addr1.address);
const finalTipperBalance = await ethers.provider.getBalance(addr2.address);

const platformFeePercentage = BigInt(await yourContract.platformFeePercentage());
const platformFeePercentage = BigInt(await bittipContract.platformFeePercentage());
const platformFee = (BigInt(tipAmount) * platformFeePercentage) / BigInt(100);
const tipTransferAmount = BigInt(tipAmount) - platformFee;

Expand Down Expand Up @@ -96,14 +96,14 @@ describe("YourContract", function () {
});

it("Should revert if tip amount is zero", async function () {
await expect(yourContract.tipCreator(addr1.address, "comment", { value: 0 })).to.be.revertedWith(
await expect(bittipContract.tipCreator(addr1.address, "comment", { value: 0 })).to.be.revertedWith(
"Tip amount must be greater than 0."
);
});

it("Should revert if creator wallet address is invalid", async function () {
await expect(
yourContract.tipCreator(ethers.ZeroAddress, "", { value: ethers.parseEther("1.0") })
bittipContract.tipCreator(ethers.ZeroAddress, "", { value: ethers.parseEther("1.0") })
).to.be.revertedWith("Invalid creator wallet address.");
});
});
Expand All @@ -113,14 +113,14 @@ describe("YourContract", function () {
const depositAmount = ethers.parseEther("2.0");

await owner.sendTransaction({
to: await yourContract.getAddress(),
to: await bittipContract.getAddress(),
value: depositAmount,
});

const initialOwnerBalance = await ethers.provider.getBalance(owner.address);
const contractBalance = await ethers.provider.getBalance(await yourContract.getAddress());
const contractBalance = await ethers.provider.getBalance(await bittipContract.getAddress());

const tx = await yourContract.withdrawAll();
const tx = await bittipContract.withdrawAll();
const receipt = await tx.wait();
const gasUsed = receipt!.gasUsed * receipt!.gasPrice;

Expand All @@ -131,13 +131,13 @@ describe("YourContract", function () {
});

it("Should revert if non-owner tries to withdraw", async function () {
await expect(yourContract.connect(addr1).withdrawAll()).to.be.revertedWith(
await expect(bittipContract.connect(addr1).withdrawAll()).to.be.revertedWith(
"Only the platform owner can perform this action."
);
});

it("Should revert if contract balance is zero", async function () {
await expect(yourContract.withdrawAll()).to.be.revertedWith("Contract balance is zero.");
await expect(bittipContract.withdrawAll()).to.be.revertedWith("Contract balance is zero.");
});
});
});
6 changes: 3 additions & 3 deletions packages/nextjs/app/bittip/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,11 @@ const Creator: React.FC<CreatorProps> = ({ avatar_url, name, description, wallet

const provider = new ethers.BrowserProvider(walletClient.data);
const signer = await provider.getSigner();
const abi = deployedContracts[chainId]?.YourContract?.abi;
const contractAddress = deployedContracts[chainId]?.YourContract?.address;
const abi = deployedContracts[chainId]?.BitTipContract?.abi;
const contractAddress = deployedContracts[chainId]?.BitTipContract?.address;

if (!abi) {
console.error('ABI not found for YourContract on chain', chainId);
console.error('ABI not found for BitTipContract on chain', chainId);
return null;
}

Expand Down
4 changes: 2 additions & 2 deletions packages/nextjs/contracts/deployedContracts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ import { GenericContractsDeclaration } from "~~/utils/scaffold-eth/contract";

const deployedContracts = {
31337: {
YourContract: {
address: "0x34ee84036C47d852901b7069aBD80171D9A489a6",
BitTipContract: {
address: "0x1C674bf0d074Dc54bb13D1e6291C0cE88054C5b5",
abi: [
{
inputs: [
Expand Down
3 changes: 3 additions & 0 deletions packages/nextjs/tailwind.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,9 @@ module.exports = {
animation: {
"pulse-fast": "pulse 1s cubic-bezier(0.4, 0, 0.6, 1) infinite",
},
colors: {
"btn-success-disabled-text": "#000000",
},
},
},
};

0 comments on commit 36d0ca7

Please sign in to comment.