Skip to content

Instantly share code, notes, and snippets.

@Elyx0
Forked from ezynda3/generateCalldata.js
Created October 9, 2021 08:31
Show Gist options
  • Save Elyx0/4f22fa876a45105704d0b8676a0e0780 to your computer and use it in GitHub Desktop.
Save Elyx0/4f22fa876a45105704d0b8676a0e0780 to your computer and use it in GitHub Desktop.
generateCalldata.js
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);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment