Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add article for moralis #951

Merged
merged 30 commits into from
Aug 22, 2024
Merged
Show file tree
Hide file tree
Changes from 26 commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
a831e19
first draft
wuzhong-papermoon Jul 10, 2024
32ff775
Update directory, replace png image with webp image
wuzhong-papermoon Jul 10, 2024
b58a0ba
Grammarly update
wuzhong-papermoon Jul 10, 2024
35b3c3e
Update builders/integrations/indexers/moralis.md
wuzhong-papermoon Jul 12, 2024
e0e43cd
Update builders/integrations/indexers/moralis.md
wuzhong-papermoon Jul 12, 2024
667e091
Update builders/integrations/indexers/moralis.md
wuzhong-papermoon Jul 12, 2024
8375e3f
Update builders/integrations/indexers/moralis.md
wuzhong-papermoon Jul 12, 2024
ff53876
Update builders/integrations/indexers/moralis.md
wuzhong-papermoon Jul 12, 2024
a192541
Update builders/integrations/indexers/moralis.md
wuzhong-papermoon Jul 12, 2024
3522329
Update builders/integrations/indexers/moralis.md
wuzhong-papermoon Jul 12, 2024
dfb4b60
Update builders/integrations/indexers/moralis.md
wuzhong-papermoon Jul 12, 2024
fb0d11e
Update builders/integrations/indexers/moralis.md
wuzhong-papermoon Jul 12, 2024
56a3d4b
Update builders/integrations/indexers/moralis.md
wuzhong-papermoon Jul 12, 2024
30448a1
Update builders/integrations/indexers/moralis.md
wuzhong-papermoon Jul 12, 2024
707b439
Update builders/integrations/indexers/moralis.md
wuzhong-papermoon Jul 12, 2024
89e5d71
refactoring #1
wuzhong-papermoon Jul 12, 2024
be93301
Revert dash/semicolon change
wuzhong-papermoon Jul 15, 2024
f095b32
Refactor V2
wuzhong-papermoon Jul 24, 2024
7b8dc39
Apply suggestions from code review
wuzhong-papermoon Jul 26, 2024
d2947f7
Image refactoring
wuzhong-papermoon Jul 26, 2024
b8068a4
Merge branch 'Add_article_moralis' of https://github.com/moonbeam-fou…
wuzhong-papermoon Jul 26, 2024
b24b198
Update builders/integrations/indexers/moralis.md
wuzhong-papermoon Jul 26, 2024
9ac133f
Apply suggestions from code review
wuzhong-papermoon Jul 29, 2024
982ba87
Update image browser color
wuzhong-papermoon Jul 30, 2024
01bd9d3
Content refactoring
wuzhong-papermoon Aug 13, 2024
4b5434c
Resize steps and arrows
wuzhong-papermoon Aug 14, 2024
4366e28
Change arrow style
wuzhong-papermoon Aug 14, 2024
e754029
Change arrow style
wuzhong-papermoon Aug 16, 2024
5ebd63c
Update moralis-5.webp
wuzhong-papermoon Aug 20, 2024
f8477fd
Apply suggestions from code review
wuzhong-papermoon Aug 22, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions builders/integrations/indexers/.pages
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,6 @@ nav:
- index.md
- 'The Graph': 'thegraph.md'
- 'Covalent API': 'covalent.md'
- 'Moralis': 'moralis.md'
- 'SubQuery': 'subquery.md'
- 'Subsquid': 'subsquid.md'
182 changes: 182 additions & 0 deletions builders/integrations/indexers/moralis.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,182 @@
---
title: Interact with Moralis APIs
description: Learn how Moralis' API suite empowers developers to retrieve and leverage various data sets from Moonbeam, Moonriver, and Moonbase Alpha.
---

# Access Moonbeam Data via Moralis APIs

## Introduction {: #introduction }

