For the complete documentation index, see llms.txt. This page is also available as Markdown.

Get Balance

Request

Returns the balance of given account address in the smallest unit.

There are two params

  • Address of wallet

  • latest which gets the latest balance

curl --location --request POST "localhost:9680/rpc" \
--header "Content-Type: application/json" \
--data-raw '{
   "request":{
      "method": "eth_getBalance",
      "params": ["0x638105AA1B69406560f6428aEFACe3DB9da83c64", "latest"]
   },
   "chain":{
      "chainId":"1"
   }
}'
using System.Collections;
using UnityEngine;
using UnityEngine.Networking;

public class GetBalance: MonoBehaviour
{
    void Start()
    {
        StartCoroutine(Balance());
    }

    private IEnumerator Balance()
    {
        string jsonString = "{ \"request\":{ \"method\": \"eth_getBalance\", \"params\": [\"0x638105AA1B69406560f6428aEFACe3DB9da83c64\", \"latest\"] }, \"chain\":{ \"chainId\":\"5\" } }";
        byte[] jsonBytes = System.Text.Encoding.UTF8.GetBytes(jsonString);

        UnityWebRequest request = new UnityWebRequest("localhost:9680/rpc", "POST");
        request.uploadHandler = new UploadHandlerRaw(jsonBytes);
        request.downloadHandler = new DownloadHandlerBuffer();
        request.SetRequestHeader("Content-Type", "application/json");

        yield return request.SendWebRequest();
        Debug.Log(request.error);
        Debug.Log(request.downloadHandler.text);
    }
}

Response

Balance will be in hexadecimal. Once converted to decimal, the unit will be in wei.

For example, hexadecimal 0x236a4c456ef7c0 to base10 is 9968499999832000

Base10 9968499999832000 wei to ETH is 0.009968499999832 ETH

Errors will have an HTTP response status 500-599

Last updated