Skip to content

Commit

Permalink
update the contract and the readme files
Browse files Browse the repository at this point in the history
  • Loading branch information
Abidoyesimze committed Dec 13, 2024
1 parent c3d0dd8 commit 39ebc79
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 26 deletions.
1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@
},
"packageManager": "[email protected]",
"devDependencies": {
"@nomicfoundation/hardhat-network-helpers": "^1.0.12",
"husky": "^9.1.6",
"lint-staged": "^15.2.10"
},
Expand Down
19 changes: 11 additions & 8 deletions packages/hardhat/Readme.md
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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
15 changes: 8 additions & 7 deletions packages/hardhat/contracts/PixelCanvas.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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 {}
Expand Down
31 changes: 21 additions & 10 deletions packages/hardhat/deploy/00_deploy_your_contract.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -25,28 +25,39 @@ 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.
autoMine: true,
});

// Get the deployed contract to interact with it after deploying.
const batchRegistry = await hre.ethers.getContract<Contract>("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<Contract>("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<Contract>("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"];

0 comments on commit 39ebc79

Please sign in to comment.