Do you want to create Gnosis Chain dapps using a free Gnosis API? If so, you’ve come to the right place! In today’s article, we’ll introduce you to Moralis’ Gnosis API – the ultimate tool for building decentralized applications (dapps) on Gnosis Chain. The Gnosis API features many prominent endpoints you can use to fetch everything from token prices to wallet balances with only single lines of code. If you’re eager to know exactly how this works, here are three Gnosis API endpoint examples:
getWalletTokenBalances()
– Get an array of all token balances of any wallet:
const response = await Moralis.EvmApi.token.getWalletTokenBalances({ "chain": "0x64", "address": "0x88ad09518695c6c3712ac10a214be5109a655671" });
getBlock()
– Fetch data for any block:
const response = await Moralis.EvmApi.block.getBlock({ "chain": "0x64", "blockNumberOrHash": "23233" });
getWalletNFTs()
– Query an array of all NFTs owned by a wallet:
const response = await Moralis.EvmApi.nft.getWalletNFTs({ "chain": "0x64", "address": "0x88ad09518695c6c3712ac10a214be5109a655671" });
If you’re looking for a more detailed breakdown of how you can leverage the Gnosis API to build dapps, join us in this article as we cover the ins and outs of this industry-leading interface!
Also, if you want to call the various endpoints of the Gnosis API yourself, don’t forget to sign up with Moralis. You can set up an account for free, and you’ll instantly be able to build smarter and faster on Gnosis Chain!
Overview
We’ll start today’s article by exploring the ins and outs of Gnosis Chain. From there, we’ll cover some of the benefits of building dapps on this network. We will then introduce you to the Moralis Gnosis API – the industry’s premier tool for Gnosis development. Next, we’ll dive into our Gnosis API tutorial, where we’re going to show you how to get the token balances of any wallet in three steps:
- Get Your Moralis API Key
- Write a Script Calling the
getWalletTokenBalances()
Endpoint - Execute the Code
Lastly, we’ll explore some Gnosis API use cases, giving you some inspiration for what you can build with our industry-leading Web3 development tool!
So, if you’re already familiar with Gnosis, feel free to skip the initial two sections and jump straight into the ”Moralis’ Gnosis API – Easiest Way to Build Gnosis Dapps” part.
However, if you’re new to Gnosis, join us in the following section as we briefly explore the intricacies of this network!
What is Gnosis? Gnosis Chain Explained
Martin Köppelman and Stefan George founded Gnosis back in 2015 when the organization – at the time – was building prediction markets. In 2020, Gnosis announced plans to fully decentralize into a DAO (decentralized autonomous organization). Just one year later, in 2021, the GnosisDAO and xDAI communities voted to combine their ecosystems to create Gnosis Chain!
So, what is Gnosis Chain?
Gnosis Chain is an Ethereum sidechain secured by a global network of 160,000+ validators worldwide. The network’s diverse set of validators and focus on community-driven governance ensures that Gnosis Chain remains neutral in its operations.
Furthermore, Gnosis Chain utilizes an innovative dual-token model with two central tokens: xDai and GNO. XDai is a stablecoin pegged to the USD, and it’s used for transactions, fees, and payments on Gnosis Chain. GNO, on the other hand, provides security via Gnosis’ consensus-layer Gnosis Beacon Chain. Consequently, GNO is used for staking, protocol protection, and community governance.
In addition to the Ethereum sidechain, Gnosis hosts an extensive ecosystem of other products. Two prominent examples include CoW and Safe. CoW, short for ”coincidence of wants”, is a permissionless decentralized exchange (DEX) allowing users to trade ERC-20 tokens. Safe is an account abstraction leader on the Ethereum network with the purpose of accelerating the transition to smart contract accounts.
That briefly covers Gnosis and Gnosis Chain. So, let’s now explore some benefits of building on this network!
Why Should You Build On Gnosis Chain?
Gnosis Chain offers a powerful playground allowing you, as a developer, to innovate and build creative Web3 projects. However, why should you opt to build on Gnosis Chain? To answer this question, let’s explore five prominent benefits of this blockchain network:
- Swift Performance: With an impressive five-second block time, you can experience rapid transaction confirmations.
- Globally Secured: With an extensive set of more than 160,000 validators worldwide, Gnosis Chain is able to offer high security.
- Cost-Efficient: Save money by achieving efficient operations at just $0.000099 per 100k gas.
- 100% Uptime: Ensure your dapps run without any issues with Gnosis Chain’s impressive 100% uptime.
- EVM-Compatible: Gnosis Chain is EVM-compatible, meaning you can leverage many of the same tools you would use for Ethereum development.
Now, with an overview of the benefits of Gnosis Chain, let’s explore the easiest way to build dapps on the network!
Moralis’ Gnosis API – Easiest Way to Build Gnosis Dapps
The easiest way to build on Gnosis Chain is to leverage Moralis’ Gnosis API. The Gnosis API from Moralis is an industry-leading tool that allows you to unlock the full potential of Gnosis Chain. With the features of this interface, you can effortlessly build dapps faster and more efficiently. In turn, you’ll save an abundance of development time and resources!
So, why should you join some of the biggest names in Web3 and build with Moralis? To answer this question, let’s explore some of the main benefits of the Moralis Gnosis API:
- Real-Time Data: Stay up-to-date and update your users with real-time data feeds.
- Accurate Data: Ensure data integrity with consistent and precise data directly from Gnosis Chain.
- Fully Indexed Data: Access the fully indexed and ready-to-use data on Gnosis Chain.
- Instant Setup: Avoid any hassles of preliminary setups and jump straight into development.
- Scalability: All of Morlis’ APIs are built to scale. Consequently, the Gnosis API will scale with your projects, ensuring smooth and hassle-free performance.
- Expert Support: Access world-class support from our team of experienced blockchain experts.
- And much more!
The Gnosis API suite consists of industry-leading interfaces, and in the following section, we’ll introduce you to three prominent examples!
Wallet API
The Moralis Wallet API is the ultimate tool for integrating wallet functionality into dapps. The Wallet API supports 500+ million addresses across all major EVM chains, including Gnosis Chain, Ethereum, Polygon, and many others. Furthermore, this interface boasts an array of prominent features, unparalleled scalability, and exceptional flexibility, making it stand out as the industry’s premier API for wallet data!
The Wallet API features many prominent endpoints, and with only single lines of code, you can seamlessly fetch all tokens, NFTs, native tokens, transactions, etc., and check the activity of any wallet on Gnosis Chain.
To illustrate the accessibility of this tool, here’s an example of how you can get all NFTs owned by a wallet using the getWalletNFTs()
endpoint:
const response = await Moralis.EvmApi.nft.getWalletNFTs({ "chain": "0x64", "address": "0x88ad09518695c6c3712ac10a214be5109a655671" });
Thanks to the multi-chain capabilities of the Wallet API, you can use the same tool to create cross-chain compatible dapps that integrate wallet stats, real-time NFT transfer data, decoded transactions, and much more!
Blockchain API
Moralis’ Blockchain API lets you seamlessly unlock the power of raw and decoded blockchain data with precision and pace. As such, when working with this industry-leading interface, it has never been easier to analyze smart contracts, set up real-time alerts, and build powerful trading platforms!
With the Blockchain API, you can seamlessly query the contents of any block on Gnosis Chain with a single line of code. The response will give you a bunch of data about the block, including a timestamp, hash, number, log blooms, the miner, gas used, and much more.
To show you how easy it is to work with the Blockchain API, here’s a Blockchain API example of how you can get the contents of a block using the getBlock()
endpoint:
const response = await Moralis.EvmApi.block.getBlock({ "chain": "0x64", "blockNumberOrHash": "23233" });
What’s more, just like the Wallet API, the Blockchain API also supports multiple networks. Consequently, you can use this tool to build cross-chain compatible dapps that integrate smart contract logs, events, address labels, etc.
Token API
The Moralis Token API is the ultimate tool for token data, with coverage spanning all tokens on all major chains, including Gnosis Chain, BNB Smart Chain, Ethereum, Ploygon, and many others!
With this interface, you can effortlessly get and integrate real-time token prices, wallet balances, and much more into your dapps. Consequently, when working with the Token API, building DEXs, portfolio trackers, token analytics tools, etc., has never been easier!
To highlight the accessibility of the Token API, here’s an example of how you can use the getWalletTokenBalances()
endpoint to get all token balances of a wallet:
const response = await Moralis.EvmApi.token.getWalletTokenBalances({ "chain": "0x64", "address": "0x88ad09518695c6c3712ac10a214be5109a655671" });
Also, since Moralis’ Token API supports all major chains, you can use this interface to build cross-chain projects integrating token metadata, stats, transfers, and much more!
However, the three interfaces above are just a few examples, and there’s a lot more to the Gnosis API suite. If you want to explore all the tools and available endpoints, check out our Web3 API page or the Web3 API documentation!
Gnosis API Tutorial: How to Get the Token Balances of any Wallet
In this section, we’ll provide an in-depth tutorial showing you how to get the token balances of any wallet on the Gnosis Chain. And thanks to the accessibility of the Moralis Gnosis API, you can accomplish this in three straightforward steps:
- Get Your Moralis API Key
- Write a Script Calling the
getWalletTokenBalances()
Endpoint - Execute the Code
However, you must deal with a few essential prerequisites before you can get going!
Prerequisites for Using the Gnosis API
The Gnosis API supports multiple programming languages. However, in this tutorial, we’ll be using JavaScript. As such, make sure you have the following ready before you proceed:
Step 1: Get Your Moralis API Key
The first thing you’ll need to call the Gnosis API is a Moralis API key. Consequently, start by clicking on the ”Start for Free” button at the top right to sign up with Moralis:
With an account at hand, you can now click on the ”Settings” tab, scroll down to the ”API Keys” section, and copy your key:
Please keep it for now, as you will use it in the next step!
Step 2: Write a Script Calling the getWalletTokenBalances()
Endpoint
Open your preferred integrated development environment, set up a new project, and run the following command in the root folder to install the Moralis SDK:
npm install moralis @moralisweb3/common-evm-utils
Next, create a new ”index.js” file 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 = "0x88ad09518695c6c3712ac10a214be5109a655671"; const chain = "0x64"; const response = await Moralis.EvmApi.token.getWalletTokenBalances({ address, chain, }); console.log(response.toJSON()); }; runApp();
From here, start by replacing YOUR_API_KEY
with the key you fetched in the previous step:
Afterward, configure the address
constant by assigning it the address of the wallet from which you want to query the token balances. What’s more, make sure that the chain
const is set to 0x64
:
We then pass along both address
and chain
as parameters when calling the getWalletTokenBalances()
endpoint:
That’s it for the code; all that remains from here is running the script!
Step 3: Execute the Code
For the final step, open a new terminal and run this command in the root folder of the project:
node index.js
In return, you should get a response containing an array of all tokens held by the wallet in question. And for each token, you’ll also get the current balance. It should look something like this:
[ { token_address: '0xfd135b71c8dbb1c2bd052edafc9cba77dd2a7d69', symbol: 'xdai.firstchef.net', name: 'xdai.firstchef.net', logo: null, thumbnail: null, decimals: 18, balance: '600000000000000000000000000', possible_spam: true }, //... [
Congratulations; you now know how to get all token balances of any wallet on Gnosis Chain!
You can follow the same steps to call any other endpoint for Gnosis Chain. You simply need to make minor configurations to the parameters and change the endpoint during the second step!
Gnosis API Use Cases
Now that you know how to fetch data from Gnosis Chain using our API, let’s also look at three examples of what you can build using this industry-leading tool:
- Governance Platforms: Build a community-driven decision-making platform that allows users to participate in polls and shape the future of your ecosystem.
- Wallet Platforms: Set up your own multi-sig wallet infrastructure like Safe, optimized for both businesses and individual users.
- DAO Management Tools: Create DAO management tools that streamline processes such as proposal submissions and voting.
Nevertheless, the examples above are only a few prominent use cases, and you can build a lot more with our Gnosis API!
Summary: Moralis’ Gnosis API – Easiest Way to Build Gnosis Chain Dapps
In today’s article, we introduced you to Moralis’ Gnosis API – the ultimate tool for building Gnosis chain dapps. With this tool, you can effortlessly get NFTs, wallet data, tokens, blockchain data, and much more with single lines of code. Consequently, when working with the Gnosis API, it has never been easier to build dapps on Gnosis Chain!
In addition to introducing you to the Gnosis API, we also showed you how to get the token balances of any wallet in three straightforward steps:
- Get Your Moralis API Key
- Write a Script Calling the
getWalletTokenBalances()
Endpoint - Execute the Code
As such, if you have followed along in this article, you now know how to use the Gnosis API to fetch data from Gnosis Chain!
If you found this Gnosis API article interesting, consider checking out more Web3 content here on the blog. For example, learn how to build on Solana and EVM, or read our complete Blockchain API tutorial for more info on our premier Web3 development tools! Also, before leaving, make sure to sign up with Moralis if you want to leverage the full power of Gnosis Chain yourself!
Read More: moralis.io