Skip to content
This repository has been archived by the owner on Jan 5, 2024. It is now read-only.

Commit

Permalink
Add new hook: useBalanceForAddress (#1098)
Browse files Browse the repository at this point in the history
* Add hook: useBalanceForAddress

* Update
  • Loading branch information
kien-ngo authored Nov 27, 2023
1 parent ada8b3c commit 0627d34
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 2 deletions.
2 changes: 1 addition & 1 deletion docs/react/hooks/token/usebalance.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ slug: /react.usebalance
displayed_sidebar: react
---

Hook for getting a wallet's current balance of an ERC20 token, (including native tokens such as Ether).
Hook for getting the connected wallet's current balance of an ERC20 token, (including native tokens such as Ether).

```jsx
import { useBalance } from "@thirdweb-dev/react";
Expand Down
41 changes: 41 additions & 0 deletions docs/react/hooks/token/usebalanceforaddress.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
---
title: useBalanceForAddress
slug: /react.usebalanceforaddress
displayed_sidebar: react
---

This hook is similar to the [useBalance](/react/react.usebalance) hook, however it takes in a mandatory `walletAddress` parameter.
This hook only fetches the native token balance of the given address and does not work with ERC20 tokens. If you want to get the ERC20 balance from a given wallet, use [useTokenBalance](/react/react.usetokenbalance)

```jsx
import { useBalanceForAddress } from "@thirdweb-dev/react";
```

## Usage

Provide the wallet address as the argument.

```jsx
import { useBalanceForAddress } from "@thirdweb-dev/react";

// The EVM wallet address that you want to fetch info from
const walletAddress = "{{wallet_address}}";

function App() {
const { data, isLoading } = useBalanceForAddress(walletAddress);
}
```

## Return Value

The hook's `data` property, once loaded, contains the following properties:

```ts
{
symbol: string;
value: BigNumber;
name: string;
decimals: number;
displayValue: string;
} | undefined>;
```
2 changes: 1 addition & 1 deletion docs/react/hooks/token/usetokenbalance.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import CodeBlock from "@theme/CodeBlock";

Hook for fetching the balance a wallet has for a specific ERC20 token.

_Note: This hook is for **custom** ERC20 tokens. For native tokens such as Ether, use [useBalance](/react/react.usebalance) instead._
_Note: This hook is for **custom** ERC20 tokens. For native tokens such as Ether, use [useBalance](/react/react.usebalance) or [useBalanceForAddress](/react/react.usebalanceforaddress) instead._

Available to use on contracts that implement the [ERC20](/solidity/extensions/erc20) interface.

Expand Down

1 comment on commit 0627d34

@vercel
Copy link

@vercel vercel bot commented on 0627d34 Nov 27, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.