javascriptethereumethers.jsalchemyapialchemy

Alchemy API returning error when using parseEther


I am following the docs for "estimateGas" and it instructs me to import "parseEther" from alchemy-sdk. However, when I run the function I get an error stating that "TypeError: (0, _alchemySdk.parseEther) is not a function."

Is this a bug currently or are the docs out of date?

import { Network, Alchemy, Wallet, TokenBalanceType, Utils, fromHex, parseEther } from 'alchemy-sdk';

export const estimateGasFees = async (toAddress, fromAddress, amount) => {
    const estimate = await alchemy.core.estimateGas({
        to: toAddress,
        from: fromAddress,
        value: parseEther(amount),
    });
    return estimate;
}

My "amount" variable is a string ("0.001")


Solution

  • Looks like parseEther is not a function. Based on example here

    const { Alchemy, Network, Wallet, Utils } = require("alchemy-sdk");
    
    value: Utils.parseEther("0.001"),