Hey is a decentralized and permissionless social media app built with Lens Protocol 馃尶
1import type {
2 Eip712TransactionRequest,
3 Eip1559TransactionRequest
4} from "@hey/indexer";
5import type { Address, Hex } from "viem";
6
7interface GetTransactionDataOptions {
8 sponsored?: boolean;
9}
10
11interface TransactionData {
12 data: Hex;
13 gas: bigint;
14 maxFeePerGas: bigint;
15 maxPriorityFeePerGas: bigint;
16 nonce: number;
17 to: Address;
18 value: bigint;
19 paymaster?: Address;
20 paymasterInput?: Hex;
21}
22
23const getTransactionData = (
24 raw: Eip1559TransactionRequest | Eip712TransactionRequest,
25 options: GetTransactionDataOptions = {}
26): TransactionData => {
27 const data: TransactionData = {
28 data: raw.data as Hex,
29 gas: BigInt(raw.gasLimit),
30 maxFeePerGas: BigInt(raw.maxFeePerGas),
31 maxPriorityFeePerGas: BigInt(raw.maxPriorityFeePerGas),
32 nonce: raw.nonce,
33 to: raw.to as Address,
34 value: BigInt(raw.value)
35 };
36
37 if (options.sponsored && "customData" in raw) {
38 data.paymaster = raw.customData.paymasterParams?.paymaster as
39 | Address
40 | undefined;
41 data.paymasterInput = raw.customData.paymasterParams?.paymasterInput as
42 | Hex
43 | undefined;
44 }
45
46 return data;
47};
48
49export default getTransactionData;