Credits

Credits are the billing unit for all blockchain API operations. They are only consumed on successful requests.

How Credits Work

Credits are only deducted on success. If a request returns any HTTP error (4xx or 5xx), no credits are consumed. A 402 response means the request was rejected before execution — your balance is untouched.

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:

Endpoint Credit Costs

0 credits — Free Always free, no balance required
EndpointMethodDescription
POST /auth/registerPOSTRegister new account
POST /auth/loginPOSTObtain JWT tokens
POST /auth/logoutPOSTInvalidate session
POST /auth/refreshPOSTRenew access token
POST /auth/verify-emailPOSTVerify email address
POST /auth/forgot-passwordPOSTRequest password reset
POST /auth/reset-passwordPOSTComplete password reset
POST /auth/change-passwordPOSTChange password
GET /auth/meGETGet user profile
PATCH /auth/mePATCHUpdate user profile
DELETE /auth/accountDELETEDelete account
GET /api-keysGETList API keys
POST /api-keysPOSTCreate API key
DELETE /api-keys/{id}DELETERevoke API key
GET /walletsGETList managed wallets
DELETE /wallets/{id}DELETEDelete managed wallet
GET /wallets/{addr}/private-keyGETRetrieve wallet private key (API Key only)
GET /packagesGETList credit packages
GET /packages/{id}GETGet package details
GET /credits/balanceGETGet credit balance
GET /credits/historyGETCredit transaction history
PATCH /credits/alert-thresholdPATCHSet low-credit alert
GET /webhooksGETList webhooks
POST /webhooksPOSTCreate webhook
DELETE /webhooks/{id}DELETEDelete webhook
GET /networksGETList networks
GET /networks/{name}GETGet network details
1 credit Read operations
EndpointMethodDescription
GET /balance/{address}GETNative balance
GET /balance/token/{token}/{user}GETERC-20 token balance
GET /token/{address}GETERC-20 token metadata
GET /token/allowance/{token}/{owner}/{spender}GETToken allowance
GET /gas/priceGETGas prices (slow/standard/fast)
POST /gas/estimatePOSTGas fee estimation
GET /blocks/latestGETLatest block info
GET /blocks/{number}GETBlock by number
GET /prices/native/{network}GETNative currency USD price
GET /prices/{contract}GETToken USD price
POST /prices/batchPOSTBatch token prices
GET /utils/validate/{address}GETAddress validation
GET /utils/ens/resolve/{name}GETENS name → address
GET /utils/ens/lookup/{address}GETAddress → ENS name
2 credits NFT queries, transaction lookups, events
EndpointMethodDescription
GET /nft/info/{contract}/{token_id}GETERC-721 token info & metadata
GET /nft/balance/{contract}/{owner}GETERC-721 balance for owner
GET /nft1155/balance/{contract}/{addr}/{token_id}GETERC-1155 single token balance
POST /nft1155/balance-batch/{contract}/{addr}POSTERC-1155 multi-token balance
GET /nft1155/uri/{contract}/{token_id}GETERC-1155 token URI
POST /transactions/statusPOSTTransaction status check
GET /transactionsGETTransaction history list
GET /transactions/onchain/{tx_hash}GETOn-chain transaction lookup
GET /transactions/{tx_id}GETStored transaction by UUID
GET /events/{contract}GETContract event logs
GET /events/address/{addr}/transfersGETTransfer events for address
5 credits Wallet creation, batch balances, sign tx
EndpointMethodDescription
POST /wallets/createPOSTCreate managed wallet
POST /tx/signPOSTSign raw transaction
POST /balance/batchPOSTNative balance for multiple addresses
POST /balance/token/batchPOSTToken balance for multiple addresses
10 credits Transfers, contract writes, broadcasts
EndpointMethodDescription
POST /transfer/nativePOSTSend native currency (ETH, MATIC, etc.)
POST /transfer/tokenPOSTSend ERC-20 token
POST /tx/broadcastPOSTBroadcast signed transaction
POST /contract/readPOSTCall view/pure contract function
POST /contract/writePOSTExecute state-changing contract function
POST /nft/transferPOSTTransfer ERC-721 token
POST /nft1155/transferPOSTTransfer ERC-1155 token
POST /token/approvePOSTApprove 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.