Here for the API?Start building with us today

Learn about DeCommas API
Tutorial: Implementing Balances features using DeCommas Mission Control API with Linea Support
November 16, 2023

Tutorial: Implementing Balances features using DeCommas Mission Control API with Linea Support

Whether it is a digital wallet, dex, or portfolio dashboard, there is a common denominator among these platforms — the balances feature. The question now is, what do balances mean? Balances in the crypto world refer to the amount of a particular asset or token an individual or token holder owns in their digital wallet, DEXes, or Portfolio Dashboards. Each of these platforms offers unique definitions of balances based on their primary function. For instance, while a wallet focuses on individual asset holdings as balances, a DEX might display balances relevant to trading pairs, and a portfolio dashboard might define it as the total asset value expressed in dollar amount.

Now, considering the different platforms and applications in the crypto ecosystem, how does one ensure that these balances are accurately fetched, updated in real-time, and presented in a user-friendly manner? The DeCommas API emerges as the solution — this powerful tool is the optimal solution for developers aiming to integrate balance features into their applications. In essence, for anyone looking to build or enhance balance features, whether in Wallets, DEXes, or Portfolio dashboards, the DeCommas API is the go-to choice due to its speed, detailed endpoints, and developers’ support.

This tutorial will walk you through how to implement the balances features using Decommas API and the role Linea plays in this process.

What Is Linea?

Linea stands out as a layer-two (L2) blockchain solution built by ConsenSys to augment the capabilities of Ethereum. What sets Linea apart is its use of zero-knowledge (ZK) proofs — a revolutionary approach to ensuring that every transaction is secure and blazingly fast.

Linea is compatible with Ethereum’s Virtual Machine. Thus, developers can transition and deploy their applications quickly. Linea provides faster transactions and reduced gas fees for defi platforms, NFT marketplaces, and other Web3 platforms. Linea was publicly launched on July 11, 2023, and Decommas started supporting it in September 2023.

How To Access Linea Using Decommas API

Accessing Linea data via the DeCommas API is straightforward. For instance, to retrieve data related to Vitalik’s wallet address, one can use the following endpoint:

https://datalayer.decommas.net/datalayer/api/v1/tokens/0xd8dA6BF26964aF9D7eEd9e03E53415D37aA96045?networks=linea&verified=false

It’s worth noting that for any request where the network parameter is relevant, appending networks=linea will filter the data to show only Linea-related information.

How do Balances features work?

Let’s break down how these balances function within various features

Accessing Balances Data

  1. Balances in Wallets

For Wallet applications like OKX Wallet, Metamask, and FoxWallet, DeCommas provides developers with the capability to retrieve balance data effortlessly. Through the Mission Control API, you can integrate endpoints related to ERC-20 Tokens, ERC-20 Tokens Metadata, NFTs, NFT Metadata, and Coins. By utilizing these endpoints, you gain access to detailed information about the user’s wallet, including token balances, token metadata, NFT holdings, and general coin balances.

# Sample API request to retrieve ERC-20 token balances in a user's wallet
GET https://datalayer.decommas.net/datalayer/api/v1/balances?wallet=METAMASK_ADDRESS

Wallet:

  • Utilize the getCoins and getTokens methods from the address namespace to retrieve native coin balances and ERC-20 token balances for a specific address.
  • Example:
const coins = await decommas.address.getCoins({ address });
const tokens = await decommas.address.getTokens({ address });
  1. Balances in DEXes

When it comes to decentralized exchanges (DEXes), DeCommas Mission Control API offers seamless integration with endpoints tailored for DEX-related features. Developers can access information about token balances, trade history, and liquidity pool holdings. This ensures that DEX platforms can provide users with a comprehensive view of their assets and transactions.

# Sample API request to retrieve trade history on a DEX
GET https://datalayer.decommas.net/datalayer/api/v1/trade-history?dex=UNISWAP&pair=ETH/USDT

DEXes:

  • Access DeCommas’ getErc20Transfers method to retrieve ERC-20 token transfer information, providing insights into trades on decentralized exchanges.
  • Example:
const erc20Transfers = await decommas.address.getErc20Transfers({ address });
  1. Balances in Portfolio Dashboards

Portfolio dashboards, such as Social Scan, can benefit from DeCommas Mission Control API to gather data on users’ holdings and activities across multiple platforms. By utilizing endpoints for ERC-20 Tokens, NFTs, and Coins, developers can aggregate information for a holistic portfolio overview.

# Sample API request to retrieve NFT holdings for a user on Social Scan
GET https://datalayer.decommas.net/datalayer/api/v1/nft-holdings?portfolio=SOCIAL_SCAN_USER_ID

Portfolio Dashboards:

  • For Portfolio dashboards, leverage the getNfts method to obtain NFT balances and metadata, creating a comprehensive overview of a user’s non-fungible assets.
  • Example:
const nfts = await decommas.address.getNfts({ address });

Utilizing DeCommas using Linea

# Any request where networks parameter is applicable can filter linea-only data by adding networks=linea to such request.
GET https://datalayer.decommas.net/datalayer/api/v1/tokens/your_address_here?networks=linea&verified=false
  1. Accessing Data in Wallets via Linea:
  • Integrate DeCommas API to access wallet data for wallets like OKX, Metamask, and FoxWallet.
  • Utilize the Linea platform to seamlessly access and display this wallet data within your application.

Example:

// DeCommas API request for Metamask wallet data
const metamaskData = await decommas.address.getTokens({ address: 'METAMASK_ADDRESS' });
// Access the same data via Linea for integration in your application
const lineaMetamaskData = await linea.integrate(metamaskData);
  1. Accessing Data in Portfolio Dashboards via Linea:
  • Extend the integration to Portfolio dashboards like Social Scan.
  • Fetch relevant data using DeCommas API and seamlessly present it on the Linea platform.

Example:

// DeCommas API request for Social Scan portfolio data
const socialScanData = await decommas.address.getNfts({ address: 'SOCIAL_SCAN_USER_ID' });
// Integrate the data into Linea for a unified user experience
const lineaSocialScanData = await linea.integrate(socialScanData);

Tutorial: An Overview of How to Build Balances for Your Features Using DeCommas API

Are you looking for a roadmap to building balances features using the Decommas API and Linea? If yes, this tutorial is for you as it will guide you through the processes, ensuring you grasp every concept. We will also recap how to get your personal mission control API key and set it up. Specifically, we will examine the following topics:

  1. Get Your Personal Mission Control API Key
  2. Setting Up Mission Control API in Your Development Environment
  3. Building Balances feature

Get Your Personal Mission Control API Key

If you recall in our previous tutorials, you need access to the Decommas Mission Control API to get your personal mission control API key. Fortunately, it’s often free to use with consistently low response times of 150 milliseconds. However, you can obtain your API key by following these steps:

Step 1: Visit https://build.decommas.io/

Step 2: Click “Get Started”

Step 3: Provide your email address for verification

Step 4: Check your email for the verification link, and click it to access with URL https://dashboard.decommas.io/ , your gateway to API keys.

Ensure your API keys are stored using high-level security and readily accessible for future use. Furthermore, you can consult our documentation here for further research.

Setting Up the Mission Control API in your Development Environment

Whether you’re keen on making raw HTTPS requests or prefer the convenience of the JavaScript SDK, DeCommas offers both options. This section walks you through both options but concentrates mainly on the JavaScript SDK. Here are the steps to get started:

Step 1: Installation

To start, install the DeCommas API SDK:

npm install @decommas/sdk

Step 2: SDK Initialization

Post-installation, import the SDK. For development-only mode, you can initialize it without an API key:

import { Decommas } from '@decommas/sdk';
const decommas = new Decommas();
const getVitalikERC20Balances = async () => {
const address = '0xd8dA6BF26964aF9D7eEd9e03E53415D37aA96045'; // Replace with any address
const tokens = await decommas.address.getTokens({ address });
console.log(tokens);
};

Step 3: Using an API Key

For full access to the DeCommas API features, sign up on the DeCommas dashboard to obtain your API key:

import { Decommas } from '@decommas/sdk';
const API_KEY = "YOUR_API_KEY";
const decommas = new Decommas(API_KEY);

Replace YOUR_API_KEY with the desired API KEY

Raw HTTPS Requests

For those who opt for raw HTTPS requests:

https://datalayer.decommas.net/datalayer/api/v1/token_holders/{chain_name}/{contract_address}?api-key={YOUR-API-KEY}

Replace CONTRACT_ADDRESS with the contract address of the token.

How to Build Balances feature

This section explores how to harness the different endpoints to create a top-tier Balances feature and also why these endpoints matter in the first place.

ERC-20 Tokens:

What it does: Fetches the balances of Ethereum-based tokens.

GET https://datalayer.decommas.net/datalayer/api/v1/tokens/{address}?api-key={YOUR-API-KEY}

GET Params:

  • api-key:

Your api key

  • networks:

Default; networks=all. You can pass one or more networks in one request (?networks=linea,optimism,arbitrum)

  • verified:

Default; verified=false. If true, returns only verified tokens. False returns all tokens.

  • limit:

Parameter for pagination (default 20, min 20, max 100)

  • offset:

parameter for pagination (default 0)

Example Use: The following example illustrates the use with Linea

https://datalayer.decommas.net/datalayer/api/v1/tokens/{address}?networks=linea&api-key={YOUR-API-KEY}

Response Example (All Fields are Mandatory)

{
  "count": 2,
  "status": 200,
  "result": [
    {
      "chain_name": "mainnet",
      "chain_id": 1,
      "address": "0x228ba514309ffdf03a81a205a6d040e429d6e80c",
      "name": "Global Social Chain",
      "decimals": 18,
      "symbol": "GSC",
      "logo_url": "https://assets.coingecko.com/coins/images/4304/large/global-social-chain.png?1547742843",
      "actual_price": "0.00147295",
      "is_verified": true,
      "is_stable": false,
      "amount": "20000000000000000000"
    },
    {
      "chain_name": "mainnet",
      "chain_id": 1,
      "address": "0x38e4adb44ef08f22f5b5b76a8f0c2d0dcbe7dca1",
      "name": "Concentrated Voting Power",
      "decimals": 18,
      "symbol": "CVP",
      "logo_url": "https://assets.coingecko.com/coins/images/12266/large/Powerpool.jpg?1598621373",
      "actual_price": "0.433299",
      "is_verified": true,
      "is_stable": false,
      "amount": "42130000000000000000"
    }
  ]
}

ERC-20 Tokens Metadata:

What it does: Retrieves metadata (information) about Ethereum-based tokens.

GET https://datalayer.decommas.net/datalayer/api/v1/token_metadata/{chain_name}/{token_address}?api-key={YOUR-API-KEY}

GET Params:

  • api-key:

Your api key

Response Example (All Fields are Mandatory)

{
  "status": 200,
  "result": {
    "chain_name": "mainnet",
    "chain_id": 1,
    "address": "0xdac17f958d2ee523a2206206994597c13d831ec7",
    "name": "Tether USD",
    "decimals": 6,
    "symbol": "USDT",
    "logo_url": "https://assets.coingecko.com/coins/images/325/large/Tether.png?1668148663",
    "actual_price": "1.002",
    "is_verified": true,
    "is_stable": true,
    "is_protocol_token": false,
        "total_supply": "string"
  }
}

NFTs:

What it does: Gets the balances of a user’s NFTs on various networks.

GET https://datalayer.decommas.net/datalayer/api/v1/nfts/{address}?api-key={YOUR-API-KEY}

GET Params:

  • api-key:

Your api key

  • networks:

Default; networks=all. You can pass one or more networks in one request (?networks=linea,optimism,arbitrum)

  • verified:

Default; verified=false. If true, returns only verified collections. False returns all collections.

  • limit:

Parameter for pagination (default 20, min 20, max 100)

  • offset:

parameter for pagination (default 0)

Response Example (All Fields are Mandatory)

{
  "count": 2,
  "status": 200,
  "result": [
    {
      "chain_name": "mainnet",
      "chain_id": 1,
      "contract_address": "0x011c77fa577c500deedad364b8af9e8540b808c0",
      "token_id": "10868",
      "amount": 1,
      "contract_type": "ERC-1155",
            "collection_verified": true
    },
    {
      "chain_name": "mainnet",
      "chain_id": 1,
      "contract_address": "0x011c77fa577c500deedad364b8af9e8540b808c0",
      "token_id": "11207",
      "amount": 1,
      "contract_type": "ERC-1155",
            "collection_verified": true
    }
  ]
}

NFT Metadata:

What it does: Returns NFT metadata by network name, contract address, and token id.

GET https://datalayer.decommas.net/datalayer/api/v1/nft_metadata/{chain_name}/{contract_address}/{token_id}?api-key={YOUR-API-KEY}

GET Params:

  • api-key:

Your api key

Response Example (All Fields are Mandatory)

{
  "status": 200,
  "result": {
    "chain_name": "mainnet",
    "chain_id": 1,
    "contract_address": "0x8bc9224253e37cd221c7f510acc42cb6e734db57",
    "token_id": "3366",
    "name": "Hasbulla #3366",
    "image_url": "https://i.seadn.io/gcs/files/cebadb7049b1d2e645eb9be5bc4294cb.png?w=500&auto=format",
    "animation_url": null,
    "contract_type": "ERC-721",
    "collection_name": "Hasbulla NFT",
    "collection_verified": true
  }
}

Coins:

What it does: Gets balances of native coins across different blockchains.

https://datalayer.decommas.net/datalayer/api/v1/coins/{address}?api-key={YOUR-API-KEY}

GET Params:

  • api-key:

Your api key

  • networks:

Default; networks=all. You can pass one or more networks in one request (?networks=linea,optimism,arbitrum)

Response Example (All Fields are Mandatory)

{
  "count": 2,
  "status": 200,
  "result": [
    {
      "chain_name": "mainnet",
      "chain_id": 1,
      "name": "ethereum",
      "symbol": "ETH",
      "logo_url": "https://assets.coingecko.com/coins/images/279/large/ethereum.png?1595348880",
      "decimals": 18,
      "amount": "2631431841986023403",
      "actual_price": "1800"
    },
    {
      "chain_name": "optimism",
      "chain_id": 10,
      "name": "ethereum",
      "symbol": "ETH",
      "logo_url": "https://assets.coingecko.com/coins/images/279/large/ethereum.png?1595348880",
      "decimals": 18,
      "amount": "26074769918530822",
      "actual_price": "1800"
    }
  ]
}

Why These Endpoints Matter

  1. Comprehensive Balances: By utilizing DeCommas endpoints, developers can offer users a complete and detailed overview of their crypto holdings, covering both fungible and non-fungible assets.
  2. Enhanced User Experience: Metadata endpoints enrich the user experience by providing additional details about tokens and NFTs, making the application more informative and engaging.
  3. Multi-Blockchain Support: DeCommas endpoints support a variety of blockchains, including Ethereum, Binance Smart Chain, Linea, and more. This ensures users can manage their balances seamlessly across different networks.

Supported chains (mainnet only):

  1. Ethereum Mainnet
  2. Polygon
  3. Optimism
  4. Arbitrum
  5. Arbitrum Nova
  6. Binance Smart Chain (BSC)
  7. Avalanche
  8. Fantom
  9. Gnosis
  10. Base
  11. opBNB
  12. Polygon zkEVM
  13. Linea

Wrapping up — Your first steps to building the Balances feature

And there you go! We’ve walked through the definitions of the balances feature, dived deep into the technical jargon of DeCommas Mission Control API, and ended our exploration on how to build a shiny balances feature.

While we’ve laid out the bricks, you can still build a lot more on this foundation. Crypto space is a vast playground, and with tools like DeCommas at your disposal, there’s much to explore and create. Got questions or hit a rocky road? Feel free to hit up the support at [email protected].

Happy building!