Skip to content

Commit

Permalink
prepare helpers
Browse files Browse the repository at this point in the history
  • Loading branch information
fadeev committed Oct 23, 2023
1 parent 69d1162 commit f3c08af
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions helpers/prepare.ts
Original file line number Diff line number Diff line change
@@ -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);
};

0 comments on commit f3c08af

Please sign in to comment.