> ## Documentation Index
> Fetch the complete documentation index at: https://seilabs-docs-evm-cookbook.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

# Moralis

> Complete guide to integrating Moralis with Sei blockchain for Web3 development

Moralis is a Web3 API provider that connects any tech stack to blockchain networks. Through one fast, reliable API, it gives you multichain data for wallets, tokens, NFTs, DeFi protocols, and more.

Moralis also has a Backend-as-a-Service (BaaS) platform for developers. It hides the complexity of blockchain integration and gives you a suite of APIs, SDKs, and scalable infrastructure. You can then focus on building the core functionality of your application.

## What you'll learn

This tutorial shows you how to:

* Set up and configure Moralis for Sei
* Work with different Moralis APIs (Wallet, NFT, Token, and Blockchain APIs)
* Fetch wallet transactions and balances
* Get NFT holder information and metadata
* Get transaction details and token information

## Prerequisites

Before you start, make sure that you have:

1. **Moralis account**: Create a free account at [moralis.io](https://moralis.io)
2. **Node.js**: Version 14 or higher installed
3. **Package manager**: npm, yarn, or pnpm
4. **TypeScript**: Basic knowledge (optional but recommended)

### Sei network configuration

<Info>These are the Sei configuration details for a Moralis integration:</Info>

**Sei Mainnet:**

* Chain ID: 1329 (0x531)
* RPC URL: [https://evm-rpc.sei-apis.com](https://evm-rpc.sei-apis.com)

**Sei Testnet:**

* Chain ID: 1328 (0x530)
* RPC URL: [https://evm-rpc-testnet.sei-apis.com](https://evm-rpc-testnet.sei-apis.com)

## Moralis APIs overview

Moralis has several APIs that work across multiple blockchains:

* **NFT API**: Access NFT data, including metadata, ownership details, and transaction history
* **Wallet API**: Get real-time wallet data, including balances, transaction history, and token holdings
* **Token API**: Get token information, prices, and transfer data
* **Blockchain API**: Fetch raw blockchain data: blocks, transactions, and logs
* **Price API**: Get real-time and historical crypto token prices
* **DeFi API**: Query DeFi protocol data, including pools, positions, and yields

## Setting up your project

### Install Moralis SDK

First, create a new project and install the Moralis SDK:

```bash theme={null}
# Create new project
mkdir moralis-sei-integration
cd moralis-sei-integration

# Initialize package.json
npm init -y

# Install Moralis SDK
npm install moralis

# For TypeScript projects, also install:
npm install @moralisweb3/common-evm-utils
npm install typescript ts-node @types/node --save-dev
```

### Get your API key

1. Sign up at [moralis.io](https://moralis.io)
2. Go to **Project Settings**
3. Copy your API key from the dashboard

### Basic configuration

Create a `.env` file in your project root:

```env theme={null}
MORALIS_API_KEY=your_api_key_here
SEI_MAINNET_CHAIN_ID=0x531
SEI_TESTNET_CHAIN_ID=0x530
```

## Initialize Moralis

Create an `index.ts` or `index.js` file:

```typescript theme={null}
import Moralis from 'moralis';

// Initialize Moralis
const initMoralis = async () => {
  await Moralis.start({
    apiKey: process.env.MORALIS_API_KEY
  });
  console.log('Moralis initialized successfully');
};

// Call initialization
initMoralis();
```

## Wallet transactions API

```typescript theme={null}
// Get wallet transactions for Sei Mainnet
const getWalletTransactions = async (walletAddress: string) => {
  try {
    const response = await Moralis.EvmApi.transaction.getWalletTransactions({
      address: walletAddress,
      chain: '0x531' // Sei Mainnet
    });

    console.log('Wallet Transactions:', response.raw);
    return response.raw;
  } catch (error) {
    console.error('Error fetching wallet transactions:', error);
    throw error;
  }
};

// Example usage
const walletAddress = '0x742d35Cc6636C0532925a3b8D62c5bceCdB8eBc8';
getWalletTransactions(walletAddress);
```

## NFT holders API

```typescript theme={null}
// Get NFTs owned by wallet address
const getWalletNFTs = async (walletAddress: string) => {
  try {
    const response = await Moralis.EvmApi.nft.getWalletNFTs({
      address: walletAddress,
      chain: '0x531' // Sei Mainnet
    });

    console.log('Wallet NFTs:', response.raw);
    return response.raw;
  } catch (error) {
    console.error('Error fetching wallet NFTs:', error);
    throw error;
  }
};

// Get NFT owners for a specific contract
const getNFTOwners = async (contractAddress: string) => {
  try {
    const response = await Moralis.EvmApi.nft.getNFTOwners({
      address: contractAddress,
      chain: '0x531' // Sei Mainnet
    });

    console.log('NFT Owners:', response.raw);
    return response.raw;
  } catch (error) {
    console.error('Error fetching NFT owners:', error);
    throw error;
  }
};
```

## Transaction details API

```typescript theme={null}
// Get detailed transaction information
const getTransactionDetails = async (transactionHash: string) => {
  try {
    const response = await Moralis.EvmApi.transaction.getTransaction({
      transactionHash: transactionHash,
      chain: '0x531' // Sei Mainnet
    });

    console.log('Transaction Details:', response.raw);
    return response.raw;
  } catch (error) {
    console.error('Error fetching transaction details:', error);
    throw error;
  }
};

// Get transaction verbose (with decoded logs)
const getTransactionVerbose = async (transactionHash: string) => {
  try {
    const response = await Moralis.EvmApi.transaction.getTransactionVerbose({
      transactionHash: transactionHash,
      chain: '0x531' // Sei Mainnet
    });

    console.log('Transaction Verbose:', response.raw);
    return response.raw;
  } catch (error) {
    console.error('Error fetching verbose transaction:', error);
    throw error;
  }
};
```

## Token API

```typescript theme={null}
// Get token balances for a wallet
const getTokenBalances = async (walletAddress: string) => {
  try {
    const response = await Moralis.EvmApi.token.getWalletTokenBalances({
      address: walletAddress,
      chain: '0x531' // Sei Mainnet
    });

    console.log('Token Balances:', response.raw);
    return response.raw;
  } catch (error) {
    console.error('Error fetching token balances:', error);
    throw error;
  }
};

// Get token transfers for a wallet
const getTokenTransfers = async (walletAddress: string) => {
  try {
    const response = await Moralis.EvmApi.token.getWalletTokenTransfers({
      address: walletAddress,
      chain: '0x531' // Sei Mainnet
    });

    console.log('Token Transfers:', response.raw);
    return response.raw;
  } catch (error) {
    console.error('Error fetching token transfers:', error);
    throw error;
  }
};

// Get token metadata
const getTokenMetadata = async (tokenAddress: string) => {
  try {
    const response = await Moralis.EvmApi.token.getTokenMetadata({
      addresses: [tokenAddress],
      chain: '0x531' // Sei Mainnet
    });

    console.log('Token Metadata:', response.raw);
    return response.raw;
  } catch (error) {
    console.error('Error fetching token metadata:', error);
    throw error;
  }
};
```

## Complete integration example

This example combines several of the previous calls into one service:

```typescript theme={null}
import Moralis from 'moralis';
import dotenv from 'dotenv';

dotenv.config();

class SeiMoralisService {
  private initialized = false;

  async initialize() {
    if (!this.initialized) {
      await Moralis.start({
        apiKey: process.env.MORALIS_API_KEY
      });
      this.initialized = true;
      console.log('Moralis initialized for Sei blockchain');
    }
  }

  async getWalletOverview(walletAddress: string) {
    await this.initialize();

    try {
      // Get all wallet data in parallel
      const [nfts, tokenBalances] = await Promise.all([this.getWalletNFTs(walletAddress), this.getTokenBalances(walletAddress)]);

      return {
        address: walletAddress,
        nfts: nfts.result,
        tokenBalances: tokenBalances,
        summary: {
          totalNFTs: nfts,
          totalTokenTypes: tokenBalances.length
        }
      };
    } catch (error) {
      console.error('Error getting wallet overview:', error);
      throw new Error('Failed to retrieve wallet overview');
    }
  }

  async getWalletNFTs(walletAddress: string) {
    return await Moralis.EvmApi.nft.getWalletNFTs({
      address: walletAddress,
      chain: '0x531'
    });
  }

  async getTokenBalances(walletAddress: string) {
    const response = await Moralis.EvmApi.token.getWalletTokenBalances({
      address: walletAddress,
      chain: '0x531'
    });
    return response.raw;
  }
}

// Usage example
const seiService = new SeiMoralisService();

async function main() {
  try {
    const walletAddress = 'your_wallet_address_here';
    const overview = await seiService.getWalletOverview(walletAddress);

    console.log('Wallet Overview:', JSON.stringify(overview, null, 2));
  } catch (error) {
    console.error('Main execution error:', error);
  }
}

main();
```

## Working with Testnet

<Warning>To switch to Sei Testnet, change the chain ID in your API calls.</Warning>

```typescript theme={null}
// Testnet configuration
const TESTNET_CONFIG = {
  chainId: '0x530', // Sei Testnet EVM chain ID
  rpcUrl: 'https://evm-rpc-testnet.sei-apis.com',
  explorer: 'https://testnet.seiscan.io'
};

// Use testnet in your API calls
const response = await Moralis.EvmApi.transaction.getWalletTransactions({
  address: walletAddress,
  chain: TESTNET_CONFIG.chainId
});
```

<Info> For a complete API reference and more guides, see the [Moralis documentation](https://docs.moralis.com/). </Info>


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.