To use it, you must run a local Hardhat node in one terminal, by running the npx hardhat node command. And then in the second terminal window run your tests or scripts using the --network localhost flag.
import { getEvm2EvmMessage, requestLinkFromTheFaucet, routeMessage } from"@chainlink/local/scripts/CCIPLocalSimulatorFork";// 1st Terminal: npx hardhat node// 2nd Terminal: npx hardhat run ./scripts/myScript.ts --network localhostasyncfunctionmain() {constETHEREUM_SEPOLIA_RPC_URL=process.env.ETHEREUM_SEPOLIA_RPC_URL; // Archive nodeconstARBITRUM_SEPOLIA_RPC_URL=process.env.ARBITRUM_SEPOLIA_RPC_URL; // Archive nodeawaitnetwork.provider.request({ method:"hardhat_reset", params: [ { forking: { jsonRpcUrl:ETHEREUM_SEPOLIA_RPC_URL, blockNumber:5663645, }, }, ], });constlinkAmountForFees=5000000000000000000n; // 5 LINKawaitrequestLinkFromTheFaucet(linkTokenAddressSepolia,awaitCCIPSender_Unsafe.getAddress(), linkAmountForFees); const tx = await CCIPSender_Unsafe.send(CCIPReceiver_Unsafe.target, textToSend, arbSepoliaChainSelector, ccipBnMTokenAddressSepolia, amountToSend);
constreceipt=awaittx.wait();if (!receipt) return;constevm2EvmMessage=getEvm2EvmMessage(receipt);console.log("-------------------------------------------");awaitnetwork.provider.request({ method:"hardhat_reset", params: [ { forking: { jsonRpcUrl:ARBITRUM_SEPOLIA_RPC_URL, blockNumber:33079804, }, }, ], }); // We must redeploy it because of the network reset but it will be deployed to the same address because of the CREATE opcode: address = keccak256(rlp([sender_address,sender_nonce]))[12:]
CCIPReceiver_Unsafe =awaitCCIPReceiver_UnsafeFactory.deploy(ccipRouterAddressArbSepolia);if (!evm2EvmMessage) return;awaitrouteMessage(ccipRouterAddressArbSepolia, evm2EvmMessage);}