MCPcopy Create free account
hub / github.com/cardstack/cardstack / usdPrice

Function usdPrice

packages/cardpay-cli/exchange-rate.ts:6–13  ·  view source on GitHub ↗
(network: string, token: string, amount?: string, mnemonic?: string)

Source from the content-addressed store, hash-verified

4const { toWei, fromWei } = Web3.utils;
5
6export async function usdPrice(network: string, token: string, amount?: string, mnemonic?: string): Promise<void> {
7 amount = amount ?? '1';
8 let web3 = await getWeb3(network, mnemonic);
9 let amountInWei = toWei(amount);
10 let exchangeRate = await getSDK('ExchangeRate', web3);
11 let usdPrice = await exchangeRate.getUSDPrice(token, amountInWei);
12 console.log(`USD value: $${usdPrice.toFixed(2)} USD`);
13}
14export async function ethPrice(network: string, token: string, amount?: string, mnemonic?: string): Promise<void> {
15 amount = amount ?? '1';
16 let web3 = await getWeb3(network, mnemonic);

Callers 1

index.tsFile · 0.90

Calls 4

getWeb3Function · 0.90
getSDKFunction · 0.90
getUSDPriceMethod · 0.80
logMethod · 0.45

Tested by

no test coverage detected