-
-
Save Elyx0/4f22fa876a45105704d0b8676a0e0780 to your computer and use it in GitHub Desktop.
Revisions
-
ezynda3 created this gist
Sep 21, 2021 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,30 @@ const ethers = require("ethers"); async function main() { if (!process.argv[2] || !process.argv[3]) { console.log("\nUsage: node generateCalldata.js <function signature> <args>"); console.log('e.g node generateCalldata.js "myFunction((uint8,bool)[],uint256)" "[[1,true],[2,false]],12345678"'); console.log("\n") throw Error } const sig = process.argv[2]; const abi = [`function ${sig}`]; const funcName = sig.substr(0, sig.indexOf("(")); const iface = new ethers.utils.Interface(abi); const args = JSON.parse(`[${process.argv[3]}]`); const calldata = iface.encodeFunctionData(funcName, args); console.log(calldata); } main() .then(() => process.exit(0)) .catch((error) => { console.error(error); process.exit(1); });