November 2, 2023

Create Chiliz Chain Dapps with Moralis’ Chiliz API 

Table of Contents
Create Chiliz Chain Dapps with Moralis’ Chiliz API

Today’s article will show you how to build on Chiliz with Moralis’ Chiliz API. The API enables you to unlock the full power of Chiliz Chain and create powerful Web3 applications. To give you a little sneak peek, here are three examples of prominent endpoints you might find helpful: 

  • getBlock() – Query the contents of a block based on its block number or hash: 
const response = await Moralis.EvmApi.block.getBlock({
  "chain": "0x15b38",
  "blockNumberOrHash": "2232"
});
  • getNativeBalance() –  Fetch the native balance of a wallet:
const response = await Moralis.EvmApi.balance.getNativeBalance({
  "chain": "0x15b38",
  "address": "0xe0efcc3fb5b1c66257945ebc533c101783fe97b4"
});
  • getWalletNFTs() Get an array of all NFTs owned by a wallet: 
const response = await Moralis.EvmApi.nft.getWalletNFTs({
  "chain": "0x15b38",
  "address": "0xe0efcc3fb5b1c66257945ebc533c101783fe97b4"
});

That’s all you have to do! When working with the Moralis Chiliz API, you only need single API calls to fetch the data you need! 

However, if you want a more detailed breakdown of the above, read on as we explore the ins and outs of the Chiliz API. Additionally, if you want to use the Chiliz API, you need a Moralis account. Fortunately, you can sign up with Moralis entirely for free! By signing up, you’ll gain immediate access to the Chiliz API, so you can start building in no time! 

Overview 

In today’s article, we’ll introduce you to the Moralis Chiliz API and show you how to use this industry-leading tool to fetch blockchain data directly from Chiliz Chain. However, before doing so, we’ll kick things off by exploring the intricacies of Chiliz Chain. From there, we’ll jump straight into the Chiliz API and cover some of this tool’s most prominent features. We’ll then provide a comprehensive tutorial where we show you how to use Moralis to fetch the native balance of any wallet in three steps: 

  1. Get a Moralis API Key
  2. Write a Script Calling the getNativeBalance() Endpoint
  3. Run the Code

Lastly, we’ll explore some prominent Chiliz API use cases to top things off! 

So, if you’re already familiar with Chiliz Chain, feel free to skip to the ”Exploring Moralis’ Chiliz API” section and dive straight into this industry-leading Web3 development tool! 

Moralis Chiliz API Marketing Image

Now, what is Chiliz Chain? Join us below as we start by answering this question!

What is Chiliz Chain? 

Chiliz was founded back in 2018, and it is a blockchain provider focused on the entertainment and sports industry. In 2023, Chiliz launched its most recent iteration of Chiliz Chain – an EVM-compatible layer-1 (L1) blockchain network. And it’s a more interoperable and open successor of the network’s Chiliz Legacy Chain! 

Art image Chiliz Chain API - Build Sports-Related Dapps!

The purpose of Chiliz Chain is to create a strong foundation for a prominent Web3 entertainment and sports ecosystem through fan experiences and B2C/B2B tools. Furthermore, Chiliz aims to become the leading blockchain network for entertainment brands and enterprise-level sports. 

Chiliz Chain operates using a proof-of-stake authority (PoSA) consensus mechanism. The chain features a system of eleven validators, and through the PoSA consensus mechanism, it’s able to deliver lower fees and shorter block finality. 

Let’s also take a closer look at Chiliz in terms of numbers: 

  • 82 Fan Tokens
  • 150+ Global Sports Partners:
    • Manchester City 
    • FC Barcelona
    • And more 
  • 2+ Million Ecosystem Users
  • Market Cap Exceeding $1 Billion 

What’s more, Chiliz Chain’s native token is called CHZ ($CHZ), and it runs on the network in exactly the same way as ETH runs on Ethereum. Consequently, it can be used to pay for gas, perform cross-chain operations, and staking. 

Now, with an overview of Chiliz Chain, let’s explore Socios, another prominent component of the Chiliz ecosystem! 

Socios Explained 

Socios is a website and service providing sports organizations with innovative ways to strengthen relationships with their supporters through fan tokens. But what are fan tokens? Fan tokens are digital assets that can give users exclusive access to experiences, the right to vote in polls, and become part of a global community of fans!

Socios Website Landing Page

Chiliz Chain powers Socios, and it uses the network’s native $CHZ token as its official currency. What’s more, Socios has multiple features, including a marketplace to exchange tokens and Token Hunt – an AR experience where users can find free tokens hidden in their city or neighborhood. 

