Skip to content
On this page

getDepositTransaction

Returns a DepositTransaction from a TransactionDepositedEvent and sourceHash or logIndex, L1 block hash and SourceHashDomain.

Internally, if sourceHash not provided, will call getSourceHash({ domain, logIndex, l1BlockHash }).

Import

ts
import { getDepositTransaction } from 'op-viem'

Usage

ts
import { getDepositTransaction } from 'viem'

const event: TransactionDepositedEvent = {
  eventName: 'TransactionDeposited',
  args: {
    from: '0xbc3ed6B537f2980e66f396Fe14210A56ba3f72C4',
    to: '0xbc3ed6B537f2980e66f396Fe14210A56ba3f72C4',
    version: 0n,
    opaqueData:
      '0x0000000000000000000000000000000000000000000000000de0b6b3a76400000000000000000000000000000000000000000000000000000000000000000001000000000000526c0000',
  },
}
const logIndex = 196
const blockHash =
  '0x9ba3933dc6ce43c145349770a39c30f9b647f17668f004bd2e05c80a2e7262f7'

// without known source hash
const deposit = getDepositTransaction({
  event: event,
  logIndex: logIndex,
  l1BlockHash: blockHash,
})

// with known source hash
const deposit = getDepositTransaction({
  event: event,
  sourceHash:
    '0xd0868c8764d81f1749edb7dec4a550966963540d9fe50aefce8cdb38ea7b2213',
})

Returns

DepositTransaction

The L2 deposit transaction generated by the L1 transaction. Can be rlp encoded and hashed to get the L2 transaction hash.

Parameters

event

sourceHash (optional)

Can be provided instead of l1BlockHash and logIndex.

logIndex (optional)

  • Type: number

The index of the given TransactionDepositedEvent log among all events emitted in the same L1 block. MUST be provied with l1BlockHash if sourceHash not passed.

l1BlockHash (optional)

  • Type: Hex

The blockhash of the L1 block in which the passed event was emitted. MUST be provied with logIndex if sourceHash not passed.

domain (optional)

Note: only SourceHashDomain.UserDeposit currently supported.