Fungibles now live Get started

How to add fungible balances to your app

Published on: 9/10/2024

How to add fungible balances to your app

If you're building a consumer-facing crypto app, your users are probably going to care about their token balances in one form or another. Most likely this includes both their native balances (so for example ETH or BTC), and the long-tail of fungible tokens that now exist, across multiple chains and ecosystems.

With the proliferation of both tokens and chains, and different implementations by ecosystem, pulling this all together in a consistent way (and with a consistent response format) can be annoying. Fortunately, using the SimpleHash API, it's easy to query any arbitrary set of wallets for their native balances and fungible tokens, across all the main networks. In this short guide, we're going to cover the most common use cases for querying wallet token balance information.

All of the referenced endpoints are REST-based, making it very easy to integrate into almost any app you might be building, using the request library of your choice - all you need is a SimpleHash API key, which can be obtained via the developer portal.

Getting native balances by wallet

This one is super easy - the Native Token Balances by Wallet(s) endpoint accepts multiple chains and multiple wallet addresses to get back the native token balances, separated out in a convenient array, along with the USD value conversions. Native Tokens are the base / native currency of a given chain - so ETH for most EVM chains, SOL for Solana, and BTC for Bitcoin for example.

Getting fungible balances by wallet

Also very straightforward. Fungibles Balances by Wallet(s) accepts multiple chains and multiple wallet addresses, and returns all of the non-native currency fungible tokens - so think ERC20s on EVM chains, SPLs on Solana, and then Runes for Bitcoin. You can also pass the include_prices param, which returns the live DEX prices for each of the tokens, making it easy to calculate current valuations for a user portfolio.

Getting the details / trades of a specific fungible token

Sometimes (e.g., for a detail view within an app) you may want to show either the metadata for a specific fungible token type, or specific transfers of a given token, for a given wallet. This is also really easy to do using the SimpleHash API - you just need the fungible token identifier, which uniquely identifies the type of fungible token.

SimpleHash uses fungible identifiers using two parts - first the chain name, followed by the relevant contract / address / ID for fungibles on that chain.

  • On EVM chains, pass the chain name, a period, and then the contract address of the ERC20 token (so for example base.0x532f27101965dd16442E59d40670FaF5eBB142E4 for BRETT)
  • On Solana, you'll want the chain name again, a period, and then the mint address (e.g., solana.7GCihgDB8fe6KNjn2MYtkzZcRjQy3t9GHdC8uHYmW2hr for POPCAT) - note if you're grabbing this from somewhere like DEX Screener, you'll want to grab the mint address of the token itself, not the pool it's trading in
  • For Bitcoin Runes, it's a little different - again the chain name, but then the rest of the identifier is made up of the block that the Rune inscription was "etched" in, followed by a colon, followed by the specific transaction index originally containing the Rune (e.g., 840000:3 for DOG•GO•TO•THE•MOON)

Then, you can use either the Get Fungibles & Prices endpoint (for current DEX prices and metadata on a single token type), or the Fungible Sales & Transfers by Wallet(s) endpoint (with the fungible_ids filter set) to get the wallet transfer history for that token.

Lookup a fungible by name

Often you won't necessarily have the exact fungible token identifier, or you may want to implement a search feature for your users. That can be done simply using the Fungible Lookup endpoint - it uses a fuzzy lookup mechanism to return a list of fungible tokens based on known names.

Have other requirements for fungible balances? We'd love to hear from you and discuss what you're building.

Getting NFT data is hard.

SimpleHash makes it easy.

Trusted by hundreds of web3 leaders:

Floor logo
Ledger logo
Brave logo
Rarible logo
Rainbow logo
Phantom logo
Manifold logo
Venly logo
Bitwave logo
Zerion logo
Nansen logo
Dappradar logo
Dust Labs logo
Bitski logo
Mask logo