Created
September 21, 2021 11:22
-
-
Save ezynda3/4bcc4fbaf60a98054348bbb68ab8f599 to your computer and use it in GitHub Desktop.
generateCalldata.js
This file contains 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 characters
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