Skip to content

Instantly share code, notes, and snippets.

@ezynda3
Created September 21, 2021 11:22
Show Gist options
  • Save ezynda3/4bcc4fbaf60a98054348bbb68ab8f599 to your computer and use it in GitHub Desktop.
Save ezynda3/4bcc4fbaf60a98054348bbb68ab8f599 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