near-gas-estimator
v1.0.0
Published
npm Package - near-gas-estimator
Readme
near-gas-estimator
Estimate NEAR Protocol gas costs and convert gas amounts to NEAR tokens.
Installation
npm install near-gas-estimator
Usage
Get Current Gas Price
import { getGasPrice } from 'near-gas-estimator';
const gasPrice = await getGasPrice(); console.log('Gas price (yoctoNEAR):', gasPrice);
Estimate Function Call Gas
import { estimateFunctionCallGas } from 'near-gas-estimator';
const estimate = await estimateFunctionCallGas({ contractId: 'example.near', methodName: 'my_method', args: { key: 'value' }, });
console.log(estimate);
Estimate Transfer Gas
import { estimateTransferGas } from 'near-gas-estimator';
const estimate = await estimateTransferGas('alice.near'); console.log(estimate);
Convert Gas to NEAR
import { gasToNEAR } from 'near-gas-estimator';
const estimate = await gasToNEAR('30000000000000'); console.log(estimate);
API
| Function | Parameters | Returns |
|---|---|---|
| getGasPrice | — | Promise<string> |
| estimateFunctionCallGas | options: FunctionCallGasOptions | Promise<GasEstimate> |
| estimateTransferGas | receiverId: string | Promise<GasEstimate> |
| gasToNEAR | gasAmount: string | Promise<GasEstimate> |
Types
interface FunctionCallGasOptions { contractId: string; methodName: string; args?: Record<string, unknown>; }
interface GasEstimate { gasAmount: string; nearCost: string; }
License
MIT
