@morph-l2/sdk • Docs
@morph-l2/sdk / CrossChainMessenger
Class: CrossChainMessenger
Constructors
new CrossChainMessenger()
new CrossChainMessenger(
opts
):CrossChainMessenger
Creates a new CrossChainProvider instance.
Parameters
• opts
Options for the provider.
• opts.backendURL?: string
backend for withdraw proof gen.
• opts.bridges?: BridgeAdapterData
Optional bridge address list.
• opts.contracts?: DeepPartial
<OEContractsLike
>
Optional contract address overrides.
• opts.l1ChainId: NumberLike
Chain ID for the L1 chain.
• opts.l1SignerOrProvider: SignerOrProviderLike
Signer or Provider for the L1 chain, or a JSON-RPC url.
• opts.l2ChainId: NumberLike
Chain ID for the L2 chain.
• opts.l2SignerOrProvider: SignerOrProviderLike
Signer or Provider for the L2 chain, or a JSON-RPC url.
Returns
Source
src/cross-chain-messenger.ts:130
Properties
backendURL
backendURL:
string
Backend url for withdrawal prove server
Source
src/cross-chain-messenger.ts:76
bridges
bridges:
BridgeAdapters
List of custom bridges for the given network.
Source
src/cross-chain-messenger.ts:116
contracts
contracts:
OEContracts
Contract objects attached to their respective providers and addresses.
Source
src/cross-chain-messenger.ts:111
estimateGas
estimateGas:
object
Object that holds the functions that estimates the gas required for a given transaction. Follows the pattern used by ethers.js.
approveERC20()
approveERC20: (
l1Token
,l2Token
,amount
,opts
?) =>Promise
<BigNumber
>
Estimates gas required to approve some tokens to deposit into the L2 chain.
Parameters
• l1Token: AddressLike
The L1 token address.
• l2Token: AddressLike
The L2 token address.
• amount: NumberLike
Amount of the token to approve.
• opts?: IActionOptions
Additional options.
Returns
Promise
<BigNumber
>
depositERC20()
depositERC20: (
l1Token
,l2Token
,amount
,opts
?) =>Promise
<BigNumber
>
Estimates gas required to deposit some ERC20 tokens into the L2 chain.
Parameters
• l1Token: AddressLike
Address of the L1 token.
• l2Token: AddressLike
Address of the L2 token.
• amount: NumberLike
Amount to deposit.
• opts?: IActionOptions
Additional options.
Returns
Promise
<BigNumber
>
depositETH()
depositETH: (
amount
,opts
?) =>Promise
<BigNumber
>
Estimates gas required to deposit some ETH into the L2 chain.
Parameters
• amount: NumberLike
Amount of ETH to deposit.
• opts?: IActionOptions
Additional options.
Returns
Promise
<BigNumber
>
proveAndRelayMessage()
proveAndRelayMessage: (
message
,opts
?) =>Promise
<BigNumber
>
Estimates gas required to proveAndRelay a cross chain message. Only applies to L2 to L1 messages.
Parameters
• message: MessageLike
Message to generate the proving transaction for.
• opts?: IActionOptions
Additional options.
Returns
Promise
<BigNumber
>
sendMessage()
sendMessage: (
message
,opts
?) =>Promise
<BigNumber
>
Estimates gas required to send a cross chain message.
Parameters
• message: CrossChainMessageRequest
Cross chain message to send.
• opts?: IActionOptions
Additional options.
Returns
Promise
<BigNumber
>
withdrawERC20()
withdrawERC20: (
l1Token
,l2Token
,amount
,opts
?) =>Promise
<BigNumber
>
Estimates gas required to withdraw some ERC20 tokens back to the L1 chain.
Parameters
• l1Token: AddressLike
Address of the L1 token.
• l2Token: AddressLike
Address of the L2 token.
• amount: NumberLike
Amount to withdraw.
• opts?: IActionOptions
Additional options.
Returns
Promise
<BigNumber
>
withdrawETH()
withdrawETH: (
amount
,opts
?) =>Promise
<BigNumber
>
Estimates gas required to withdraw some ETH back to the L1 chain.
Parameters
• amount: NumberLike
Amount of ETH to withdraw.
• opts?: IActionOptions
Additional options.
Returns
Promise
<BigNumber
>
Source
src/cross-chain-messenger.ts:1600
l1ChainId
l1ChainId:
number
Chain ID for the L1 network.
Source
src/cross-chain-messenger.ts:101
l1CrossDomainMessenger
l1CrossDomainMessenger:
Contract
CrossDomainMessenger connected to the L1 chain.
Source
src/cross-chain-messenger.ts:91
l1SignerOrProvider
l1SignerOrProvider:
Provider
|Signer
Provider connected to the L1 chain.
Source
src/cross-chain-messenger.ts:81
l2ChainId
l2ChainId:
number
Chain ID for the L2 network.
Source
src/cross-chain-messenger.ts:106
l2CrossDomainMessenger
l2CrossDomainMessenger:
Contract
CrossDomainMessenger connected to the L2 chain.
Source
src/cross-chain-messenger.ts:96
l2SignerOrProvider
l2SignerOrProvider:
Provider
|Signer
Provider connected to the L2 chain.
Source
src/cross-chain-messenger.ts:86
populateTransaction
populateTransaction:
object
Object that holds the functions that generate transactions to be signed by the user. Follows the pattern used by ethers.js.
approveERC20()
approveERC20: (
l1Token
,l2Token
,amount
,opts
?) =>Promise
<TransactionRequest
>
Generates a transaction for approving some tokens to deposit into the L2 chain.
Parameters
• l1Token: AddressLike
The L1 token address.
• l2Token: AddressLike
The L2 token address.
• amount: NumberLike
Amount of the token to approve.
• opts?: IActionOptions
Additional options.
Returns
Promise
<TransactionRequest
>
depositERC20()
depositERC20: (
l1Token
,l2Token
,amount
,opts
?,isEstimatingGas
) =>Promise
<TransactionRequest
>
Generates a transaction for depositing some ERC20 tokens into the L2 chain.
Parameters
• l1Token: AddressLike
Address of the L1 token.
• l2Token: AddressLike
Address of the L2 token.
• amount: NumberLike
Amount to deposit.
• opts?: IActionOptions
Additional options.
• isEstimatingGas?: boolean
= false
Returns
Promise
<TransactionRequest
>
depositETH()
depositETH: (
amount
,opts
?,isEstimatingGas
) =>Promise
<TransactionRequest
>
Generates a transaction for depositing some ETH into the L2 chain.
Parameters
• amount: NumberLike
Amount of ETH to deposit.
• opts?: IActionOptions
Additional options.
• isEstimatingGas?: boolean
= false
Returns
Promise
<TransactionRequest
>
proveAndRelayMessage()
proveAndRelayMessage: (
message
,opts
?) =>Promise
<TransactionRequest
>
Generates a message proving and relaying transaction that can be signed and executed. Only applicable for L2 to L1 messages.
Parameters
• message: MessageLike
Message to generate the proving transaction for.
• opts?: IActionOptions
Additional options.
Returns
Promise
<TransactionRequest
>
sendMessage()
sendMessage: (
message
,opts
?) =>Promise
<TransactionRequest
>
Generates a transaction that sends a given cross chain message. This transaction can be signed and executed by a signer.
Parameters
• message: CrossChainMessageRequest
Cross chain message to send.
• opts?: IActionOptions
Additional options.
Returns
Promise
<TransactionRequest
>
withdrawERC20()
withdrawERC20: (
l1Token
,l2Token
,amount
,opts
?,isEstimatingGas
?) =>Promise
<TransactionRequest
>
Generates a transaction for withdrawing some ERC20 tokens back to the L1 chain.
Parameters
• l1Token: AddressLike
Address of the L1 token.
• l2Token: AddressLike
Address of the L2 token.
• amount: NumberLike
Amount to withdraw.
• opts?: IActionOptions
Additional options.
• isEstimatingGas?: boolean
Returns
Promise
<TransactionRequest
>
withdrawETH()
withdrawETH: (
amount
,opts
?,isEstimatingGas
?) =>Promise
<TransactionRequest
>
Generates a transaction for withdrawing some ETH back to the L1 chain.
Parameters
• amount: NumberLike
Amount of ETH to withdraw.
• opts?: IActionOptions
Additional options.
• isEstimatingGas?: boolean
Returns
Promise
<TransactionRequest
>
Source
src/cross-chain-messenger.ts:1304
Accessors
l1Provider
get
l1Provider():Provider
Provider connected to the L1 chain.
Returns
Provider
Source
src/cross-chain-messenger.ts:193
l1Signer
get
l1Signer():Signer
Signer connected to the L1 chain.
Returns
Signer
Source
src/cross-chain-messenger.ts:215
l2Provider
get
l2Provider():Provider
Provider connected to the L2 chain.
Returns
Provider
Source
src/cross-chain-messenger.ts:204
l2Signer
get
l2Signer():Signer
Signer connected to the L2 chain.
Returns
Signer
Source
src/cross-chain-messenger.ts:226
Methods
approval()
approval(
l1Token
,l2Token
,opts
?):Promise
<BigNumber
>
Queries the account's approval amount for a given L1 token.
Parameters
• l1Token: AddressLike
The L1 token address.
• l2Token: AddressLike
The L2 token address.
• opts?: IActionOptions
Additional options.
Returns
Promise
<BigNumber
>
Amount of tokens approved for deposits from the account.
Source
src/cross-chain-messenger.ts:1214
approveERC20()
approveERC20(
l1Token
,l2Token
,amount
,opts
?):Promise
<TransactionResponse
>
Approves a deposit into the L2 chain.
Parameters
• l1Token: AddressLike
The L1 token address.
• l2Token: AddressLike
The L2 token address.
• amount: NumberLike
Amount of the token to approve.
• opts?: IActionOptions
Additional options.
Returns
Promise
<TransactionResponse
>
Transaction response for the approval transaction.
Source
src/cross-chain-messenger.ts:1233
depositERC20()
depositERC20(
l1Token
,l2Token
,amount
,opts
?):Promise
<TransactionResponse
>
Deposits some ERC20 tokens into the L2 chain.
Parameters
• l1Token: AddressLike
Address of the L1 token.
• l2Token: AddressLike
Address of the L2 token.
• amount: NumberLike
Amount to deposit.
• opts?: IActionOptions
Additional options.
Returns
Promise
<TransactionResponse
>
Transaction response for the deposit transaction.
Source
src/cross-chain-messenger.ts:1256
depositETH()
depositETH(
amount
,opts
?):Promise
<TransactionResponse
>
Deposits some ETH into the L2 chain.
Parameters
• amount: NumberLike
Amount of ETH to deposit (in wei).
• opts?: IActionOptions
Additional options.
Returns
Promise
<TransactionResponse
>
Transaction response for the deposit transaction.
Source
src/cross-chain-messenger.ts:1183
encodeFunctionMessage()
encodeFunctionMessage(
options
):string
L2CrossDomainMessenger contract encode message, such as hashCrossDomainMessagev1
Parameters
• options
• options.message: string
The message passed along with the cross domain message
• options.messageNonce: BigNumber
The cross domain message nonce
• options.sender: string
The sender of the cross domain message
• options.target: string
The target of the cross domain message
• options.value: BigNumber
The value being sent with the cross domain message
Returns
string
Source
src/cross-chain-messenger.ts:972
estimateL2MessageGasLimit()
estimateL2MessageGasLimit(
message
,opts
?):Promise
<BigNumber
>
Estimates the amount of gas required to fully execute a given message on L2. Only applies to L1 => L2 messages. You would supply this gas limit when sending the message to L2.