As a one-stop solution for blockchain development, [Moralis](https://moralis.io/){target=\_blank} offers a comprehensive platform that empowers developers to create, launch, and scale decentralized applications (dApps) with ease.
wuzhong-papermoon marked this conversation as resolved.
Show resolved Hide resolved

It provides a suite of tools and services designed to streamline the process of accessing Web3 data and interacting with blockchain networks. Its offerings are structured into these primary categories:

- **EVM API** - EVM API allows developers to query essential data for Ethereum Virtual Machine (EVM)-compatible blockchains. Moralis provides dedicated APIs for four key areas: NFTs, tokens, wallets, and general blockchain information
wuzhong-papermoon marked this conversation as resolved.
Show resolved Hide resolved

- **Streams API** - the Streams API enables developers to listen for on-chain events, such as smart contract event emissions, in real-time. Popular use cases include real-time wallet notifications, asset monitoring, and gaming event notifications

- **RPC API** - the RPC API offers a secure and reliable connection to various blockchain networks. It provides a high-performance gateway for developers to interact with blockchain nodes, ensuring stable and efficient communication between dApps and the blockchain

This guide will show you how to access the API endpoints for Moonbeam using curl commands and the Moralis SDK using JavaScript and Python snippets.

--8<-- 'text/_disclaimers/third-party-content-intro.md'

wuzhong-papermoon marked this conversation as resolved.
Show resolved Hide resolved
## Checking Prerequisites {: #checking-prerequisites }

To interact with Moralis' API endpoints, an account and API key are required.

Head to the [sign up page](https://admin.moralis.io/register){target=\_blank} to create an account. Once you're in, navigate to the **API keys** section. There, you can generate your own unique API key. Be sure to copy it for future use.

![Moralis API key](/images/builders/integrations/indexers/moralis/moralis-1.webp)
wuzhong-papermoon marked this conversation as resolved.
Show resolved Hide resolved

## Querying the EVM API {: #querying-the-evm-api }

With the API key, you can try Moralis' REST APIs. The following examples show how the EVM API works:

Get the token balance of a wallet:

```bash
curl --request GET \
wuzhong-papermoon marked this conversation as resolved.
Show resolved Hide resolved
--url 'https://deep-index.moralis.io/api/v2.2/0xd4d7fb1f98dD66f6D1f393E8e237AdF74c31F3ea/erc20?chain=moonbeam' \
--header 'accept: application/json' \
--header 'X-API-Key: INSERT_YOUR_API_KEY'
```

Get the list of owners of an NFT:

```bash
curl --request GET \
--url 'https://deep-index.moralis.io/api/v2.2/nft/0xfffffffffffffffffffffffffffffffffffffffff/owners?chain=moonbeam&format=decimal' \
--header 'accept: application/json' \
--header 'X-API-Key: INSERT_YOUR_API_KEY'
```

For a comprehensive overview of EVM APIs and their capabilities, please refer to Moralis' [official documentation](https://docs.moralis.io/web3-data-api/evm/reference){target=\_blank}.

## Using the Moralis SDK {: #using-the-moralis-SDK }

Moralis has an SDK that allows developers to seamlessly integrate Moralis' API into their backend infrastructure. This SDK offers a wide array of features, including:
wuzhong-papermoon marked this conversation as resolved.
Show resolved Hide resolved

- Data querying from EVM APIs
- Integration of Web3 authentication
- A collection of utility functions for efficient data transformation and formatting

Moralis currently provides official SDK support for two primary programming languages:
wuzhong-papermoon marked this conversation as resolved.
Show resolved Hide resolved

- Node.js
- Python

You can install Moralis SDK with the following commands:

=== "npm"

```bash
npm install moralis
```

=== "yarn"

```bash
yarn add moralis
```

=== "pnpm"

```bash
pnpm add moralis
```

=== "pip"

```bash
pip install moralis
```

Once the SDK is ready, you can leverage it to query Moralis APIs. Here's an example of how to interact with the EVM API using a JSON-RPC interface:

=== "JavaScript"

```js
import Moralis from 'moralis';

try {
await Moralis.start({
apiKey: 'INSERT_YOUR_API_KEY',
});

const response = await Moralis.EvmApi.block.getBlock({
chain: '0x504',
blockNumberOrHash: '1',
});

console.log(response.raw);
} catch (e) {
console.error(e);
}
```

=== "Python"

```python
from moralis import evm_api

api_key = "INSERT_YOUR_API_KEY"

params = {"chain": "moonbeam", "block_number_or_hash": "1"}

result = evm_api.block.get_block(
api_key=api_key,
params=params,
)

print(result)
```

wuzhong-papermoon marked this conversation as resolved.
Show resolved Hide resolved
For more information on advanced features and configurations within the Moralis SDK, please refer to the official [JavaScript](https://moralisweb3.github.io/Moralis-JS-SDK/Introduction){target=\_blank} and [Python](https://moralisweb3.github.io/Moralis-Python-SDK/){target=\_blank} documentation.

## Accessing the Stream API {: #accessing-stream-api }

The [Moralis Streams API](https://docs.moralis.io/streams-api/evm){target=\_blank} is a tool for developers to listen to and react to events happening on blockchains in real time. This API lets you listen for specific events, such as a new transaction being added to a block, a particular smart contract function being called, or an NFT being transferred and delivering the event via Webhook.

Head over to the **Streams** page from your Moralis dashboard and click **Create a new stream** to get started.

![stream API page](/images/builders/integrations/indexers/moralis/moralis-2.webp)
wuzhong-papermoon marked this conversation as resolved.
Show resolved Hide resolved

To get started quickly, choose a predefined template. This example focuses on transactions related to xcDOT. Select the **Contract Activity** template to listen for events related specifically to xcDOT.

![template selection page](/images/builders/integrations/indexers/moralis/moralis-3.webp)
wuzhong-papermoon marked this conversation as resolved.
Show resolved Hide resolved

On the next page, enter the following details:
wuzhong-papermoon marked this conversation as resolved.
Show resolved Hide resolved

1. Enter the smart contract address for [xcDOT](https://moonscan.io/token/0xffffffff1fcacbd218edc0eba20fc2308c778080){target=\_blank}:
```
0xFfFFfFff1FcaCBd218EDc0EbA20Fc2308C778080
```
2. Select Moonbeam from the available network options. Moralis supports listening to events on Moonbeam, Moonriver, and Moonbase Alpha
wuzhong-papermoon marked this conversation as resolved.
Show resolved Hide resolved
3. Customize the events you want to receive. For this example, choose **All contract events**. You may also test the stream to confirm it captures the needed data
4. Connect the stream to an endpoint to receive updates from Moralis
5. Click **Save** to activate your stream

![details input page](/images/builders/integrations/indexers/moralis/moralis-4.webp)

Now you're all set. Once you activate your stream, it will be added to your list of streams on your dashboard:

![stream API end page](/images/builders/integrations/indexers/moralis/moralis-5.webp)

## Accessing the RPC API {: #accessing-rpc-api }

To use the Moralis Moonbeam RPC endpoint, visit the **Nodes** page, click **Create Node**, and take the following steps:

1. Select **Moonbeam** as the protocol
2. Choose **Mainnet** as the chain
3. Click **Create Node**

![RPC API setup page](/images/builders/integrations/indexers/moralis/moralis-5.webp)
wuzhong-papermoon marked this conversation as resolved.
Show resolved Hide resolved

Your RPC endpoint will be generated for you to easily copy, and your Moonbeam node will be up and running in seconds, ready to handle your RPC requests. You can view your nodes at any time from your dashboard.

![node ready page](/images/builders/integrations/indexers/moralis/moralis-7.webp)

And that's it! Hope this guide has been helpful. For advanced features and more complex use cases, refer to [the official Moralis documentation](https://docs.moralis.io/) for further details.

--8<-- 'text/_disclaimers/third-party-content.md'
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Loading