Fetch the pool creation fee from the Factory contract.
The following code demonstrates how to accurately the current pool creation fee in HBAR using a combination of JSON RPC and REST API. The pool creation fee is used when creating a new liquidity pool.
The current fee for creating V1 liquidity pools is $50 USD, paid in HBAR. The exchange rate information is used to accurately determine the equivalent value in HBAR.
The pairCreateFee() function will return the current fee expressed in Tinycent (US).
import*as ethers from'ethers'; //V6//Set one of Hedera's JSON RPC Relay as the providerconstprovider=newethers.JsonRpcProvider(hederaJsonRelayUrl,'', { batchMaxCount:1,//workaround for V6});//load ABI data containing Factory's pairCreateFee functionconstinterfaces=newethers.Interface(abi);//get pool creation fee in tinycentconstfactoryContract=newethers.Contract(factoryEvmAddress,interfaces.fragments, provider);constresult=awaitfactoryContract.pairCreateFee();consttinycent=Number(result); //amount in tinycent (US)//get the current exchange rate via REST APIconsturl=`${mirrorNodeBaseUrl}/api/v1/network/exchangerate`;constresponse=awaitaxios.get(url);constcurrentRate=response.data.current_rate;constcentEquivalent=Number(currentRate.cent_equivalent);consthbarEquivalent=Number(currentRate.hbar_equivalent);constcentToHbarRatio= centEquivalent/hbarEquivalent;//calculate the fee in terms of HBARconsttinybar=BigNumber(tinycent / centToHbarRatio).decimalPlaces(0);constpoolCreateFeeInHbar=Hbar.from(tinybar,HbarUnit.Tinybar);console.log(`Pool creation fee: ${poolCreateFeeInHbar.toString(HbarUnit.Hbar)}`);