diff --git a/helpers/prepare.ts b/helpers/prepare.ts new file mode 100644 index 00000000..5caecbd3 --- /dev/null +++ b/helpers/prepare.ts @@ -0,0 +1,16 @@ +import { ethers } from "ethers"; + +export const prepareData = (contract: string, types: string[], args: any[]) => { + const params = prepareParams(types, args); + return `${contract}${params.slice(2)}`; +}; + +export const prepareParams = (types: string[], args: any[]) => { + const abiCoder = ethers.utils.defaultAbiCoder; + for (let i = 0; i < args.length; i++) { + if (types[i] === "bytes32") { + args[i] = ethers.utils.hexlify(ethers.utils.zeroPad(args[i], 32)); + } + } + return abiCoder.encode(types, args); +};