Copy
// gets the price of ETH from Coingecko
import 'dotenv/config';
import {
DEPOSIT_AMOUNT_WEI,
ensureEnv,
PRIVATE_KEY,
RPC_URL,
PRICE_CALLER_ADDRESS,
cast,
depositToRitualWallet,
} from './helpers';
function main() {
// 0) Ensure env vars are set
ensureEnv();
// 1) Deposit to RitualWallet
depositToRitualWallet(DEPOSIT_AMOUNT_WEI);
// 2) Fetch latest block number
const latestBlock = cast([`block-number`, `--rpc-url ${RPC_URL}`].join(' '));
console.log('[chain] latest block number:', latestBlock);
// 3) Call getEthPrice(uint64) with latest block number
console.log(`[price] Calling getEthPrice(${latestBlock}) on PriceCaller ...`);
const priceCmd = [
'send',
PRICE_CALLER_ADDRESS,
'"getEthPrice(uint64)"',
String(latestBlock),
'--gas-limit 5000000',
`--rpc-url ${RPC_URL}`,
`--private-key ${PRIVATE_KEY}`,
].join(' ');
const priceOut = cast(priceCmd);
console.log('[price] tx response:', priceOut);
try {
const result = cast(['call', PRICE_CALLER_ADDRESS, '"result()(string)"', `--rpc-url ${RPC_URL}`].join(' '));
console.log('[price] result body:', result);
} catch (_e) {
console.warn('[price] Could not read result() — this is optional.');
}
}
main();