Source code

ETH progress bar – PHP/CSS (EtherScan API)

Shortcode Exapmle:

[eth_balance address="ETH WAllet"]

Source Code:

function get_eth_balance($atts) {
    $atts = shortcode_atts(
        array(
            'address' => '', // Ethereum address
            'apikey' => '###APIKEY###' // Your EtherScan API Key
        ), $atts, 'eth_balance'
    );

    $address = $atts['address'];
    $apikey = $atts['apikey'];

    if (empty($address)) {
        return 'Please provide an Ethereum address.';
    }

    $url = "https://api.etherscan.io/api?module=account&action=balance&address=$address&tag=latest&apikey=$apikey";
    $response = wp_remote_get($url);

    if (is_wp_error($response)) {
        return 'Unable to retrieve balance.';
    }

    $body = wp_remote_retrieve_body($response);
    $data = json_decode($body, true);

    if ($data['status'] != '1') {
        return 'Error retrieving balance.';
    }

    $balance_wei = $data['result'];
    $balance_eth = $balance_wei / 1000000000000000000; // Convert Wei to Ether
    $balance_percentage = min(100, ($balance_eth / 20) * 100); // Calculate percentage (capped at 100%)

    ob_start();
    ?>

    <div class="eth-balance-container">
        <div class="eth-balance-bar" style="width: <?php echo $balance_percentage; ?>%;"></div>
    </div>
    <p>ETH Balance: <?php echo number_format($balance_eth, 4); ?> / <?php echo number_format($balance_percentage, 2); ?>%</p>

    <style>
        .eth-balance-container {
            width: 100%;
            background-color: #e0e0e0;
            border-radius: 10px;
            overflow: hidden;
            position: relative;
            height: 25px;
        }
        .eth-balance-bar {
            height: 100%;
            background-color: #1e90ff;
            border-radius: 10px 0 0 10px;
        }
    </style>

    <?php
    return ob_get_clean();
}

add_shortcode('eth_balance', 'get_eth_balance');

Transactions List – PHP (EtherScan API)

Shortcode Example:

[eth_transactions address="ETH Wallet"]

Source code:

function get_eth_transactions($atts) {
    $atts = shortcode_atts(
        array(
            'address' => '', // Ethereum address
            'apikey' => '###APIKEY###' // Your EtherScan API Key
        ), $atts, 'eth_transactions'
    );

    $address = $atts['address'];
    $apikey = $atts['apikey'];

    if (empty($address)) {
        return 'Please provide an Ethereum address.';
    }

    $url = "https://api.etherscan.io/api?module=account&action=txlist&address=$address&startblock=0&endblock=99999999&sort=asc&apikey=$apikey";
    $response = wp_remote_get($url);

    if (is_wp_error($response)) {
        return 'Unable to retrieve transactions.';
    }

    $body = wp_remote_retrieve_body($response);
    $data = json_decode($body, true);

    if ($data['status'] != '1') {
        return 'Error retrieving transactions.';
    }

    $transactions = $data['result'];
    ob_start();

    echo '<div class="eth-transactions">';
    foreach ($transactions as $tx) {
        $from = $tx['from'];
        $to = $tx['to'];
        $value = $tx['value'] / 1000000000000000000; // Convert Wei to Ether
        $date = date('Y-m-d H:i:s', $tx['timeStamp']);
        $color = 'grey';

        if ($tx['to'] === strtolower($address)) {
            if ($value >= 0.02) {
                $color = 'green';
            } elseif ($value >= 0.002) {
                $color = 'blue';
            }
        } else {
            $color = 'red';
        }

        echo "<p style='color: $color;'>From: $from, To: $to, Date: $date, Value: " . number_format($value, 4) . " ETH</p>";
    }
    echo '</div>';

    return ob_get_clean();
}

add_shortcode('eth_transactions', 'get_eth_transactions');

An example for use in WordPress, for convenience, you can use Code Snippets. The Etherscan API can be obtained for free after registration, in your personal account in the API section.

Scroll to Top