# Bootstrap local Z Chain (chainId 900002) with Hyperledger Besu via Docker. $ErrorActionPreference = "Stop" $Root = (Resolve-Path (Join-Path $PSScriptRoot "..\..")).Path $NetworkDir = if ($env:Z_CHAIN_NETWORK_DIR) { $env:Z_CHAIN_NETWORK_DIR } else { Join-Path $Root "logs\z-chain-network" } $GenesisConfig = Join-Path $Root "config\z-chain-network-config.json" $RpcPort = if ($env:Z_CHAIN_RPC_PORT) { $env:Z_CHAIN_RPC_PORT } else { "8546" } $ContainerName = if ($env:Z_CHAIN_BESU_CONTAINER) { $env:Z_CHAIN_BESU_CONTAINER } else { "z-chain-besu" } try { docker info 2>&1 | Out-Null if ($LASTEXITCODE -ne 0) { throw "Docker daemon not running" } } catch { Write-Error "Docker is installed but not running. Start Docker Desktop or run: scripts\deployment\complete-z-chain.ps1 (Hardhat fallback)" } if (-not (Test-Path $GenesisConfig)) { Write-Error "Missing $GenesisConfig" } New-Item -ItemType Directory -Force -Path $NetworkDir | Out-Null $GenesisOut = Join-Path $NetworkDir "genesis.json" if (-not (Test-Path $GenesisOut)) { Write-Host "Generating IBFT2 network files in $NetworkDir ..." docker run --rm ` -v "${Root}\config:/config:ro" ` -v "${NetworkDir}:/network" ` hyperledger/besu:latest ` operator generate-blockchain-config ` --config-file=/config/z-chain-network-config.json ` --to=/network } $existing = docker ps -a --format "{{.Names}}" 2>$null | Where-Object { $_ -eq $ContainerName } if ($existing) { Write-Host "Removing existing container $ContainerName ..." docker rm -f $ContainerName | Out-Null } $NodeKey = Join-Path $NetworkDir "keys\node1\key" if (-not (Test-Path $NodeKey) -or -not (Test-Path $GenesisOut)) { Write-Error "Generated network files missing under $NetworkDir" } Write-Host "Starting Z Chain Besu on http://127.0.0.1:$RpcPort (chainId 900002) ..." docker run -d ` --name $ContainerName ` -p "${RpcPort}:8545" ` -v "${NetworkDir}:/network:ro" ` hyperledger/besu:latest ` --data-path=/tmp/besu ` --genesis-file=/network/genesis.json ` --node-private-key-file=/network/keys/node1/key ` --rpc-http-enabled ` --rpc-http-api=ETH,NET,WEB3,IBFT,ADMIN,DEBUG ` --rpc-http-host=0.0.0.0 ` --rpc-http-port=8545 ` --rpc-http-cors-origins="*" ` --host-allowlist="*" ` --min-gas-price=0 | Out-Null Write-Host "" Write-Host "Z Chain local RPC: http://127.0.0.1:$RpcPort" Write-Host 'Set env: CHAIN_900002_RPC_URL=http://127.0.0.1:' + $RpcPort Write-Host 'Set env: VITE_RPC_URL_900002=http://127.0.0.1:' + $RpcPort