Adapter

Ethereum Transaction Fees

Ethereum is the base layer-1 chain.

Sub-Adapters 1

Preview and test each sub adapter.

Ethereum (ethereum)

Metadata

ID
ethereum
icon
category

"l1"

name

"Ethereum"

description

"Ethereum is the base layer-1 chain."

website

"https://ethereum.org"

Queries

Adapter Code

Check the entire code written for the Adapter.

Source code

Showing TS source.
1export const name = 'Ethereum Transaction Fees';
2export const version = '0.2.0';
3export const license = 'MIT';
4
5const SEC_IN_DAY = 86400;
6
7export function setup(sdk: Context) {
8  const getFeeResolverForCost = (gasAmt: number) => async () => {
9    const gasData = await sdk.http.get('https://app.defisaver.com/api/gas-price/current');
10    const ethPrice = await sdk.coinGecko.getCurrentPrice('ethereum');
11    return (gasData.regular * gasAmt * ethPrice) / 1e9;
12  };
13
14  const getAverageSwapFee = async (date: string) => {
15    const dayId = Math.floor(sdk.date.dateToTimestamp(date) / SEC_IN_DAY);
16
17    const query = `{
18      dayStat(id: "${dayId}") {
19        averageCostUSD
20      }
21      nextDay: dayStat(id: "${dayId + 1}") {
22        averageCostUSD
23      }
24    }`;
25
26    const result = await sdk.graph.query('dmihal/ethereum-average-fees', query);
27
28    if (!result.dayStat) {
29      throw new Error('Data unavailable');
30    }
31    if (!result.nextDay) {
32      throw new Error('Day incomplete');
33    }
34    return parseFloat(result.dayStat.averageCostUSD);
35  }
36
37
38  sdk.register({
39    id: 'ethereum',
40    queries: {
41      feeTransferEth: getFeeResolverForCost(21000),
42      feeTransferERC20: getFeeResolverForCost(48000),
43      feeTransferToken: getFeeResolverForCost(48000),
44      feeSwap: getFeeResolverForCost(105000),
45      oneDayAverageFeeSwap: getAverageSwapFee,
46    },
47    metadata: {
48      icon: sdk.ipfs.getDataURILoader('QmedJLPy6R7x3dDEy2cfMd8gXbZm9e3vxvgBLXp3YZEHCy', 'image/svg+xml'),
49      category: 'l1',
50      name: 'Ethereum',
51      description: 'Ethereum is the base layer-1 chain.',
52      website: 'https://ethereum.org',
53    },
54  });
55}
56

It's something off?

Report it to the discussion board on Discord, we will take care of it.

Adapter Info

Version

0.2.0

License

MIT

IPFS CID

QmNwS9n4UGWvhaJmpfdiSE39axXx3bQxbYuaG7SAYdE3x9

CID (source)

QmQ8NoZ53UsJ4YrGNnhUQ4kUM3uLa6ooAHakEAFBWQwVpB

Collections

Author

mihal.eth