Socios currently partners with 170+ major sports organizations, including soccer teams for Europe, premium Formula One teams, giants from the NFL, NBA, MLS, the UFC, and many other prominent organizations. 

All in all, Socios is a fan engagement application that gives major sports organizations a venue to build and improve relationships with their supporters and fans! 

Now that you have familiarized yourself with Chiliz Chain and Socios, you will likely want to know how to build on Chiliz. So, if this is the case, join us in the next section as we introduce you to Moralis’ Chiliz API – the easiest way to build on Chiliz!

Exploring Moralis’ Chiliz API 

The easiest way to build on Chiliz Chain is to leverage Moralis’ Chiliz API. The Chiliz API provides everything you need to build and deploy sophisticated Web3 projects, enabling you to effortlessly unlock the full potential of Chiliz Chain! 

Moralis x Chiliz Chain API partnership announcement banner

So, why should you use Moralis to build on Chiliz Chain? 

To answer the query above, let’s look at some prominent features and benefits of the Chiliz API:

  • Instant Setup: Moralis and the Chiliz API offer a hassle-free setup process, allowing you to dive straight into coding. 
  • Real-Time Data: With instant access to real-time data, you can effortlessly keep your users up-to-date. 
  • Speed and Efficiency: Through our easy-to-use tech, you can seamlessly speed up your development processes tenfold. 
  • Scalability: All of Moralis’ APIs are built to scale. Consequently, as your projects grow, you don’t have to worry, as the Chiliz API will have no trouble handling the increased traffic. 
  • Cross-Chain Compatability: Moralis’ cross-chain APIs support all major EVM chains, meaning you can effortlessly bring your dapps beyond the Chiliz ecosystem. 
  • And more! 

Furthermore, the Moralis Chiliz API suite contains a bunch of prominent interfaces that you can use to build everything from NFT-based projects to esports platforms. And in the following sections, we’ll look at three prominent examples! 

NFT API

The Moralis NFT API is the industry’s premier interface for NFT data. It supports more than three million NFT collections across multiple blockchain networks, including Chiliz Chain, Ethereum, Solana, Polygon, Gnosis, and many others. What’s more, it delivers unparalleled performance through lighting-fast CDNs, allowing you to fetch and integrate NFT data into your Web3 projects in a heartbeat!

Chiliz API with NFT-compatability

With only single lines of code, you can effortlessly get all NFT tokens owned by a user address, fetch all NFT transfers by block, query all NFT transfers by contract, and more! 

To highlight the accessibility of this industry-leading interface, let’s briefly explore three endpoints with support for Chiliz Chain:

  • getWalletNFTs() – Get an array of all NFTs owned by the given address: 
const response = await Moralis.EvmApi.nft.getWalletNFTs({
  "chain": "0x15b38",
  "address": "0xe0efcc3fb5b1c66257945ebc533c101783fe97b4"
});
  • getNFTContractTransfers() – Fetch a list of all NFT transfers for the specified contract:
const response = await Moralis.EvmApi.nft.getNFTContractTransfers({
  "chain": "0x15b38",
  "address": "0xe0efcc3fb5b1c66257945ebc533c101783fe97b4"
});
  • getNFTTransfersByBlock() – Query an array of all NFT transfers for a given block: 
const response = await Moralis.EvmApi.nft.getNFTTransfersByBlock({
  "chain": "0x15b38",
  "blockNumberOrHash": "2232"
});

With Moralis’ NFT API, you can also build cross-chain dapps that integrate real-time prices, enriched NFT metadata, optimized image previews, advanced spam detection, ownership data, and much more!

To learn more about this tool’s cross-chain capabilities, check out all featured endpoints at our official NFT API documentation page.

Blockchain API

The Moralis Blockchain API is an industry-leading interface for blockchain data. With this tool, you can effortlessly fetch and integrate block data, contract logs, events, transactions, and much more into your Chiliz Chain projects. As such, when working with the Blockchain API, it has never been easier to build Web3 wallets, create decentralized exchanges, and set up real-time notifications! 

Chiliz Blokchain API art image

To highlight the accessibility of this tool, let’s explore three prominent Chiliz Chain-supported endpoints: 

  • getBlock() – Get the contents of a block by a given hash or block number: 
const response = await Moralis.EvmApi.block.getBlock({
  "chain": "0x15b38",
  "blockNumberOrHash": "2232"
});
  • getContractLogs() – Query the logs of any contract based on its address: 
