permissionless
Version:
A utility library for working with ERC-4337
79 lines • 2.42 kB
JavaScript
import { decodeFunctionData } from "viem";
export const decodeCallData = async (callData) => {
try {
const decodedBatch = decodeFunctionData({
abi: [
{
inputs: [
{
internalType: "address[]",
name: "dest",
type: "address[]"
},
{
internalType: "uint256[]",
name: "value",
type: "uint256[]"
},
{
internalType: "bytes[]",
name: "func",
type: "bytes[]"
}
],
name: "executeBatch",
outputs: [],
stateMutability: "nonpayable",
type: "function"
}
],
data: callData
});
const calls = [];
for (let i = 0; i < decodedBatch.args[0].length; i++) {
calls.push({
to: decodedBatch.args[0][i],
value: decodedBatch.args[1][i],
data: decodedBatch.args[2][i]
});
}
return calls;
}
catch { }
const decodedSingle = decodeFunctionData({
abi: [
{
inputs: [
{
internalType: "address",
name: "dest",
type: "address"
},
{
internalType: "uint256",
name: "value",
type: "uint256"
},
{
internalType: "bytes",
name: "func",
type: "bytes"
}
],
name: "execute",
outputs: [],
stateMutability: "nonpayable",
type: "function"
}
],
data: callData
});
return [
{
to: decodedSingle.args[0],
value: decodedSingle.args[1],
data: decodedSingle.args[2]
}
];
};
//# sourceMappingURL=decodeCallData.js.map