Post Processing Tools
The size of the contract is a critical characteristic. The best way to keep it small is a well-designed minimalistic code with a reduced number of dependencies. It is especially important for large contracts and huge multi-contract dApps that can take a fortune to deploy.
When you have done your best with the code optimization it is worth reducing the size of the contract by minifying it.
Ready to use script
We have prepared a simple
bash script that can be used to minify
.wasm contract file. You can find it here.
The current approach to minification is the following:
- Snip (i.e. just replace with unreachable instruction) few known fat functions from the standard library (such as float formatting and panic-related) with
wasm-gcto eliminate all functions reachable from the snipped functions.
- Strip unneeded sections, such as names with
binaryen wasm-opt, which cleans up the rest.
Requirements to run the script:
cargo install wasm-snip wasm-gc
- install binaryen and wabt on your system. For Ubuntu and other Debian based Linux distributions run:
apt install binaryen wabt
Minification could be rather aggressive, so you must test the contract after minification. Standalone NEAR runtime could be helpful here.