Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@hellwolf
Created February 19, 2019 14:39
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hellwolf/473d598b7963079e32af98ab168bc78a to your computer and use it in GitHub Desktop.
Save hellwolf/473d598b7963079e32af98ab168bc78a to your computer and use it in GitHub Desktop.
Truffle minimize json artifacts
#!/usr/bin/env bash
# Notes:
# - Shchema: https://github.com/trufflesuite/truffle/tree/develop/packages/truffle-contract-schema
# - bytecode vs deployedBytecode: https://ethereum.stackexchange.com/questions/32234/difference-between-bytecode-and-runtime-bytecode
for i in "$1"/*.json;do
[ -z "${i%%*.min.json}" ] && continue # already minified
m=${i%%.json}.min.json
echo "Minimizing truffle json artifact: $i"
echo "Original size: $(wc -c "$i")"
jq 'del(.ast,.legacyAST,.source,.deployedSourceMap,.userdoc,.sourcePath)' $i > $m
echo "Minimized size: $(wc -c "$m")"
done
@jackoelv
Copy link

great job!
when json file reduced, app.js resized from 5M to 2M. could you reduce it to less than 100K?
how to reduce web3 and then? thanks a lot!

@hellwolf
Copy link
Author

If you only need the ABI part of it, you could simply extract .abi only and trim everything off.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment