/uniswap-calldata-optimization-monorepo-next-js

A full-stack snippet to demonstrate how to implement front-end part when doing calldata gas optimization with `Solid Grinder`

Primary LanguageTypeScript

📚 Calldata Optimization Demo with Monorepo Architecture 📚

A full-stack snippet & example to demonstrate how to implement calldata gas optimization with Solid Grinder

If you wonder how calldata optimization works, you can check it out at this guide

Note💡

The code is not audited yet. Please use it carefully in production.

Installation

Assuming that you have zellij installed:

pnpm i
cd contracts
pnpm i
cd web
pnpm i

Quickstart

There are two main components, which are blockchain component and web component

  1. Spinning up the blockchain component:
cd contracts
pnpm start

If it appears that you need to intall more dependencies, just delete /contracts/lib, modify the command and re-run it.

Note💡

In the first time, it is needed to install relevant dependencies:

cd contracts
pnpm prepare

This will open a customized terminal with three sub-terminals, including anvil, testing and interaction.

  1. In another terminal, run deployment scripts to the local network:
pnpm contracts:deploy

This will atomically deploy sets of deployment scripts.

  1. Export deployment artifacts with formated schema to be used later in front-end part:
pnpm contracts:export-local

This schema includes address and abi.

  1. Running the front-end component:
pnpm web:dev

Note💡

  1. (Optional) kill blockchain component when not needed
cd contracts
pnpm stop

Troubleshooting

These are some guidlines to do when the front-end component can not sync to the blockchain component:

  1. Delete generated files after deployment in your contracts/broadcast/ to clear the cache, and then re-deploy again.

  2. Go to your Metamask extention and clear the data. There sometimes are updates in local nonce, so the checksum in front-end pass doesnot match the right ones.

Settings -> Advanced -> Clear activity and nonce data
  1. Rebuild again
pnpm dev
  1. Make sure your metamask connect to the same address which has been registered. Otherwise, register it!!

💡 Note:

You can directly send Tx to the chain via your CLI:

cast send <Contract Address> "register(address)" <Sender Address> <Addr as Argument> --private-key <Sender Privatekey>
  1. Open new Chrome tab every time after you have spinned up blockchain compoment and deployed the contract in order to make sure the front-end does not cache the wrong config.

Contributing

See our contributing guidelines.

Acknowledgement

💡 Note:

We acknowledge, use, and get inspiration from this amazing template: jolly-roger.