Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

getFullCanvas #39

Merged
merged 2 commits into from
Dec 20, 2024
Merged

getFullCanvas #39

merged 2 commits into from
Dec 20, 2024

Conversation

melanke
Copy link
Contributor

@melanke melanke commented Dec 17, 2024

Description

  • Adds a new method to retrieve all canvaas pixels at once
  • Changes the pixel initialization to form "11" in black

Additional Information

Your ENS/address:
melanke.eth

Copy link

vercel bot commented Dec 17, 2024

@melanke is attempting to deploy a commit to the BuidlGuidl Team on Vercel.

A member of the Team first needs to authorize it.

Copy link
Collaborator

@phipsae phipsae left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the updates!

Just a quick note on the contract (though I’m not a full-on smart contract expert): the way you’re retrieving the full canvas doesn’t seem optimal. It’s quite gas inefficient, and you’ve reintroduced the "big array" again. We moved to mappings because they’re more efficient, but your getFullCanvas function switches back to arrays.

As a general rule of thumb, try to keep the smart contract as lean as possible and shift the heavy lifting to the front-end.

For example, could you use emitted events in the front-end to display the canvas instead?

* @dev Initialize a default Buidlguidl Batch11 inspired pixel art
* This is a simplified representation and can be customized
*/
function initializeBuidlGuidlLogo() private {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's very repetitive, why not having a loop? What costs gas is writing to the blockchain.

Comment on lines +191 to +202
function getFullCanvas() external view returns (Pixel[][] memory) {
Pixel[][] memory fullCanvas = new Pixel[][](CANVAS_WIDTH);

for (uint256 x = 0; x < CANVAS_WIDTH; x++) {
fullCanvas[x] = new Pixel[](CANVAS_HEIGHT);
for (uint256 y = 0; y < CANVAS_HEIGHT; y++) {
fullCanvas[x][y] = canvas[x][y];
}
}

return fullCanvas;
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In here you reintroducing the array again, we wanted to get rid of and exchanged it with a mapping.

@phipsae phipsae merged commit 0be284f into BuidlGuidl:main Dec 20, 2024
1 of 2 checks passed
Copy link

vercel bot commented Dec 20, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
batch11.buidlguidl.com ✅ Ready (Inspect) Visit Preview 💬 Add feedback Dec 20, 2024 6:23am

@phipsae
Copy link
Collaborator

phipsae commented Dec 20, 2024

Merged! I just deployed the contract and updated the ABI accordingly in externalContracts.ts.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants