Prebuilt APIs: Wallet Use Case
Welcome to the Wallet Use Case guide! Here, you'll learn how to leverage ZettaBlock's Prebuilt APIs for various wallet functionalities. 🛠️
The below Prebuilt APIs provide the foundational building blocks for asset management, enabling seamless transactions, balance tracking, and real-time data analytics. With ZettaBlock's real-time GraphQL APIs, you can effortlessly integrate these functionalities, enhancing user experience and operational efficiency. 🌟
Table of Contents
- Get Native Balance of an Address
- Get Token Balance by Address and Contract
- Get All Tokens' Balance and Metadata
- Get Token Metadata and All Holders
1. Get Native Balance of an Address
query {
native_balance(address: "0x0000000000000000000000000000000000000006")
}
Use Case: Retrieve the native balance of a specific blockchain address.
How it Works: This API returns the native balance (in WEI) of the given address. 1 ETH = 10^18 WEI.

2. Get Token Balance by Address and Contract
query {
token_balance(address: "0x0000000000000000000000000000000000000000", contract_address: "0x0000000000085d4780b73119b644ae5ecd22b376")
}
Use Case: Fetch the balance of a specific token for a given address.
How it Works: This API returns the token balance based on the wallet address and the contract address of the token.

3. Get All Tokens' Balance and Metadata
query {
token_balances(
where: {address: {eq: "0xd8da6bf26964af9d7eed9e03e53415d37aa96045"}}
first:20
orderBy: value
orderDirection:desc
) {
value
contract_address
token_metadata {
name
symbol
}
}
}
Use Case: Retrieve all tokens, their balance, and metadata owned by an address.
How it Works: This API lists all tokens owned by an address, sorted by value, and provides metadata like name and symbol. To get the ETH value, multiply the output by the token decimal.

4. Get Token Metadata and All Holders
query token_balances{
token_metadata(contract_address: "0x0000000000004946c0e9f43f4dee607b0ef1fa1c") {
name
symbol
decimals
}
token_balances(
where: {contract_address: {eq: "0x0000000000004946c0e9f43f4dee607b0ef1fa1c"}}
first: 5
orderBy: value
orderDirection:desc
) {
value
contract_address
}
}
Use Case: Get metadata of a token and its top holders.
How it Works: This API provides metadata for a specific token and lists its top holders based on the token value.

That's it! You're now equipped to handle various wallet use cases using ZettaBlock's Prebuilt APIs. 🚀
The Traditional Way: Using RPC Node for Wallet Balance
Getting the balance of an ERC20 token in a wallet using native RPC eth_call requests is doable but cumbersome.
Here's a quick rundown using QuikNode:
What You'll Need:
- Ethereum endpoint
- Terminal
Steps:
- Identify Addresses: You need the wallet address and the ERC20 token contract address.
- Create Data Parameter: Use the Keccak hash of balanceOf(address) and append specific strings to form the data parameter.
- Make the Call: Execute an eth_call to the Ethereum RPC node using curl.
curl https://your-subdomain-here.quiknode.pro/yourtoken/ \
-X POST \
-H "Content-Type: application/json" \
--data '{
"id":67,
"jsonrpc":"2.0",
"method":"eth_call",
"params":[{"data":"0x70a08231000000000000000000000000d8da6bf26964af9d7eed9e03e53415d37aa96045","to":"0x0D8775F648430679A709E98d2b0Cb6250d2887EF"}, "latest"]
}'
- Decode the Response: The value returned is hex-encoded. Decode it to get the actual balance.
Drawbacks:
- Time-consuming
- Requires multiple steps
- Error-prone
Another Traditional Approach: Alchemy's API
- Multiple Steps (TLDR): You need to install SDKs, write extensive scripts, and handle API keys.
- Data Overload: Fetching transaction history for a token contract could mean sifting through millions of records.
- Constant Updates: You'll need to run this process continuously to keep data updated.
- Parameter Management: Requires specifying both the owner and token contract addresses.
- Data Parsing: Additional steps to convert token balance from its smallest unit based on token's decimal value.
Source: link.
Now, compare this with ZettaBlock's Prebuilt APIs. Which one would you prefer? 🤔
Updated 3 months ago