Module
Gas — 1 credit
Query current gas prices and estimate transaction fees before submitting. Both methods cost 1 credit each.
API Key or JWT
price()
GET
1 credit
Get current gas prices in three speed tiers (slow, standard, fast) for a network. All values in Gwei.
Parameters
| Name | Type | Required | Description |
|---|---|---|---|
$network | ?string | No | Network name. Defaults to WEB3_DEFAULT_NETWORK |
Example
$gas = Web3Api::gas()->price(network: 'polygon');
echo $gas['slow']; // "30" — safe/cheap, may be slow
echo $gas['standard']; // "50" — normal confirmation speed
echo $gas['fast']; // "80" — prioritized, faster confirmation
echo $gas['unit']; // "gwei"
Response
[
'network' => 'polygon',
'slow' => '30', // gwei string
'standard' => '50',
'fast' => '80',
'unit' => 'gwei',
]
estimate()
POST
1 credit
Estimate the gas cost for a specific transaction type before submitting it. Returns estimated gas units, gas price, and total fee in native currency.
Parameters
| Name | Type | Required | Description |
|---|---|---|---|
$type | string | Yes | Transaction type: "token_transfer", "native_transfer", "nft_transfer", etc. |
$fromAddress | string | Yes | Sender wallet address |
$toAddress | string | Yes | Recipient wallet address |
$tokenAddress | ?string | No | Token contract address (required for token transfers) |
$amount | ?string | No | Transfer amount (used to simulate the exact call) |
$network | ?string | No | Network name. Defaults to WEB3_DEFAULT_NETWORK |
Example — estimate a token transfer
$estimate = Web3Api::gas()->estimate(
type: 'token_transfer',
fromAddress: '0xSENDER_ADDRESS',
toAddress: '0xRECEIVER_ADDRESS',
tokenAddress: '0x2791Bca1f2de4661ED88A30C99A7a9449Aa84174', // USDC
amount: '10.0',
network: 'polygon',
);
echo $estimate['estimated_gas']; // 65000
echo $estimate['gas_price_gwei']; // "50"
echo $estimate['estimated_fee_matic']; // "0.00325"
Example — estimate a native transfer
$estimate = Web3Api::gas()->estimate(
type: 'native_transfer',
fromAddress: '0xSENDER_ADDRESS',
toAddress: '0xRECEIVER_ADDRESS',
amount: '0.1',
network: 'polygon',
);
Response
[
'estimated_gas' => 65000, // gas units
'gas_price_gwei' => '50', // standard gas price
'estimated_fee_matic' => '0.00325', // total fee in native currency
]