Get Native Balance
Overview
This SDK method allows you to check the native coin balance (e.g., ETH, MATIC) of a smart account.
Method
xellar.accountAbstraction.balance.getNativeBalance({
accountId: string, // The ID of the smart account
});
Parameters
accountId
(required): The ID of the smart account to check.
Example Usage
import { Xellar } from "@xellar/sdk";
const xellar = new Xellar({
appId: "YOUR_APP_ID",
// or
clientSecret: "YOUR_CLIENT_SECRET",
});
try {
const response = await xellar.accountAbstraction.balance.getNativeBalance({
accountId: "68027beb6a1ae347d38563d7",
});
console.log(response);
} catch (error) {
console.error(error);
}
Response
The response will include an object with the following properties:
status
(number): The HTTP status code of the response (e.g., 200 for success).message
(string): A message indicating the result of the operation.data
(object): An object containing the balance information:balance
(string): The raw balance in the smallest unit (wei, gwei, etc.).formattedBalance
(string): The human-readable balance.
Example Response
{
"status": 200,
"message": "success get native balance",
"data": {
"balance": "0",
"formattedBalance": "0"
}
}
ℹ️
The balance is returned in both raw format (in wei) and a human-readable format.
⚠️
Make sure to provide a valid account ID. The request will fail if an invalid or non-existent account ID is provided.