Module
Prices — 1 credit
Fetch current USD prices for native currencies and ERC-20 tokens. All three methods cost 1 credit, including the batch method — use batch() to price multiple tokens in a single credit.
API Key or JWT
native()
GET
1 credit
Get the current USD price of a network's native currency (e.g. ETH, MATIC, BNB).
Parameters
| Name | Type | Required | Description |
|---|---|---|---|
$network | string | Yes | Network name (e.g. "polygon", "ethereum", "bsc") |
Example
$price = Web3Api::prices()->native(network: 'polygon');
echo $price['symbol']; // "MATIC"
echo $price['price_usd']; // "0.85"
echo $price['updated_at']; // "2024-06-01T12:00:00"
Response
[
'network' => 'polygon',
'symbol' => 'MATIC',
'price_usd' => '0.85',
'updated_at' => '2024-06-01T12:00:00',
]
token()
GET
1 credit
Get the current USD price of an ERC-20 token by its contract address.
Parameters
| Name | Type | Required | Description |
|---|---|---|---|
$contractAddress | string | Yes | ERC-20 token contract address |
$network | ?string | No | Network name. Defaults to WEB3_DEFAULT_NETWORK |
Example
$price = Web3Api::prices()->token(
contractAddress: '0x2791Bca1f2de4661ED88A30C99A7a9449Aa84174', // USDC
network: 'polygon',
);
echo $price['symbol']; // "USDC"
echo $price['price_usd']; // "1.0001"
Response
[
'contract' => '0x2791Bca1f2de4661ED88A30C99A7a9449Aa84174',
'price_usd' => '1.0001',
'symbol' => 'USDC',
]
batch()
POST
1 credit
Get USD prices for multiple ERC-20 token contracts in a single call. Costs only 1 credit regardless of how many contracts you query — very cost-efficient for portfolio dashboards.
Parameters
| Name | Type | Required | Description |
|---|---|---|---|
$contracts | string[] | Yes | Array of ERC-20 contract addresses |
$network | ?string | No | Network name. Defaults to WEB3_DEFAULT_NETWORK |
Example
$prices = Web3Api::prices()->batch(
contracts: [
'0x2791Bca1f2de4661ED88A30C99A7a9449Aa84174', // USDC
'0x7ceB23fD6bC0adD59E62ac25578270cFf1b9f619', // WETH
'0x0d500B1d8E8eF31E21C99d1Db9A6444d3ADf1270', // WMATIC
],
network: 'polygon',
);
// Access prices by contract address
echo $prices['0x2791Bca1f2de4661ED88A30C99A7a9449Aa84174']['price_usd']; // "1.0001"
echo $prices['0x7ceB23fD6bC0adD59E62ac25578270cFf1b9f619']['price_usd']; // "2150.00"
echo $prices['0x7ceB23fD6bC0adD59E62ac25578270cFf1b9f619']['symbol']; // "WETH"
Response
{
"0x2791Bca1f2de4661ED88A30C99A7a9449Aa84174": {
"price_usd": "1.0001",
"symbol": "USDC"
},
"0x7ceB23fD6bC0adD59E62ac25578270cFf1b9f619": {
"price_usd": "2150.00",
"symbol": "WETH"
}
}