const response = await Moralis.EvmApi.events.getContractLogs({
  "chain": "0x15b38",
  "topic0": "0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef",
  "address": "0xb47e3cd837dDF8e4c57F05d70Ab865de6e193BBB"
});
  • getContractEvents() – Fetch the events of any contract by address: 
const response = await Moralis.EvmApi.events.getContractEvents({
  "chain": "0x15b38",
  "topic": "0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef",
  "address": "0xd1723eb9e7c6ee7c7e2d421b2758dc0f2166eddc", 
  “abi”:  {
  anonymous: false,
  inputs: [
  {
  indexed: true,
  name: "from",
  type: "address",
  },
  {
  indexed: true,
  name: "to",
  type: "address",
  },
  {
  indexed: false,
  name: "value",
  type: "uint256",
  },
  ],
  name: "Transfer",
  type: "event",
  },
});

The Blockchain API supports multiple networks, including Ethereum, Gnosis, Solana, Polygon, BNB Smart Chain, and many others. As such, with this interface, you can also build cross-chain compatible dapps to reach the largest possible user base. 

Check out the official Blockchain API documentation page to learn more about all cross-chain compatible endpoints and features! 

Wallet API

The Moralis Wallet API is the ultimate tool for building Web3 wallets and integrating wallet functionality into your dapps. Furthermore, it features support for over 500 million addresses across all EVM blockchains, including Chiliz Chain!

Chiliz Wallet API - Build wallet-related apps on Chiliz Chain

With only single API calls, you can get native balance, token balance, transactions, check the activity, and much more for any wallet address on the Chiliz Chain network! 

To highlight the capabilities of the Wallet API, let’s dive into three examples of endpoints that offer support for Chiliz Chain: 

  • getWalletTokenBalances() – Fetch an array of all token balances from any wallet: 
const response = await Moralis.EvmApi.token.getWalletTokenBalances({
  "chain": "0x15b38",
  "address": "0xe0efcc3fb5b1c66257945ebc533c101783fe97b4"
});
  • getNativeBalance() – Query the native balance of any wallet address:
const response = await Moralis.EvmApi.balance.getNativeBalance({
  "chain": "0x15b38",
  "address": "0xe0efcc3fb5b1c66257945ebc533c101783fe97b4"
});
  • getWalletTransactions() – Get a list of any wallet’s native transactions: 
const response = await Moralis.EvmApi.transaction.getWalletTransactions({
  "chain": "0x15b38",
  "address": "0xe0efcc3fb5b1c66257945ebc533c101783fe97b4"
});

With the Wallet API, you can also build cross-chain dapps that integrate NFT wallet transfers, NFT wallet collection data, wallet stats, real-time transaction data, and much more! 

To learn more about this interface’s cross-chain capabilities, please read about all featured endpoints on the Wallet API documentation page. 

Also, the NFT API, Blockchain API, and Wallet API are just three examples of prominent tools in the Chiliz API suite. So, if you want to explore them all, check out our Web3 API page!

Chiliz API Tutorial: How to Get the Native Balance By Wallet in 3 Steps 

In this section, we’ll give you a more in-depth tutorial on how you can get the native balance of any wallet using Moralis’ Chiliz API. And thanks to the accessibility of this Web3 development tool, you can fetch the data you need in three straightforward steps: 

  1. Get a Moralis API Key
  2. Write a Script Calling the getNativeBalance() Endpoint
  3. Run the Code

However, before you can get going with the first step of this tutorial, you need to deal with some prerequisites! 

Prerequisites for Using the Chiliz API

Although Moralis supports multiple programming languages, this is a JavaScript tutorial. As such, make sure you have the following ready before you continue: 

  • Node.js v14+ 
  • NPM/Yarn

Step 1: Get a Moralis API Key 

For you to be able to make calls to the various interfaces of the Chiliz API suite, you need a Moralis API key. As such, if you haven’t already, sign up with Moralis by clicking on the ”Start for Free” button at the top right:

Start Using Chiliz API for Free Button on Moralis Homepage

From there, go to the ”Settings” tab, scroll down to ”API Keys”, and copy your API key: 

Moralis admin panel page with the Copy Chiliz Web3 API button

Keep the key for now, as you need it in the next section! 

Step 2: Write a Script Calling the getNativeBalance() Endpoint 

For the second step, start by setting up a new project folder in your integrated development environment. From there, open a new terminal and run the following command in the root folder to install the Moralis SDK:

npm install moralis @moralisweb3/common-evm-utils

