Granite Upgrade Activates in06d:02h:04m:16s
MethodsPublic Methods

Public Methods

Complete reference for Avalanche-specific public client methods

Overview

The Avalanche Client extends viem's Public Client with Avalanche-specific methods for querying fee information, chain configuration, and active rules. These methods are available on both the main Avalanche Client and the C-Chain client.

Fee Operations

baseFee

Get the base fee for the next block on the C-Chain.

Function Signature:

function baseFee(): Promise<string>;

Parameters:

No parameters required.

Returns:

TypeDescription
stringBase fee for the next block as hex string (e.g., "0x3b9aca00")

Example:

import { createAvalancheClient } from "@avalanche-sdk/client";
import { avalanche } from "@avalanche-sdk/client/chains";

const client = createAvalancheClient({
  chain: avalanche,
  transport: { type: "http" },
});

const baseFee = await client.baseFee();
console.log("Base fee:", baseFee); // "0x3b9aca00"

Related:


maxPriorityFeePerGas

Get the maximum priority fee per gas for the next block.

Function Signature:

function maxPriorityFeePerGas(): Promise<string>;

Parameters:

No parameters required.

Returns:

TypeDescription
stringMaximum priority fee per gas as hex string (e.g., "0x3b9aca00")

Example:

const maxPriorityFee = await client.maxPriorityFeePerGas();
console.log("Max priority fee per gas:", maxPriorityFee);

// Use in EIP-1559 transaction
const txHash = await walletClient.sendTransaction({
  to: "0x...",
  value: avaxToWei(1),
  maxFeePerGas: baseFee + maxPriorityFee,
  maxPriorityFeePerGas: maxPriorityFee,
});

Related:


feeConfig

Get the fee configuration for a specific block. Returns fee settings and when they were last changed.

Function Signature:

function feeConfig(params: FeeConfigParameters): Promise<FeeConfigReturnType>;

interface FeeConfigParameters {
  blk?: string; // Block number or hash, defaults to "latest"
}

interface FeeConfigReturnType {
  feeConfig: {
    [key: string]: string;
  };
  lastChangedAt: string;
}

Parameters:

NameTypeRequiredDescription
blkstringNoBlock number or hash (hex string), defaults to "latest"

Returns:

TypeDescription
FeeConfigReturnTypeFee configuration object

Return Object:

PropertyTypeDescription
feeConfigobjectFee configuration key-value pairs
lastChangedAtstringTimestamp when fee config was last changed

Example:

// Get fee config for latest block
const feeConfig = await client.feeConfig({});
console.log("Fee config:", feeConfig.feeConfig);
console.log("Last changed:", feeConfig.lastChangedAt);

// Get fee config for specific block
const blockFeeConfig = await client.feeConfig({ blk: "0x123456" });

Related:


Chain Configuration

getChainConfig

Get the chain configuration for the C-Chain, including fork blocks and Avalanche-specific upgrade timestamps.

Function Signature:

function getChainConfig(): Promise<GetChainConfigReturnType>;

interface GetChainConfigReturnType {
  chainId: number;
  homesteadBlock: number;
  daoForkBlock: number;
  daoForkSupport: boolean;
  eip150Block: number;
  eip150Hash: string;
  eip155Block: number;
  eip158Block: number;
  byzantiumBlock: number;
  constantinopleBlock: number;
  petersburgBlock: number;
  istanbulBlock: number;
  muirGlacierBlock: number;
  apricotPhase1BlockTimestamp: number;
  apricotPhase2BlockTimestamp: number;
  apricotPhase3BlockTimestamp: number;
  apricotPhase4BlockTimestamp: number;
  apricotPhase5BlockTimestamp: number;
}

Parameters:

No parameters required.

Returns:

TypeDescription
GetChainConfigReturnTypeChain configuration object

Return Object:

PropertyTypeDescription
chainIdnumberChain ID
homesteadBlocknumberHomestead fork block
daoForkBlocknumberDAO fork block
daoForkSupportbooleanDAO fork support flag
eip150BlocknumberEIP-150 fork block
eip150HashstringEIP-150 fork hash
eip155BlocknumberEIP-155 fork block
eip158BlocknumberEIP-158 fork block
byzantiumBlocknumberByzantium fork block
constantinopleBlocknumberConstantinople fork block
petersburgBlocknumberPetersburg fork block
istanbulBlocknumberIstanbul fork block
muirGlacierBlocknumberMuir Glacier fork block
apricotPhase1BlockTimestampnumberApricot Phase 1 upgrade timestamp
apricotPhase2BlockTimestampnumberApricot Phase 2 upgrade timestamp
apricotPhase3BlockTimestampnumberApricot Phase 3 upgrade timestamp
apricotPhase4BlockTimestampnumberApricot Phase 4 upgrade timestamp
apricotPhase5BlockTimestampnumberApricot Phase 5 upgrade timestamp

Example:

const chainConfig = await client.getChainConfig();
console.log("Chain ID:", chainConfig.chainId);
console.log("Apricot Phase 1:", chainConfig.apricotPhase1BlockTimestamp);

Related:


Active Rules

getActiveRulesAt

Get the active rules (EIPs, precompiles) at a specific timestamp. Useful for determining which features are enabled at a given time.

Function Signature:

function getActiveRulesAt(
  params: GetActiveRulesAtParameters
): Promise<GetActiveRulesAtReturnType>;

interface GetActiveRulesAtParameters {
  timestamp: string; // Unix timestamp as hex string or "latest"
}

interface GetActiveRulesAtReturnType {
  ethRules: Map<string, true>;
  avalancheRules: Map<string, true>;
  precompiles: Map<string, object>;
}

Parameters:

NameTypeRequiredDescription
timestampstringYesUnix timestamp as hex string (e.g., "0x1234567890") or "latest"

Returns:

TypeDescription
GetActiveRulesAtReturnTypeActive rules object

Return Object:

PropertyTypeDescription
ethRulesMap<string, true>Active Ethereum rules (EIPs)
avalancheRulesMap<string, true>Active Avalanche-specific rules
precompilesMap<string, object>Active precompiles with their configurations

Example:

// Get active rules at current time
const activeRules = await client.getActiveRulesAt({
  timestamp: "latest",
});

console.log("Ethereum rules:", Array.from(activeRules.ethRules.keys()));
console.log("Avalanche rules:", Array.from(activeRules.avalancheRules.keys()));
console.log("Precompiles:", Array.from(activeRules.precompiles.keys()));

// Get active rules at specific timestamp
const historicalRules = await client.getActiveRulesAt({
  timestamp: "0x1234567890",
});

Related:


Viem Integration

The Avalanche Client extends viem's Public Client, providing access to all standard Ethereum RPC methods. For complete method reference, see:

Next Steps

Is this guide helpful?