Skip to content

Commit

Permalink
contracts interaction
Browse files Browse the repository at this point in the history
  • Loading branch information
JustAnotherDevv committed Jul 14, 2024
1 parent 4f19423 commit ed1dfd3
Show file tree
Hide file tree
Showing 8 changed files with 972 additions and 12 deletions.
2 changes: 1 addition & 1 deletion packages/hardhat/contracts/BoxManager.sol
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ contract BoxManager is Ownable {
BoxStatus status;
}

constructor(address initialOwner, IERC20 _token) Ownable(initialOwner) {
constructor(IERC20 _token) Ownable() {
token = _token;
}

Expand Down
4 changes: 2 additions & 2 deletions packages/hardhat/contracts/BoxToken.sol
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ import "@openzeppelin/contracts/access/Ownable.sol";
import "@openzeppelin/contracts/token/ERC20/extensions/ERC20Permit.sol";

contract BoxToken is ERC20, Ownable, ERC20Permit {
constructor(address initialOwner)
constructor()
ERC20("BoxToken", "BOX")
Ownable(initialOwner)
Ownable()
ERC20Permit("BoxToken")
{}

Expand Down
11 changes: 7 additions & 4 deletions packages/hardhat/deploy/00_deploy_your_contract.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,21 +34,24 @@ const deployYourContract: DeployFunction = async function (hre: HardhatRuntimeEn

await deploy("BoxToken", {
from: deployer,
args: [deployer],
args: [],
log: true,
autoMine: true,
});

const boxToken = await hre.ethers.getContract<Contract>("BoxToken", deployer);
console.log(boxToken.target);

await deploy("BoxManager", {
from: deployer,
args: [deployer],
args: [boxToken.target],
log: true,
autoMine: true,
});

// Get the deployed contract to interact with it after deploying.
const yourContract = await hre.ethers.getContract<Contract>("YourContract", deployer);
console.log("👋 Initial greeting:", await yourContract.greeting());
// const boxToken = await hre.ethers.getContract<Contract>("BoxToken", deployer);
// console.log("👋 Initial greeting:", await boxToken.greeting());
};

export default deployYourContract;
Expand Down
4 changes: 2 additions & 2 deletions packages/hardhat/hardhat.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ const etherscanApiKey = process.env.ETHERSCAN_API_KEY || "DNXJA8RX2Q3VZ4URQIWP7Z

const config: HardhatUserConfig = {
solidity: {
version: "0.8.17",
version: "0.8.20",
settings: {
optimizer: {
enabled: true,
Expand All @@ -30,7 +30,7 @@ const config: HardhatUserConfig = {
},
},
},
defaultNetwork: "sepolia",
defaultNetwork: "localhost",
namedAccounts: {
deployer: {
// By default, it will take the first Hardhat account as the deployer
Expand Down
28 changes: 26 additions & 2 deletions packages/nextjs/app/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,42 @@ import { Address } from "~~/components/scaffold-eth";
import { Alert, AlertDescription, AlertTitle } from "~~/components/ui/alert";
import { Button } from "~~/components/ui/button";
import { Card, CardContent } from "~~/components/ui/card";
import { Badge } from "~~/components/ui/badge";
import { useReadContract } from "wagmi";
import {deployedContracts} from "~~/contracts/deployedContracts";
import { useScaffoldReadContract } from "~~/hooks/scaffold-eth";

const Home: NextPage = () => {
const { address: connectedAddress } = useAccount();

const { data: isRegistered } = useScaffoldReadContract({
contractName: "BoxManager",
functionName: "isBoxRegistered",
args: [BigInt(0)],
});

const { data: boxInfo } = useScaffoldReadContract({
contractName: "BoxManager",
functionName: "boxes",
args: [BigInt(0)],
});

return (
<>
<div className="flex py-10 flex-col px-5">
<div className="flex items-center flex-col flex-grow pt-10">
<div className="px-5">
<h1 className="text-center">
<span className="block text-2xl mb-2">Welcome to</span>
<span className="block text-4xl font-bold">The Box</span>
{/* <span className="block text-2xl mb-2">Welcome to</span>
<span className="block text-4xl font-bold">The Box</span> */}
<span className="block text-4xl mb-2 font-bold">Box.eth</span>
{isRegistered ? (
<div>
<Badge>{boxInfo?.status}</Badge>
</div>
) : ""}
{/* <span className="block text-xl">EMPTY</span> */}
{/* <Badge>Available</Badge> */}
</h1>
<p className="text-center text-lg">The peer-to-peer delivery service. </p>
</div>
Expand Down
2 changes: 2 additions & 0 deletions packages/nextjs/components/Footer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { BuidlGuidlLogo } from "~~/components/assets/BuidlGuidlLogo";
import { Faucet } from "~~/components/scaffold-eth";
import { useTargetNetwork } from "~~/hooks/scaffold-eth/useTargetNetwork";
import { useGlobalState } from "~~/services/store/store";
// import { getTargetNetworks } from "~~/utils/scaffold-eth";

/**
* Site footer
Expand All @@ -20,6 +21,7 @@ export const Footer = () => {
return (
<div className="min-h-0 py-5 px-1 mb-11 lg:mb-0">
<div className="w-full">
<Faucet />
<ul className="menu menu-horizontal w-full">
<div className="flex justify-center items-center gap-2 text-sm w-full">
<div className="text-center">
Expand Down
Loading

0 comments on commit ed1dfd3

Please sign in to comment.