description |
---|
Get the balance of an address |
The getBalance
function returns the AR token balance in Winston (smallest possible unit of the AR token) for a given wallet address. The AR token is the native token in the Arweave ecosystem.
The function is called as follows:
import { getBalance } from 'arweavekit/wallet'
const address = await getBalance({params});
The following params are available for this function:
address: string
: The wallet address passed in as typestring
.environment: 'local' | 'mainnet'
(optional) : The environment on which the wallet balance must be fetched.
{% hint style="info" %}
The local
environment is configured to port 1984
and must have an arlocal
instance running on the same port in the background for the function to work successfully. To create one, simply run npx arlocal
in the command line. Learn more about arlocal
here.
{% endhint %}
options
: Additional options can be passed in as a JSON object.
-
winstonToAr: boolean
(optional) : Set this totrue
in order to receive wallet ballance inAr
instead ofWinston
.
{% hint style="info" %} Winston is the smallest possible unit of AR, similar to a satoshi in Bitcoin, or wei in Ethereum.
1 AR = 1000000000000 Winston (12 zeros) and 1 Winston = 0.000000000001 AR. {% endhint %}
Example
const walletBalance = await getBalance({
address: string,
environment: 'local',
});
This returns the AR
token balance of the entered wallet address in Winston
for the chosen environment.
The function call returns the following data:
'100000000000'
walletBalance: string
: Wallet balance inWinston
returned as typestring
when thewinston
parameter is set totrue
.