Skip to main content
Version: Next

Function: calculateL2MessageTxHash()

calculateL2MessageTxHash(l1FromAddress, l2ToAddress, l2Selector, l2Calldata, l2ChainId, l1Nonce): string

Defined in: src/utils/hash/transactionHash/v2.ts:158

Calculate the L2 transaction hash generated by a message L1->L2

Parameters

l1FromAddress

BigNumberish

L1 account address that paid the message.

l2ToAddress

BigNumberish

L2 contract address to execute.

l2Selector

BigNumberish

can be a function name ("bridge_withdraw") or a number (BigNumberish).

l2Calldata

RawCalldata

an array of BigNumberish of the raw parameters passed to the above function.

l2ChainId

"0x534e5f4d41494e" | "0x534e5f5345504f4c4941"

L2 chain ID : from constants.StarknetChainId.xxx

l1Nonce

BigNumberish

The nonce of the L1 account.

Returns

string

hex-string of the L2 transaction hash

Example

const l1FromAddress = "0x0000000000000000000000008453fc6cd1bcfe8d4dfc069c400b433054d47bdc";
const l2ToAddress = 2158142789748719025684046545159279785659305214176670733242887773692203401023n;
const l2Selector = 774397379524139446221206168840917193112228400237242521560346153613428128537n;
const payload = [
4543560n,
829565602143178078434185452406102222830667255948n,
3461886633118033953192540141609307739580461579986333346825796013261542798665n,
9000000000000000n,
0n,
];
const l1Nonce = 8288n;
const result = hash.calculateL2MessageTxHash(l1FromAddress, l2ToAddress, l2Selector, payload, constants.StarknetChainId.SN_SEPOLIA, l1Nonce);
// result = "0x67d959200d65d4ad293aa4b0da21bb050a1f669bce37d215c6edbf041269c07"