From 39ebc794f6e75d44c3d8bb23619cbcf561d914f2 Mon Sep 17 00:00:00 2001 From: Abidoyesimze Date: Fri, 13 Dec 2024 21:47:21 +0100 Subject: [PATCH] update the contract and the readme files --- package.json | 1 - packages/hardhat/Readme.md | 19 +++++++----- packages/hardhat/contracts/PixelCanvas.sol | 15 ++++----- .../hardhat/deploy/00_deploy_your_contract.ts | 31 +++++++++++++------ 4 files changed, 40 insertions(+), 26 deletions(-) diff --git a/package.json b/package.json index 39f78b3..44fdb6f 100644 --- a/package.json +++ b/package.json @@ -38,7 +38,6 @@ }, "packageManager": "yarn@3.2.3", "devDependencies": { - "@nomicfoundation/hardhat-network-helpers": "^1.0.12", "husky": "^9.1.6", "lint-staged": "^15.2.10" }, diff --git a/packages/hardhat/Readme.md b/packages/hardhat/Readme.md index 7d11b9e..da8bb4b 100644 --- a/packages/hardhat/Readme.md +++ b/packages/hardhat/Readme.md @@ -1,7 +1,7 @@ ## PixelCanvas: Decentralized Collaborative Pixel Art Smart Contract ### Contract Overview -A collaborative on-chain pixel art platform implemented as an Ethereum smart contract, enabling users to create and modify a shared 64x64 pixel canvas. +PixelCanvas is an Ethereum smart contract that enables collaborative pixel art creation on a fixed 64x64 canvas with a predefined color palette. ### Technical Specifications - **Blockchain**: Ethereum @@ -29,20 +29,23 @@ Allows user to place a single pixel Emits PixelPlaced event for tracking 2. Canvas Retrieval - getPixel(x, y): Retrieves individual pixel information -getCanvasSnapshot(): Returns entire canvas state +initializeBuidlGuidlLogo(): Sets initial canvas state with Batch11 logo + +3. Contract Management +withdraw(): Allows owner to withdraw contract balance +Accepts Ether via fallback() and receive() functions -3. Initialization +4. Initialization Test the PixelCanvas contract Includes default Buidlguidl Batch11 logo on contract deployment Demonstrates initial canvas state -Known Limitations - -Fixed 64x64 canvas size -Limited 8-color palette +Current Limitations +Fixed canvas size (64x64) No pixel modification after placement +Limited to 8 colors +Only contract owner can withdraw funds diff --git a/packages/hardhat/contracts/PixelCanvas.sol b/packages/hardhat/contracts/PixelCanvas.sol index a019832..e4b02d6 100644 --- a/packages/hardhat/contracts/PixelCanvas.sol +++ b/packages/hardhat/contracts/PixelCanvas.sol @@ -111,15 +111,16 @@ mapping(uint256 => mapping(uint256 => Pixel)) public canvas; function withdraw() external onlyOwner { - uint256 balance = address(this).balance; - require(balance > 0, "No funds to withdraw"); + uint256 balance = address(this).balance; + require(balance > 0, "No funds to withdraw"); - // Transfer the balance to the owner - payable(owner()).transfer(balance); + + (bool success, ) = payable(owner()).call{value: balance}(""); + require(success, "Transfer failed"); - // Emit withdrawal event - emit Withdrawal(owner(), balance); - } + + emit Withdrawal(owner(), balance); +} // Fallback and receive functions to accept Ether fallback() external payable {} diff --git a/packages/hardhat/deploy/00_deploy_your_contract.ts b/packages/hardhat/deploy/00_deploy_your_contract.ts index 1fc13e0..740675b 100644 --- a/packages/hardhat/deploy/00_deploy_your_contract.ts +++ b/packages/hardhat/deploy/00_deploy_your_contract.ts @@ -3,7 +3,7 @@ import { DeployFunction } from "hardhat-deploy/types"; import { Contract } from "ethers"; // Update with your Batch number -const BATCH_NUMBER = "11"; +// const BATCH_NUMBER = "11"; /** * Deploys a contract named "deployYourContract" using the deployer account and @@ -25,10 +25,13 @@ const deployYourContract: DeployFunction = async function (hre: HardhatRuntimeEn const { deployer } = await hre.getNamedAccounts(); const { deploy } = hre.deployments; - await deploy("BatchRegistry", { + // await deploy("BatchRegistry", { + // from: deployer, + // // Contract constructor arguments + // args: [deployer, BATCH_NUMBER], + await deploy("PixelCanvas", { from: deployer, - // Contract constructor arguments - args: [deployer, BATCH_NUMBER], + args: [], 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. @@ -36,17 +39,25 @@ const deployYourContract: DeployFunction = async function (hre: HardhatRuntimeEn }); // Get the deployed contract to interact with it after deploying. - const batchRegistry = await hre.ethers.getContract("BatchRegistry", deployer); - console.log("\nBatchRegistry deployed to:", await batchRegistry.getAddress()); - console.log("Remember to update the allow list!\n"); + // const batchRegistry = await hre.ethers.getContract("BatchRegistry", deployer); + // console.log("\nBatchRegistry deployed to:", await batchRegistry.getAddress()); + // console.log("Remember to update the allow list!\n"); + + const pixelCanvas = await hre.ethers.getContract("PixelCanvas", deployer); + console.log("\nPixelCanvas deployed to:", await pixelCanvas.getAddress()); // The GraduationNFT contract is deployed on the BatchRegistry constructor. - const batchGraduationNFTAddress = await batchRegistry.batchGraduationNFT(); - console.log("BatchGraduation NFT deployed to:", batchGraduationNFTAddress, "\n"); + // const batchGraduationNFTAddress = await batchRegistry.batchGraduationNFT(); + // console.log("BatchGraduation NFT deployed to:", batchGraduationNFTAddress, "\n"); + + // Verify initial canvas state + const canvasWidth = await pixelCanvas.CANVAS_WIDTH(); + const canvasHeight = await pixelCanvas.CANVAS_HEIGHT(); + console.log(`Canvas dimensions: ${canvasWidth}x${canvasHeight}`); }; export default deployYourContract; // 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 = ["BatchRegistry"]; +deployYourContract.tags = ["PixelCanvas"];