Module
Token — 1–10 credits
ERC-20 token operations: query token metadata, check allowances, and approve spending. Read operations cost 1 credit; the approve() action costs 10 credits.
API Key or JWT
approve() requires JWT
info()
GET
1 credit
Retrieve ERC-20 token metadata: name, symbol, decimals, and total supply.
Parameters
| Name | Type | Required | Description |
|---|---|---|---|
$contractAddress | string | Yes | ERC-20 token contract address |
$network | ?string | No | Network name. Defaults to WEB3_DEFAULT_NETWORK |
Example
$token = Web3Api::token()->info(
contractAddress: '0x2791Bca1f2de4661ED88A30C99A7a9449Aa84174', // USDC on Polygon
network: 'polygon',
);
echo $token['name']; // "USD Coin"
echo $token['symbol']; // "USDC"
echo $token['decimals']; // 6
echo $token['total_supply']; // "1000000000"
Response
[
'address' => '0x2791Bca1f2de4661ED88A30C99A7a9449Aa84174',
'name' => 'USD Coin',
'symbol' => 'USDC',
'decimals' => 6,
'total_supply' => '1000000000',
]
allowance()
GET
1 credit
Query the spending allowance granted by an owner to a spender contract (e.g., a DEX router). Returns the remaining allowance in token's raw units.
Parameters
| Name | Type | Required | Description |
|---|---|---|---|
$token | string | Yes | ERC-20 token contract address |
$owner | string | Yes | Address that granted the allowance |
$spender | string | Yes | Address that was granted permission to spend |
$network | ?string | No | Network name. Defaults to WEB3_DEFAULT_NETWORK |
Example
// Check if a DEX router can spend USDC on behalf of a user
$result = Web3Api::token()->allowance(
token: '0x2791Bca1f2de4661ED88A30C99A7a9449Aa84174', // USDC
owner: '0xUSER_ADDRESS',
spender: '0xUNISWAP_ROUTER_ADDRESS',
network: 'polygon',
);
echo $result['allowance']; // "1000000" — raw units (divide by 10^6 for USDC)
Response
[
'token' => '0x2791Bca1f2de4661ED88A30C99A7a9449Aa84174',
'owner' => '0xUSER_ADDRESS',
'spender' => '0xUNISWAP_ROUTER_ADDRESS',
'allowance' => '1000000', // raw units
]
approve()
POST
10 credits
JWT
Approve a spender contract to transfer tokens on behalf of the owner. This sends a transaction to the blockchain. Used before DEX swaps, staking, and other DeFi interactions that require token spending approval.
Parameters
| Name | Type | Required | Description |
|---|---|---|---|
$tokenAddress | string | Yes | ERC-20 token contract address |
$ownerAddress | string | Yes | Address granting the approval |
$privateKey | ?string | No | Owner's private key to sign the transaction. Pass null to use the stored managed wallet |
$spenderAddress | string | Yes | Address being granted spending permission |
$amount | string | Yes | Amount to approve in human-readable form (e.g. "1000.0") |
$decimals | int | No | Token decimals (default: 18). USDC = 6 |
$network | ?string | No | Network name. Defaults to WEB3_DEFAULT_NETWORK |
Example — approve DEX router to spend USDC
$tx = Web3Api::token()->approve(
tokenAddress: '0x2791Bca1f2de4661ED88A30C99A7a9449Aa84174', // USDC
ownerAddress: '0xUSER_ADDRESS',
privateKey: '0xUSER_PRIVATE_KEY',
spenderAddress: '0xUNISWAP_ROUTER_ADDRESS',
amount: '1000.0', // approve up to 1000 USDC
decimals: 6,
network: 'polygon',
);
echo $tx['tx_hash']; // "0xabcdef..."
echo $tx['status']; // "pending"
Response
[
'tx_hash' => '0xabcdef1234567890...',
'status' => 'pending',
]