PHP WebShell

Текущая директория: /usr/lib/node_modules/bitgo/node_modules/viem/_esm/op-stack/actions

Просмотр файла: initiateWithdrawal.js

import { writeContract, } from '../../actions/wallet/writeContract.js';
import { l2ToL1MessagePasserAbi } from '../abis.js';
import { contracts } from '../contracts.js';
import { estimateInitiateWithdrawalGas, } from './estimateInitiateWithdrawalGas.js';
/**
 * Initiates a [withdrawal](https://community.optimism.io/docs/protocol/withdrawal-flow/#withdrawal-initiating-transaction) on an L2 to the L1.
 *
 * Internally performs a contract write to the [`initiateWithdrawal` function](https://github.com/ethereum-optimism/optimism/blob/283f0aa2e3358ced30ff7cbd4028c0c0c3faa140/packages/contracts-bedrock/src/L2/L2ToL1MessagePasser.sol#L73)
 * on the [Optimism L2ToL1MessagePasser predeploy contract](https://github.com/ethereum-optimism/optimism/blob/283f0aa2e3358ced30ff7cbd4028c0c0c3faa140/packages/contracts-bedrock/src/L2/L2ToL1MessagePasser.sol).
 *
 * - Docs: https://viem.sh/op-stack/actions/initiateWithdrawal
 *
 * @param client - Client to use
 * @param parameters - {@link InitiateWithdrawalParameters}
 * @returns The L2 transaction hash. {@link InitiateWithdrawalReturnType}
 *
 * @example
 * import { createWalletClient, custom, parseEther } from 'viem'
 * import { base, mainnet } from 'viem/chains'
 * import { initiateWithdrawal } from 'viem/op-stack'
 *
 * const client = createWalletClient({
 *   chain: mainnet,
 *   transport: custom(window.ethereum),
 * })
 *
 * const hash = await initiateWithdrawal(client, {
 *   account: '0xA0Cf798816D4b9b9866b5330EEa46a18382f251e',
 *   args: {
 *     gas: 21_000n,
 *     to: '0x70997970c51812dc3a010c7d01b50e0d17dc79c8',
 *     value: parseEther('1'),
 *   },
 * })
 *
 * @example
 * // Account Hoisting
 * import { createWalletClient, http } from 'viem'
 * import { privateKeyToAccount } from 'viem/accounts'
 * import { base, mainnet } from 'viem/chains'
 * import { initiateWithdrawal } from 'viem/op-stack'
 *
 * const client = createWalletClient({
 *   account: privateKeyToAccount('0x…'),
 *   chain: mainnet,
 *   transport: http(),
 * })
 *
 * const hash = await initiateWithdrawal(client, {
 *   request: {
 *     gas: 21_000n,
 *     to: '0x70997970c51812dc3a010c7d01b50e0d17dc79c8',
 *     value: parseEther('1'),
 *   },
 * })
 */
export async function initiateWithdrawal(client, parameters) {
    const { account, chain = client.chain, gas, maxFeePerGas, maxPriorityFeePerGas, nonce, request: { data = '0x', gas: l1Gas, to, value }, } = parameters;
    const gas_ = typeof gas !== 'number' && gas !== null
        ? await estimateInitiateWithdrawalGas(client, parameters)
        : undefined;
    return writeContract(client, {
        account: account,
        abi: l2ToL1MessagePasserAbi,
        address: contracts.l2ToL1MessagePasser.address,
        chain,
        functionName: 'initiateWithdrawal',
        args: [to, l1Gas, data],
        gas: gas_,
        maxFeePerGas,
        maxPriorityFeePerGas,
        nonce,
        value,
    });
}
//# sourceMappingURL=initiateWithdrawal.js.map

Выполнить команду


Для локальной разработки. Не используйте в интернете!