Credits
Credits are the billing unit for all blockchain API operations. They are only consumed on successful requests.
How Credits Work
Every response includes these headers so you can track usage in real time:
X-Credits-Used: 1
X-Credits-Balance: 949
X-Request-Id: uuid
The credit system works as follows:
- Each API account has a credit balance.
- Before executing a chargeable request, the API checks your balance.
- If your balance is less than the endpoint's cost, HTTP
402is returned andInsufficientCreditsExceptionis thrown. - On success, the exact credit cost is deducted and reflected in the response headers.
- Free endpoints (0-credit) always execute regardless of balance.
Endpoint Credit Costs
| Endpoint | Method | Description |
|---|---|---|
POST /auth/register | POST | Register new account |
POST /auth/login | POST | Obtain JWT tokens |
POST /auth/logout | POST | Invalidate session |
POST /auth/refresh | POST | Renew access token |
POST /auth/verify-email | POST | Verify email address |
POST /auth/forgot-password | POST | Request password reset |
POST /auth/reset-password | POST | Complete password reset |
POST /auth/change-password | POST | Change password |
GET /auth/me | GET | Get user profile |
PATCH /auth/me | PATCH | Update user profile |
DELETE /auth/account | DELETE | Delete account |
GET /api-keys | GET | List API keys |
POST /api-keys | POST | Create API key |
DELETE /api-keys/{id} | DELETE | Revoke API key |
GET /wallets | GET | List managed wallets |
DELETE /wallets/{id} | DELETE | Delete managed wallet |
GET /wallets/{addr}/private-key | GET | Retrieve wallet private key (API Key only) |
GET /packages | GET | List credit packages |
GET /packages/{id} | GET | Get package details |
GET /credits/balance | GET | Get credit balance |
GET /credits/history | GET | Credit transaction history |
PATCH /credits/alert-threshold | PATCH | Set low-credit alert |
GET /webhooks | GET | List webhooks |
POST /webhooks | POST | Create webhook |
DELETE /webhooks/{id} | DELETE | Delete webhook |
GET /networks | GET | List networks |
GET /networks/{name} | GET | Get network details |
| Endpoint | Method | Description |
|---|---|---|
GET /balance/{address} | GET | Native balance |
GET /balance/token/{token}/{user} | GET | ERC-20 token balance |
GET /token/{address} | GET | ERC-20 token metadata |
GET /token/allowance/{token}/{owner}/{spender} | GET | Token allowance |
GET /gas/price | GET | Gas prices (slow/standard/fast) |
POST /gas/estimate | POST | Gas fee estimation |
GET /blocks/latest | GET | Latest block info |
GET /blocks/{number} | GET | Block by number |
GET /prices/native/{network} | GET | Native currency USD price |
GET /prices/{contract} | GET | Token USD price |
POST /prices/batch | POST | Batch token prices |
GET /utils/validate/{address} | GET | Address validation |
GET /utils/ens/resolve/{name} | GET | ENS name → address |
GET /utils/ens/lookup/{address} | GET | Address → ENS name |
| Endpoint | Method | Description |
|---|---|---|
GET /nft/info/{contract}/{token_id} | GET | ERC-721 token info & metadata |
GET /nft/balance/{contract}/{owner} | GET | ERC-721 balance for owner |
GET /nft1155/balance/{contract}/{addr}/{token_id} | GET | ERC-1155 single token balance |
POST /nft1155/balance-batch/{contract}/{addr} | POST | ERC-1155 multi-token balance |
GET /nft1155/uri/{contract}/{token_id} | GET | ERC-1155 token URI |
POST /transactions/status | POST | Transaction status check |
GET /transactions | GET | Transaction history list |
GET /transactions/onchain/{tx_hash} | GET | On-chain transaction lookup |
GET /transactions/{tx_id} | GET | Stored transaction by UUID |
GET /events/{contract} | GET | Contract event logs |
GET /events/address/{addr}/transfers | GET | Transfer events for address |
| Endpoint | Method | Description |
|---|---|---|
POST /wallets/create | POST | Create managed wallet |
POST /tx/sign | POST | Sign raw transaction |
POST /balance/batch | POST | Native balance for multiple addresses |
POST /balance/token/batch | POST | Token balance for multiple addresses |
| Endpoint | Method | Description |
|---|---|---|
POST /transfer/native | POST | Send native currency (ETH, MATIC, etc.) |
POST /transfer/token | POST | Send ERC-20 token |
POST /tx/broadcast | POST | Broadcast signed transaction |
POST /contract/read | POST | Call view/pure contract function |
POST /contract/write | POST | Execute state-changing contract function |
POST /nft/transfer | POST | Transfer ERC-721 token |
POST /nft1155/transfer | POST | Transfer ERC-1155 token |
POST /token/approve | POST | Approve token allowance |
Handling Insufficient Credits (HTTP 402)
When your account balance is lower than the endpoint's cost, the API returns HTTP 402 before the operation executes. The plugin throws InsufficientCreditsException with parsed $cost and $balance properties:
<?php
use Web3Sdk\Laravel\Facades\Web3Api;
use Web3Sdk\Laravel\Exceptions\InsufficientCreditsException;
try {
$tx = Web3Api::contract()->write(
contractAddress: '0xCONTRACT...',
functionName: 'mint',
args: ['0xUSER...', 1],
abi: $abi,
fromAddress: '0xSENDER...',
privateKey: '0xKEY...',
);
} catch (InsufficientCreditsException $e) {
// $e->cost => 10
// $e->balance => 3
logger()->warning('Insufficient credits', [
'needed' => $e->cost,
'current' => $e->balance,
'deficit' => $e->cost - $e->balance,
]);
// Guide the user to purchase more
$packages = Web3Api::packages()->list();
// Show $packages to user
}
Checking Your Balance
<?php
use Web3Sdk\Laravel\Facades\Web3Api;
$result = Web3Api::credits()->balance();
echo $result['balance']; // 950
echo $result['user_id']; // "uuid..."
You can also view your credit debit/credit history:
<?php
$history = Web3Api::credits()->history(page: 1, limit: 20, type: 'debit');
// Each entry:
// $entry['type'] => "debit"
// $entry['amount'] => -10
// $entry['balance_before'] => 960
// $entry['balance_after'] => 950
// $entry['endpoint'] => "/api/v1/transfer/native"
// $entry['created_at'] => "2024-06-01T12:00:00"
Buying More Credits
Credit packages are available via the Packages module. Use the checkout endpoint to generate a Stripe Checkout URL:
<?php
use Web3Sdk\Laravel\Facades\Web3Api;
// 1. List available packages
$packages = Web3Api::packages()->list();
// [
// ['id' => 'uuid', 'name' => 'Starter', 'credits' => 10000, 'price' => 9.99, 'currency' => 'USD'],
// ['id' => 'uuid', 'name' => 'Pro', 'credits' => 50000, 'price' => 39.99, ...],
// ]
// 2. Get a specific package
$package = Web3Api::packages()->get(packageId: 'uuid-of-package');
// 3. Create Stripe Checkout session (requires JWT auth)
$checkout = Web3Api::packages()->checkout(
packageId: 'uuid-of-package',
successUrl: 'https://myapp.com/credits/success',
cancelUrl: 'https://myapp.com/credits/cancel',
);
// Redirect user to Stripe Checkout
return redirect($checkout['checkout_url']);
// $checkout['session_id'] => "cs_..."
Low-Credit Alerts
Set a threshold to receive a notification when your balance drops below a value:
<?php
// Get notified when balance drops below 100 credits
Web3Api::credits()->setAlertThreshold(threshold: 100);
Buy packages in your provider dashboard. See the Credits module for the balance check API.