Skip to main content

Gas price manager

Use GasPriceManager to fetch and cache gas estimates and pass them to the Write SDK for faster, predictable transaction building:
import {
  GasPriceManager,
  DecibelWriteDex,
  TESTNET_CONFIG,
} from "@decibeltrade/sdk";
import { Ed25519Account, Ed25519PrivateKey } from "@aptos-labs/ts-sdk";

const gas = new GasPriceManager(TESTNET_CONFIG, {
  multiplier: 2, // default multiplier applied to estimates
  refreshIntervalMs: 60_000, // refresh cadence
});
await gas.initialize();

const account = new Ed25519Account({
  privateKey: new Ed25519PrivateKey(process.env.PRIVATE_KEY!),
});

const write = new DecibelWriteDex(TESTNET_CONFIG, account, {
  nodeApiKey: process.env.APTOS_NODE_API_KEY!, // Required
  gasPriceManager: gas,
});
Stop the manager when your app unmounts:
gas.destroy();

Gas sponsorship

  • By default, transactions are self-pay (the user pays gas in APT).
  • To sponsor gas via Geomi Gas Station, add gasStationApiKey to your config:
const config = { ...TESTNET_CONFIG, gasStationApiKey: process.env.GAS_STATION_API_KEY! };
const write = new DecibelWriteDex(config, account);

Time synchronization

If client clocks are skewed, set timeDeltaMs to shift local time used when building transactions:
const write = new DecibelWriteDex(TESTNET_CONFIG, account, {
  timeDeltaMs: serverDeltaMs,
});
You can compute serverDeltaMs = serverTimeMs - Date.now() using your own time endpoint.