Skip to content

Commit

Permalink
script to calculate contract bytecode
Browse files Browse the repository at this point in the history
  • Loading branch information
haythemsellami committed Apr 20, 2020
1 parent d78ace7 commit dc4e454
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 3 deletions.
13 changes: 10 additions & 3 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@
},
"homepage": "https://github.com/aparnakr/OptionsProtocol#readme",
"dependencies": {
"minimist": "^1.2.5",
"truffle-hdwallet-provider": "^1.0.17"
}
}
24 changes: 24 additions & 0 deletions scripts/CalculateContractBytecode.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
// This simple script tells you how big your contract byte code is and how much you have until you exceed
// the current block limit as defined by EIP170.

const argv = require("minimist")(process.argv.slice(), { string: ["contract"] });
const contractName = argv.contract;

if (!contractName) {
console.log("Please enter the contract name as a parameter as `--contract <name>`.");
return;
}
var child = require("child_process").exec("truffle compile");
child.stdout.pipe(process.stdout);
child.on("exit", function() {
console.log("finished compiling 🚀!");
console.log("loading", contractName + ".json");
let obj = require("./../build/contracts/" + contractName + ".json");

const byteCodeSize = (obj.bytecode.length - 2) / 2;
const remainingSize = 2 ** 14 + 2 ** 13 - (obj.bytecode.length - 2) / 2;
console.log("Contract is", byteCodeSize, "bytes in size.");
console.log("This leaves a total of", remainingSize, "bytes within the EIP170 limit 🔥.");

process.exit();
});

0 comments on commit dc4e454

Please sign in to comment.