Force Inclusion — Foundry
Force-include a transaction on MegaETH using Foundry (cast or forge) — step-by-step guide for scripted and automated submissions.
Contract addresses
Contract
Chain
Address
Contract
Chain
Address
Step-by-step
1
Set environment variables
export PRIVATE_KEY=0x...
export TOKEN=... # ERC-20 contract address on MegaETH
export RECIPIENT=... # address to receive the tokens
export AMOUNT=... # amount in wei
# Testnet
export PORTAL=0xF68D900e1Cdec64a8f5Dc0Ee873A9E2879256b10
export L1_RPC=https://ethereum-sepolia-rpc.publicnode.com
export L2_RPC=https://carrot.megaeth.com/rpc # see Connect page for all RPC options
# Mainnet
# export PORTAL=0x7f82f57F0Dd546519324392e408b01fcC7D709e8
# export L1_RPC=<your Ethereum mainnet RPC>
# export L2_RPC=https://mainnet.megaeth.com/rpc2
3
4
5
Submit depositTransaction on L1
cast send $PORTAL \
"depositTransaction(address,uint256,uint64,bool,bytes)" \
$TOKEN \
0 \
$GAS_LIMIT \
false \
$CALLDATA \
--value 0 \
--rpc-url $L1_RPC \
--private-key $PRIVATE_KEY// SPDX-License-Identifier: MIT
pragma solidity ^0.8.25;
import {Script} from "forge-std/Script.sol";
interface IOptimismPortal {
function depositTransaction(
address _to, uint256 _value, uint64 _gasLimit,
bool _isCreation, bytes calldata _data
) external payable;
}
contract ForceInclude is Script {
function run() external {
address portal = vm.envAddress("PORTAL");
address token = vm.envAddress("TOKEN");
address recipient = vm.envAddress("RECIPIENT");
uint256 amount = vm.envUint("AMOUNT");
uint64 gasLimit = uint64(vm.envUint("GAS_LIMIT"));
bytes memory data = abi.encodeWithSignature(
"transfer(address,uint256)", recipient, amount
);
vm.startBroadcast();
IOptimismPortal(portal).depositTransaction(
token, 0, gasLimit, false, data
);
vm.stopBroadcast();
}
}How it works
Last updated