### Project Setup: Initialize npm
Source: https://docs.moralis.com/get-started/tutorials/data-api/tokens-and-markets/get-erc-20-transfer-history-by-wallet-or-token
Initialize a new Node.js project. Ensure you have Node.js v18+ installed.
```bash
mkdir get-token-transfers && cd get-token-transfers
npm init -y
```
--------------------------------
### Full App.js Example
Source: https://docs.moralis.com/get-started/tutorials/auth-api/authenticate-users-with-meta-mask-using-react
This is the complete App.js file demonstrating the setup of wagmi, react-router-dom, and necessary imports for a React application with Web3 authentication.
```javascript
import { createBrowserRouter, RouterProvider } from "react-router-dom";
import { createConfig, configureChains, WagmiConfig } from "wagmi";
import { publicProvider } from "wagmi/providers/public";
import { mainnet } from "wagmi/chains";
import Signin from "./signin";
import User from "./user";
const { publicClient, webSocketPublicClient } = configureChains(
[mainnet],
[publicProvider()]
);
const config = createConfig({
autoConnect: true,
publicClient,
webSocketPublicClient,
});
const router = createBrowserRouter([
{
path: "/signin",
element: ,
},
{
path: "/user",
element: ,
},
{
path: "/",
element:
Home Component
,
},
]);
function App() {
return (
);
}
export default App;
```
--------------------------------
### Run Server Command
Source: https://docs.moralis.com/get-started/tutorials/auth-api/authenticate-users-with-meta-mask-using-angular
Command to execute to start the server. Ensure your project has the necessary dependencies installed.
```bash
npm run start
```
--------------------------------
### Project Setup for Crypto Charts
Source: https://docs.moralis.com/get-started/tutorials/charts-and-widgets/ohlc-chart-configurator
Initializes a new React project and installs necessary dependencies including lightweight-charts, axios, and react-spinners. Also includes instructions for setting up the environment variable for the Moralis API key.
```bash
npx create-react-app crypto-charts
cd crypto-charts
npm install lightweight-charts axios react-spinners
```
```dotenv
REACT_APP_MORALIS_API_KEY=YOUR_API_KEY
```
--------------------------------
### Install RainbowKit and Dependencies
Source: https://docs.moralis.com/get-started/tutorials/auth-api/authenticate-users-with-rainbow-kit
Install the necessary packages for RainbowKit, wagmi, and viem. Use npm or yarn for installation.
```bash
npm install @rainbow-me/rainbowkit@latest wagmi viem
```
--------------------------------
### Get Native Balances for Multiple Wallets
Source: https://docs.moralis.com/data-api/evm/wallet/native-balances-batch
This example demonstrates how to fetch the native balances for a batch of wallet addresses on a specified chain. It includes query parameters for the chain and the wallet addresses, along with the required API key.
```APIDOC
## GET /wallets/balances
### Description
Retrieves the native token balances for a list of wallet addresses on a specified chain.
### Method
GET
### Endpoint
https://deep-index.moralis.io/api/v2.2/wallets/balances
### Parameters
#### Header Parameters
- **X-API-Key** (string) - Required - Your Moralis API Key.
#### Query Parameters
- **chain** (enum) - Optional - The chain to query. Defaults to 'eth'.
Available options: `eth`, `0x1`, `sepolia`, `0xaa36a7`, `polygon`, `0x89`, `bsc`, `0x38`, `bsc testnet`, `0x61`, `avalanche`, `0xa86a`, `fantom`, `0xfa`, `cronos`, `0x19`, `arbitrum`, `0xa4b1`, `chiliz`, `0x15b38`, `chiliz testnet`, `0x15b32`, `gnosis`, `0x64`, `gnosis testnet`, `0x27d8`, `base`, `0x2105`, `base sepolia`, `0x14a34`, `optimism`, `0xa`, `polygon amoy`, `0x13882`, `linea`, `0xe708`, `moonbeam`, `0x504`, `moonriver`, `0x505`, `moonbase`, `0x507`, `linea sepolia`, `0xe705`, `flow`, `0x2eb`, `flow-testnet`, `0x221`, `ronin`, `0x7e4`, `ronin-testnet`, `0x31769`, `lisk`, `0x46f`, `lisk-sepolia`, `0x106a`, `pulse`, `0x171`, `sei-testnet`, `0x530`, `sei`, `0x531`, `monad`, `0x8f`
- **to_block** (number) - Optional - The block number on which the balances should be checked.
- **wallet_addresses** (string[]) - Required - The addresses to get metadata for. Maximum array length: 25.
### Request Example
```json
{
"chain": "eth",
"wallet_addresses": ["0x123", "0x456"]
}
```
### Response
#### Success Response (200)
- **chain** (string) - The chain.
- **chain_id** (string) - The chain id.
- **total_balance** (string) - The total balances for all the wallets.
- **block_number** (string) - The block Number.
- **block_timestamp** (string) - The block timestamp.
- **total_balance_formatted** (string) - The total balances for all the wallets formatted.
- **wallet_balances** (object[]) - An array of wallet balance objects.
- **address** (string) - The wallet address.
- **balance** (string) - The native balance of the wallet.
- **balance_formatted** (string) - The formatted native balance of the wallet.
#### Response Example
```json
[
{
"chain": "eth_mainnet",
"chain_id": "2",
"total_balance": "57499206466583095",
"block_number": "123456789",
"block_timestamp": "0.057",
"total_balance_formatted": "123456789",
"wallet_balances": [
{
"address": "0x123",
"balance": "28499206466583095",
"balance_formatted": "0.0285"
}
]
}
]
```
```
--------------------------------
### Install Onchain Skills with ClawHub
Source: https://docs.moralis.com/data-api/onchain-skills/tutorial
Alternative installation methods for Onchain Skills using ClawHub. Each skill can be installed individually.
```bash
clawhub install moralis-data-api
clawhub install moralis-streams-api
clawhub install learn-moralis
```
--------------------------------
### Eth Get Logs Response Example
Source: https://docs.moralis.com/rpc-nodes/arbitrum/eth-get-logs
This is an example of a successful JSON response from the eth_getLogs method, containing an array of log objects.
```json
{
"jsonrpc": "2.0",
"id": 1,
"result": [
{
"logIndex": "0x1",
"blockNumber": "0x1b4",
"blockHash": "0x8216c5785ac562ff41e2dcfdf5785ac562ff41e2dcfdf829c5a142f1fccd7d",
"transactionHash": "0xdf829c5a142f1fccd7d8216c5785ac562ff41e2dcfdf5785ac562ff41e2dcf",
"transactionIndex": "0x0",
"address": "0x16c5785ac562ff41e2dcfdf829c5a142f1fccd7d",
"data": "0x0000000000000000000000000000000000000000000000000000000000000000",
"topics": [
"0x59ebeb90bc63057b6515673c3ecf9438e5058bca0f92585014eced636878c9a5"
]
}
]
}
```
--------------------------------
### Initialize Project and Install Dependencies
Source: https://docs.moralis.com/get-started/tutorials/data-api/nfts/get-nft-owners-and-ownership-details
Set up a new project directory and initialize it with npm. This is the first step before adding any code.
```bash
mkdir get-nft-owners && cd get-nft-owners
npm init -y
```
--------------------------------
### Initialize Project and Install Dependencies
Source: https://docs.moralis.com/get-started/tutorials/data-api/blocks-and-transactions/get-a-blockchain-transaction-by-hash
Set up a new project directory and initialize it with npm. This is the first step before adding any code.
```bash
mkdir get-transaction && cd get-transaction
npm init -y
```
--------------------------------
### Eth Get Code RPC Response Example
Source: https://docs.moralis.com/rpc-nodes/arbitrum/eth-get-code
This is an example of a successful response from the eth_getCode RPC method, containing the contract's bytecode.
```json
{
"jsonrpc": "2.0",
"id": 1,
"result": "0x600160008035811a818181146012578301005b601b6001356025565b8060005260206000f25b600060078202905091905056"
}
```
--------------------------------
### Initialize Project and Install Dependencies
Source: https://docs.moralis.com/get-started/tutorials/data-api/nfts/get-all-nfts-owned-by-a-wallet-address
Set up a new project directory and initialize it with npm. This is the first step before adding the script to fetch NFT data.
```bash
mkdir get-nft-balances && cd get-nft-balances
npm init -y
```
--------------------------------
### Example Prompts for Learn Moralis Skill
Source: https://docs.moralis.com/data-api/onchain-skills/overview
Use these example prompts to ask general questions about Moralis and get guidance on which technical skill to use.
```text
/learn-moralis What is Moralis?
```
```text
/learn-moralis Which Moralis API should I use for tracking wallet activity?
```
--------------------------------
### Initialize Project and Install Dependencies
Source: https://docs.moralis.com/get-started/tutorials/data-api/nfts/get-nft-metadata-by-contract-and-token-id
Set up a new project directory and initialize it with npm. This is the first step before adding the script to fetch NFT metadata.
```bash
mkdir get-nft-metadata && cd get-nft-metadata
npm init -y
```
--------------------------------
### Eth Get Code RPC Request Parameters Example
Source: https://docs.moralis.com/rpc-nodes/arbitrum/eth-get-code
Example of the parameters array for an eth_getCode RPC request, specifying the contract address and block tag.
```json
[
"0xa94f5374fce5edbc8e2a8697c15331677e6ebf0b",
"0x2"
]
```
--------------------------------
### Initialize Project Directory and npm
Source: https://docs.moralis.com/get-started/tutorials/data-api/tokens-and-markets/build-a-dex-screener-clone
Sets up a new project directory and initializes npm for dependency management.
```bash
mkdir dex-screener && cd dex-screener
npm init -y
```
--------------------------------
### Eth Get Logs Request Params Example
Source: https://docs.moralis.com/rpc-nodes/arbitrum/eth-get-logs
This JSON object shows an example of the `params` array for the eth_getLogs method, specifying block ranges, contract address, and topics for filtering.
```json
[
{
"fromBlock": "0x1",
"toBlock": "0x2",
"address": "0x8888f1f195afa192cfee860698584c030f4c9db1",
"topics": [
"0x000000000000000000000000a94f5374fce5edbc8e2a8697c15331677e6ebf0b",
null,
[
"0x000000000000000000000000a94f5374fce5edbc8e2a8697c15331677e6ebf0b",
"0x0000000000000000000000000aff3454fce5edbc8cca8697c15331677e6ebccc"
]
]
}
]
```
--------------------------------
### Initialize Project - npm
Source: https://docs.moralis.com/get-started/tutorials/data-api/blocks-and-transactions/find-the-closest-block-by-unix-timestamp
Set up a new project directory and initialize it with npm. Ensure Node.js v18+ is installed.
```bash
mkdir get-block-by-date && cd get-block-by-date
npm init -y
```
--------------------------------
### Response Example for Get Entities By Category
Source: https://docs.moralis.com/data-api/universal/entity/endpoints/entity-by-category
This is an example of a successful JSON response when retrieving entities by category. It includes a list of entities, each with its name, ID, logo, description, and other relevant details, along with pagination data.
```json
{
"result": [
{
"name": "Uniswap",
"id": "uniswap",
"logo": "https://uniswap.io/favicon.ico",
"bio": "Uniswap is a decentralized finance protocol that is used to exchange cryptocurrencies.",
"description": "Uniswap is a decentralized finance protocol that is used to exchange cryptocurrencies.",
"website": "https://uniswap.io",
"twitter": "https://twitter.com/uniswap",
"type": "exchange",
"total_addresses": 100
}
],
"page": "1",
"page_size": "100"
}
```
--------------------------------
### Initialize Project for Pump.fun Swaps
Source: https://docs.moralis.com/get-started/tutorials/data-api/tokens-and-markets/get-pump-fun-tokens-swaps-and-prices
Set up a new project directory and initialize it with npm. Ensure Node.js v18+ is installed.
```bash
mkdir pump-fun-swaps && cd pump-fun-swaps
npm init -y
```
--------------------------------
### Get Current Block Number
Source: https://docs.moralis.com/rpc-nodes/pulsechain/eth-blockNumber
This example demonstrates how to fetch the latest block number on the PulseChain network using the eth_blockNumber RPC method.
```APIDOC
## POST /pulse/:apiKey
### Description
Retrieves the current block number of the PulseChain network.
### Method
POST
### Endpoint
`https://site1.moralis.com/pulse/:apiKey`
### Parameters
#### Path Parameters
- **apiKey** (string) - Required - Your API key for authentication
#### Request Body
```json
{
"jsonrpc": "2.0",
"method": "eth_blockNumber",
"params": [],
"id": 1
}
```
### Response
#### Success Response (200)
- **result** (string) - The current block number in hexadecimal format.
#### Response Example
```json
{
"jsonrpc": "2.0",
"id": 1,
"result": "0x4b7"
}
```
```
--------------------------------
### Initialize Project Directory and Dependencies
Source: https://docs.moralis.com/get-started/tutorials/data-api/prices-and-charts/build-crypto-price-charts-using-ohlc-data
Sets up a new project directory and initializes npm for dependency management. Ensure Node.js v18+ is installed.
```bash
mkdir crypto-charts && cd crypto-charts
npm init -y
```
--------------------------------
### Get Streams API Response Structure
Source: https://docs.moralis.com/streams/api-reference/streams/get-streams
This is an example of a successful response when fetching streams. It includes details about each stream, total count, and pagination cursor.
```json
{
"result": [
{
"webhookUrl": "",
"description": "",
"chainIds": [
""
],
"id": "3c90c3cc-0d44-4b50-8888-8dd25736052a",
"status": {},
"statusMessage": "",
"updatedAt": "2023-11-07T05:31:56Z",
"amountOfAddresses": 123,
"tag": "",
"topic0": [
""
],
"allAddresses": true,
"includeNativeTxs": true,
"includeContractLogs": true,
"includeInternalTxs": true,
"includeAllTxLogs": true,
"getNativeBalances": [
{
"selectors": [
""
],
"type": "tx"
}
],
"abi": null,
"advancedOptions": null,
"filterPossibleSpamAddresses": true,
"demo": true,
"triggers": [
{
"type": "tx",
"contractAddress": "",
"functionAbi": {},
"inputs": [
""
],
"topic0": "",
"callFrom": ""
}
]
}
],
"total": 123,
"cursor": ""
}
```
--------------------------------
### Initialize Project Directory
Source: https://docs.moralis.com/get-started/tutorials/data-api/nfts/get-nft-floor-prices
Create and navigate into a new project directory, then initialize it with npm. Ensure Node.js v18+ is installed.
```bash
mkdir get-nft-floor-price && cd get-nft-floor-price
npm init -y
```
--------------------------------
### Complete Server Setup
Source: https://docs.moralis.com/get-started/tutorials/auth-api/authenticate-users-with-meta-mask-using-react
This is the complete server setup including all endpoints for authentication, verification, and logout, along with necessary middleware and CORS configuration.
```javascript
const Moralis = require("moralis").default;
const express = require("express");
const cors = require("cors");
const cookieParser = require("cookie-parser");
const jwt = require("jsonwebtoken");
// to use our .env variables
require("dotenv").config();
const app = express();
const port = 4000;
app.use(express.json());
app.use(cookieParser());
// allow access to React app domain
app.use(
cors({
origin: "http://localhost:3000",
credentials: true,
})
);
const config = {
domain: process.env.APP_DOMAIN,
statement: "Please sign this message to confirm your identity.",
uri: process.env.REACT_URL,
timeout: 60,
};
// request message to be signed by client
app.post("/request-message", async (req, res) => {
const { address, chain, network } = req.body;
try {
const message = await Moralis.Auth.requestMessage({
address,
chain,
...config,
});
res.status(200).json(message);
} catch (error) {
res.status(400).json({ error: error.message });
console.error(error);
}
});
app.post("/verify", async (req, res) => {
try {
const { message, signature } = req.body;
const { address, profileId } = (
await Moralis.Auth.verify({
message,
signature,
networkType: "evm",
})
).raw;
const user = { address, profileId, signature };
// create JWT token
const token = jwt.sign(user, process.env.AUTH_SECRET);
// set JWT cookie
res.cookie("jwt", token, {
httpOnly: true,
});
res.status(200).json(user);
} catch (error) {
```
--------------------------------
### Eth Get Storage At JSON Response
Source: https://docs.moralis.com/rpc-nodes/arbitrum/eth-get-storage-at
This is an example of the JSON response you will receive when successfully querying the eth_getStorageAt method. The 'result' field contains the storage value.
```json
{
"jsonrpc": "2.0",
"id": 1,
"result": "0x00000000000000000000000000000000000000000000000000000000000004d2"
}
```
--------------------------------
### Example Request Params for Eth Get Storage At
Source: https://docs.moralis.com/rpc-nodes/arbitrum/eth-get-storage-at
This array represents the parameters required for the eth_getStorageAt method: the contract address, the storage position (slot), and the block tag.
```json
[
"0x295a70b2de5e3953354a6a8344e616ed314d7251",
"0x0",
"latest"
]
```
--------------------------------
### Example Request Params for Eth Get Balance
Source: https://docs.moralis.com/rpc-nodes/arbitrum/eth-get-balance
This array represents the parameters required for the eth_getBalance JSON-RPC method. It includes the address and the block tag (e.g., 'latest').
```json
[
"0x407d73d8a49eeb85d32cf465507dd71d507100c1",
"latest"
]
```
--------------------------------
### Serve Project Locally
Source: https://docs.moralis.com/get-started/tutorials/data-api/prices-and-charts/build-crypto-price-charts-using-ohlc-data
Starts a simple HTTP server in the current directory to serve the project files. This is useful for previewing the HTML file and its associated JavaScript in a browser.
```bash
npx serve .
```
--------------------------------
### Example Request with Query Parameters
Source: https://docs.moralis.com/data-api/evm/nft/metadata/nft-metadata-batch
This example demonstrates how to construct a request to the batch NFT metadata endpoint, including specifying the chain and whether to normalize metadata or include media items.
```javascript
const options = {
method: "POST",
headers: {
"Content-Type": "application/json",
"X-API-Key": "YOUR_API_KEY"
},
body: JSON.stringify({
tokens: [
{
"token_address": "0xa4991609c508b6d4fb7156426db0bd49fe298bd8",
"token_id": "12"
},
{
"token_address": "0x3c64dc415ebb4690d1df2b6216148c8de6dd29f7",
"token_id": "1"
}
],
normalizeMetadata: true,
media_items: false
})
};
fetch(
"https://deep-index.moralis.io/api/v2/nft/metadata/batch?chain=eth",
options
)
.then(response => response.json())
.then(response => console.log(response))
.catch(error => console.error(error));
```
--------------------------------
### Eth Get Balance JSON Response
Source: https://docs.moralis.com/rpc-nodes/arbitrum/eth-get-balance
This is an example of the JSON response you will receive after successfully querying the eth_getBalance method. The 'result' field contains the balance in hexadecimal format.
```json
{
"jsonrpc": "2.0",
"id": 1,
"result": "0x0234c8a3397aab58"
}
```
--------------------------------
### Successful Response for Get Block by Date
Source: https://docs.moralis.com/data-api/evm/blockchain/block-by-date
This is an example of a successful JSON response when retrieving block information by date. It includes the requested date, block number, and timestamps.
```json
{
"date": "2020-01-01T00:00:00+00:00",
"block": 9193266,
"timestamp": 1577836811,
"block_timestamp": "2019-12-31T23:59:45.000Z",
"hash": "0x9b559aef7ea858608c2e554246fe4a24287e7aeeb976848df2b9a2531f4b9171",
"parent_hash": "0x011d1fc45839de975cc55d758943f9f1d204f80a90eb631f3bf064b80d53e045"
}
```
--------------------------------
### Initialize Project Directory
Source: https://docs.moralis.com/get-started/tutorials/data-api/nfts/get-nft-collections-owned-by-a-wallet
Create a new directory for your project and initialize it with npm. Ensure Node.js v18+ is installed.
```bash
mkdir get-nft-collections && cd get-nft-collections
npm init -y
```
--------------------------------
### Eth Get Proof Request Example (cURL)
Source: https://docs.moralis.com/rpc-nodes/lisk/eth-get-proof
This cURL command demonstrates how to make a request to the eth_getProof RPC method. Ensure you replace ':apiKey' with your actual API key.
```bash
curl https://site1.moralis-nodes.com/lisk/:apiKey \
-X POST \
-H "Content-Type: application/json" \
-d '{"jsonrpc": "2.0", "method": "eth_getProof", "params": ["0x7F0d15C7FAae65896648C8273B6d7E43f58Fa842", ["0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421"], "latest"], "id": 1}'
```
--------------------------------
### Eth Get Proof Response
Source: https://docs.moralis.com/rpc-nodes/arbitrum/eth-get-proof
This is an example JSON response for the eth_getProof method. It includes the account proof, balance, code hash, nonce, storage hash, and storage proof.
```json
{
"jsonrpc": "2.0",
"id": 1,
"result": {
"address": "0x7F0d15C7FAae65896648C8273B6d7E43f58Fa842",
"accountProof": [
"0xf90211a090dcaf88c40c7bbc95a912cbdde67c175767b31173df9ee4b0d733bfdd511c43a0babe369f6b12092f49181ae04ca173fb68d1a5456f18d20fa32cba73954052bda0473ecf8a7e36a829e75039a3b055e51b8332cbf03324ab4af2066bbd6fbf0021fa0bbda34753d7aa6c38e603f360244e8f59611921d9e1f128372fec0d586d4f9e0a04e44caecff45c9891f74f6a2156735886eedf6f1a733628ebc802ec79d844648a0a5f3f2f7542148c973977c8a1e154c4300fec92f755f7846f1b734d3ab1d90e7a0e823850f50bf72baae9d1733a36a444ab65d0a6faaba404f0583ce0ca4dad92da0f7a00cbe7d4b30b11faea3ae61b7f1f2b315017e79a3de5ab2dc8bb46a59fdb37a09b3b8d0e0e4c1e3b2d3e8f7c6e5d4c3b2a1e0f9e8d7c6b5a4e3f2e1d0c9b8a7a0b1f8e8d7c6b5a4e3f2e1d0c9b8a7a6f5e4d3c2b1a0f9e8d7c6b5a4e3f2e1d0a0c9b8a7a6f5e4d3c2b1a0f9e8d7c6b5a4e3f2e1d0c9b8a7a6f5e4d3c2b1a0a0d7c6b5a4e3f2e1d0c9b8a7a6f5e4d3c2b1a0f9e8d7c6b5a4e3f2e1d0c9b8a7a08080"
],
"balance": "0x0",
"codeHash": "0x5e61b0f7919ab4e6fc7cfa6f3f5f6f6f6f6f6f6f6f6f6f6f6f6f6f6f6f6f6f",
"nonce": "0x0",
"storageHash": "0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421",
"storageProof": [
{
"key": "0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421",
"value": "0x1",
"proof": [
"0xf90211a090dcaf88c40c7bbc95a912cbdde67c175767b31173df9ee4b0d733bfdd511c43a0babe369f6b12092f49181ae04ca173fb68d1a5456f18d20fa32cba73954052bda0473ecf8a7e36a829e75039a3b055e51b8332cbf03324ab4af2066bbd6fbf0021fa0bbda34753d7aa6c38e603f360244e8f59611921d9e1f128372fec0d586d4f9e0a04e44caecff45c9891f74f6a2156735886eedf6f1a733628ebc802ec79d844648a0a5f3f2f7542148c973977c8a1e154c4300fec92f755f7846f1b734d3ab1d90e7a0e823850f50bf72baae9d1733a36a444ab65d0a6faaba404f0583ce0ca4dad92da0f7a00cbe7d4b30b11faea3ae61b7f1f2b315017e79a3de5ab2dc8bb46a59fdb37a09b3b8d0e0e4c1e3b2d3e8f7c6e5d4c3b2a1e0f9e8d7c6b5a4e3f2e1d0c9b8a7a0b1f8e8d7c6b5a4e3f2e1d0c9b8a7a6f5e4d3c2b1a0f9e8d7c6b5a4e3f2e1d0a0c9b8a7a6f5e4d3c2b1a0f9e8d7c6b5a4e3f2e1d0c9b8a7a6f5e4d3c2b1a0a0d7c6b5a4e3f2e1d0c9b8a7a6f5e4d3c2b1a0f9e8d7c6b5a4e3f2e1d0c9b8a7a08080"
]
}
]
}
}
```