Home > Software engineering >  getting only the results i need in unminable API
getting only the results i need in unminable API

Time:01-04

I wanna use unminable API like this one

 https://api.unminable.com/v4/address/0x9ee9e85cae8299f1f634d2306dbab94c885040a1?coin=SHIB

if u see when u use this URL in the browser the result is

{"success":true,"msg":"Ok","data":{"balance":"812765.88792766","balance_payable":"812765.88792766","precision":"8","payment_threshold":"1500000","mining_fee":"1","auto":false,"enabled":true,"enabled_auto_only":false,"uuid":"85c636dd-0598-46f1-b579-72b4b5c64ae2","fresh":false,"address":"0x9ee9e85cae8299f1f634d2306dbab94c885040a1","network":"ETH","err_flags":{"payment_error":false,"missing_memo":false,"not_activated":false,"restricted":false},"chains":[{"name":"Ethereum","network":"ETH","token_standard":"ERC20","regex":"^(0x)[0-9A-Fa-f]{40}$","regex_memo":null,"is_default":true,"explorer_address":"https://etherscan.io/address/","enabled":true,"enabled_auto_only":false,"payment_threshold":"1500000","compatible":true},{"name":"Binance Smart Chain","network":"BSC","token_standard":"BEP20","regex":"^(0x)[0-9A-Fa-f]{40}$","regex_memo":null,"is_default":false,"explorer_address":"https://bscscan.com/address/","enabled":true,"enabled_auto_only":false,"payment_threshold":"250000","compatible":true},{"name":"Kucoin Community Chain","network":"KCC","token_standard":"KRC20","regex":"^(0x)[0-9A-Fa-f]{40}$","regex_memo":null,"is_default":false,"explorer_address":"https://explorer.kcc.io/en/address/","enabled":true,"enabled_auto_only":false,"payment_threshold":"250000","compatible":true}]}}

but I only want to see the balance

"balance":"812765.88792766"

is there is any method to do that in HTML or Javascript WebPage? Thanks for all

CodePudding user response:

Save the result in an object, then access the data.balance property like this, and then update your html when data is fetched from the api:

Given this html:

<div id="balance"></div>
<button onclick="fetchDataAndUpdateHtml()">Click me</button>

You can fetch the data and update it like this:

function fetchDataAndUpdateHtml() {
    const url = 'https://api.unminable.com/v4/address/0x9ee9e85cae8299f1f634d2306dbab94c885040a1?coin=SHIB';
    fetch(url)
        .then(response => response.json())
        .then((result) => {
            document.getElementById('balance').innerHTML = result.data.balance));
        });

  • Related