Another method of getting the gas fee on ETH

in blog •  10 months ago 

I am currently checking different approaches to get the gas fee on ETH, because from 14/Feb/2024, the infrua API has a rate limit of 10 requests per second, and previous methods may be impacted.

image.png

const getGasPrice = async () => {
const body = {
    jsonrpc: "2.0",
    method: "eth_gasPrice",
    params: [],
    id: 1
};

try {
    const response = await fetch(MAIN_ENDPOINT, {
        method: 'POST',
        headers: {
            'Content-Type': 'application/json',
        },
        body: JSON.stringify(body),
    });

    const data = await response.json();
    const wei = parseInt(data.result, 16); // Convert hex to decimal
    const gwei = wei / 1e9; // Convert wei to gwei

    return {
        wei: wei,
        gwei: gwei,
    };
} catch (error) {
    console.error('Error fetching gas price:', error);
    return null;
}

};

See all methods of getting ETH gas fee

From 14/Feb, the Steem2ETH may be impacted, but I'll find out how to resolve this.

image.png

Steem to the Moon🚀!

Authors get paid when people like you upvote their post.
If you enjoyed what you read here, create your account today and start earning FREE BLURT!