EthBridger¶
- class arbitrum_py.asset_bridger.eth_bridger.EthBridger(child_network)[source]¶
Bases:
AssetBridger[DepositParams,WithdrawParams]Bridger for moving ETH or custom gas tokens between parent and child networks.
This class provides functionality for bridging ETH (or a custom gas token) between a parent chain (typically Ethereum mainnet) and a child chain (an Arbitrum chain). It handles token approvals, deposits, withdrawals, and inbox interactions.
The bridger supports two main scenarios: 1. Native ETH bridging when the chain uses ETH as its gas token 2. Custom ERC20 token bridging when the chain uses a different token for gas
- Variables:
child_network (ArbitrumNetwork) – Network configuration for the child chain
- __init__(child_network)[source]¶
Initialize the ETH bridger.
- Parameters:
child_network (
ArbitrumNetwork) – ArbitrumNetwork instance containing chain configuration including chain IDs and bridge details.
- static from_provider(child_provider)[source]¶
Create an EthBridger instance from a child chain provider.
- Parameters:
child_provider (
Web3) – Web3 provider connected to the child chain- Returns:
New bridger instance configured for the detected network
- Return type:
- Raises:
ArbSdkError – If network detection fails or network is not supported
- is_approve_gas_token_params(params)[source]¶
Check if params represent standard approve parameters vs custom transaction.
Helper method to distinguish between an ApproveGasTokenParams dict and an ApproveGasTokenTxRequest dict.
- Parameters:
params (
Dict[str,Any]) – Dictionary containing either standard approve parameters or a custom transaction request- Returns:
True if params is ApproveGasTokenParams, False if ApproveGasTokenTxRequest
- Return type:
bool
- get_approve_gas_token_request(params=None)[source]¶
Create transaction request to approve custom gas token for bridging.
Creates a transaction request object to approve a custom gas token (ERC20) for bridging on the parent chain. This is only needed when the chain uses an ERC20 token for gas instead of native ETH.
- Parameters:
params (
Optional[Dict[str,Any]]) – Optional dictionary containing: - amount: Amount to approve (defaults to MAX_UINT256) - parentProvider: Web3 provider for parent chain- Return type:
TxParams- Returns:
Transaction request object with ‘to’, ‘data’, and ‘value’ fields
- Raises:
ValueError – If the chain uses ETH as its native gas token
- approve_gas_token(params)[source]¶
Approve custom gas token for spending by the Inbox contract.
This method approves the custom gas token to be spent by the Inbox contract on the parent network. This is only necessary when the chain uses an ERC20 token for gas instead of native ETH.
- Parameters:
params (
Dict[str,Any]) –Dictionary containing either: 1. Standard approve parameters:
amount: (optional) Amount to approve
parentSigner: Signer object for parent chain
- OR Custom transaction parameters:
txRequest: Pre-built transaction request
parentSigner: Signer object for parent chain
overrides: (optional) Transaction overrides
- Return type:
- Returns:
Transaction receipt from the approval transaction
- Raises:
ValueError – If the chain uses ETH as its native gas token
MissingProviderArbSdkError – If parentSigner lacks a provider
- get_deposit_request_data(params)[source]¶
Create calldata for depositing ETH or custom gas token.
Constructs the appropriate function call data for depositing either native ETH or a custom gas token, depending on the chain configuration.
- Parameters:
params (
Dict[str,Any]) – Dictionary containing: - amount: Amount to deposit - parentProvider: (optional) Web3 provider for parent chain- Returns:
Encoded function call data for either depositEth() or depositERC20()
- Return type:
bytes
- get_deposit_request(params)[source]¶
Create transaction request for direct token deposit.
Creates a transaction request for depositing ETH or a custom gas token directly into the child chain’s inbox contract. This is used for the simple deposit scenario where tokens are minted to the same address on the child chain.
- Parameters:
params (
Dict[str,Any]) – Dictionary containing: - amount: Amount to deposit - from: Address initiating the deposit - parentProvider: Web3 provider for parent chain- Returns:
txRequest: Transaction parameters (to, value, data, from)
isValid: Function that returns True (simple deposit always valid)
- Return type:
Dictionary containing
- deposit(params)[source]¶
Deposit ETH or custom gas token from parent to child chain.
Executes a deposit transaction that moves ETH or custom gas token from the parent chain to the same address on the child chain. If a transaction request is not provided, one will be built using get_deposit_request().
- Parameters:
params (
Dict[str,Any]) –Dictionary containing either: 1. Standard deposit parameters:
parentSigner: Signer object for parent chain
amount: Amount to deposit
overrides: (optional) Transaction overrides
OR Custom transaction parameters: - txRequest: Pre-built ParentToChildTransactionRequest - parentSigner: Signer object for parent chain - overrides: (optional) Transaction overrides
- Return type:
- Returns:
Transaction receipt from the deposit transaction
- Raises:
MissingProviderArbSdkError – If parentSigner lacks a provider
- get_deposit_to_request(params)[source]¶
Create transaction request for depositing to a different address.
Builds a transaction request for depositing ETH or a custom gas token from the parent chain to a different address on the child chain. This uses a retryable ticket flow under the hood.
- Parameters:
params (
Dict[str,Any]) – Dictionary containing: - parentProvider: Web3 provider for parent chain - childProvider: Web3 provider for child chain - amount: Amount to deposit - destinationAddress: Address to receive the deposit on the child chain- Returns:
txRequest: Transaction parameters (to, value, data, from)
retryableData: Retryable ticket data
- Return type:
Dictionary containing
- deposit_to(params)[source]¶
Deposit ETH or custom gas token to a different address on the child chain.
Executes a deposit transaction that moves ETH or custom gas token from the parent chain to a different address on the child chain. If a transaction request is not provided, one will be built using get_deposit_to_request().
- Parameters:
params (
Dict[str,Any]) –Dictionary containing either: 1. Standard deposit parameters:
parentSigner: Signer object for parent chain
childProvider: Web3 provider for child chain
amount: Amount to deposit
destinationAddress: Address to receive the deposit on the child chain
overrides: (optional) Transaction overrides
OR Custom transaction parameters: - txRequest: Pre-built ParentToChildTransactionRequest - parentSigner: Signer object for parent chain - childProvider: Web3 provider for child chain - overrides: (optional) Transaction overrides
- Return type:
- Returns:
Transaction receipt from the deposit transaction
- Raises:
MissingProviderArbSdkError – If parentSigner lacks a provider
- get_withdrawal_request(params)[source]¶
Create transaction request for withdrawing ETH from the child chain.
Builds a transaction request for withdrawing ETH from the child chain back to the parent chain.
- Parameters:
params (
Dict[str,Any]) – Dictionary containing: - childSigner or childProvider: Signer or provider for child chain - destinationAddress: Address to receive the withdrawal on the parent chain - amount: Amount to withdraw- Returns:
txRequest: Transaction parameters (to, value, data, from)
estimateParentGasLimit: Function to estimate gas limit for parent chain
- Return type:
Dictionary containing
- withdraw(params)[source]¶
Withdraw ETH from the child chain to the parent chain.
Executes a withdrawal transaction that moves ETH from the child chain back to the parent chain. If a transaction request is not provided, one will be built using get_withdrawal_request().
- Parameters:
params (
Dict[str,Any]) –Dictionary containing either: 1. Standard withdrawal parameters:
childSigner: Signer object for child chain
destinationAddress: Address to receive the withdrawal on the parent chain
amount: Amount to withdraw
overrides: (optional) Transaction overrides
OR Custom transaction parameters: - txRequest: Pre-built ChildToParentTransactionRequest - childSigner: Signer object for child chain - overrides: (optional) Transaction overrides
- Return type:
- Returns:
Transaction receipt from the withdrawal transaction
- Raises:
MissingProviderArbSdkError – If childSigner lacks a provider