const { JsonRpcProvider, Contract, formatEther, id } = require("ethers");
(async () => {
const p = new JsonRpcProvider("https://mainnet.optimism.io");
const ID_GATEWAY = "0x00000000Fc25870C6eD6b6c7E41Fb078b7656f69";
const STORAGE = "0x00000000fcCe7f938e7aE6D3c335bD6a1a7c593D";
const abiG = ["function price() view returns (uint256)",
"function price(uint256 extraStorage) view returns (uint256)"];
const abiS = ["function unitPrice() view returns (uint256)",
"function price(uint256 units) view returns (uint256)"];
const g = new Contract(ID_GATEWAY, abiG, p);
const s = new Contract(STORAGE, abiS, p);
const out = {};
try { out.idGateway_price_eth = formatEther(await g["price()"]()); } catch(e){ out.idGateway_err = e.shortMessage||e.message; }
try { out.storage_unitPrice_eth = formatEther(await s.unitPrice()); } catch(e){ out.storage_err = e.shortMessage||e.message; }
const fee = await p.getFeeData();
out.opGasPrice_gwei = fee.gasPrice ? Number(fee.gasPrice)/1e9 : null;
out.block = await p.getBlockNumber();
console.log(JSON.stringify(out, null, 2));
})().catch(e=>console.log("FATAL", e.shortMessage||e.message));