Next, create a file called ”index.js” and add the following code: 

const Moralis = require("moralis").default;
const { EvmChain } = require("@moralisweb3/common-evm-utils");

const runApp = async() => {
  await Moralis.start({
    apiKey: "YOUR_API_KEY",
    // ...and any other configuration
  });

  const address = '0xd8da6bf26964af9d7eed9e03e53415d37aa96045';

  const chain = '0x15b38';

  const response = await Moralis.EvmApi.balance.getNativeBalance({
    address,
    chain,
  });

    console.log(response.toJSON());
}

runApp();

You then need to make some minor modifications. First of all, replace YOUR_API_KEY with the key you copied in the previous step: 

Showing code interface and where to paste the Chiliz API key

Next, make sure that the chain const is set to 0x15b38, and that you configure the address const so you query the right wallet: 

Showing how to change the address and chain parameters to query Chiliz Chain

We then pass along both chain and address when calling the getNativeBalance() endpoint: 

Code block showing how to call the getNativeBalance() endpoint using the Chiliz API

That’s it; you’re now ready to execute the script! 

Step 3: Run the Code 

For the final step, open a new terminal, cd into the project’s root folder and execute the following command: 

node index.js

Running the command above will execute the script. In return, you should get a response looking something like this: 

[
  {
    "balance": "900051407680925"
  }
]

Congratulations! You now know how to use the Chiliz API to get the native balance of any wallet! 

What’s more, if you want to call any of our other endpoints, you can follow precisely the same steps. All you have to do is configure the parameters and the endpoint during the second step! 

Chiliz API Use Cases 

Now that you know how to build dapps on Chiliz Chain with Moralis, let’s explore some prominent use cases:

  • Fan Engagement Platforms: Build fan engagement platforms where fans can participate in contests, polls, and Q&A sessions with their favorite celebrities and athletes. 
  • Ticketing Systems: Develop innovative ticketing systems and applications offering secure, blockchain-based tickets. 
  • Esports Platforms: Build esports platforms with revolutionizing token-based rewards, seamless fan interactions, and real-time data integration. 
  • Fantasy Leagues: Enhance the fantasy sports experience by integrating unique digital assets, real-time stats, and rewards for top players. 
  • AR Games: Create AR games – like Socios’ Token Hunt – combining the digital and physical realms, letting players collect fungible tokens and NFTs.
Art Image - Showin a Dapp built on Chiliz Chain

The five use cases above are only a few examples; the only thing limiting you here is your imagination! 

Summary: Create Chiliz Chain Dapps with Moralis’ Chiliz API 

In today’s article, we introduced you to Moralis’ Chiliz API – the ultimate tool for building dapps on Chiliz Chain. With the Chiliz API, you can seamlessly fetch NFT metadata, token balances, prices, and much more with only single lines of code. As such, when working with Moralis, it has never been easier to build Chiliz Chain projects! 

What’s more, in combination with introducing you to the Chiliz API, we also showed you how to use this industry-leading tool to get the native balance of any wallet in three straightforward steps: 

  1. Get a Moralis API Key
  2. Write a Script Calling the getNativeBalance() Endpoint
  3. Run the Code

As such, if you have followed along this far, you now know how to get data straight from Chiliz Chain! 

If you liked this Chiliz API tutorial, make sure to check out more content here on the Web3 blog. For instance, explore our guide on how to build on Solana and EVM or learn about the industry’s top blockchain API providers.

Also, if you want to leverage the Chiliz API yourself, don’t forget to sign up with Moralis. You can set up your account for free and immediately unlock the full potential of Chiliz Chain! 

Market Data API
Build amazing trading and portfolio dapps with this Market Data API. Keep users engaged with up-to-date data!
Market Data API
Related Articles
December 6, 2022

An Introduction to Web3.Storage – What is it and How Does it Work?

November 4, 2022

Web3 JS Tutorial – A Guide for Blockchain Developers

January 2, 2023

Get Contract Logs – Exploring Web3 Get Event Logs for Ethereum

January 12, 2024

Full List of DEXs – Best Decentralized Crypto Exchanges

January 4, 2024

Starknet Faucet – How to Get Testnet Funds for Starknet

March 9, 2023

xNFT – What is an xNFT (Executable NFT)?

December 14, 2023

Holesky Faucet – How to Get Free Holesky Testnet Funds 

November 11, 2022

The Easiest Way to Create NFTs on Solana

October 13, 2023

Ultimate Guide to getLogs and How to Use the getLogs Method