Moralis Onboarding

Welcome to Moralis v2! Build dapps efficiently and quickly using our robust cross-chain APIs for NFTs, EVMs, Web3 authentication, and more.

Create Your Account

Create a free account to get started.

Get Your API Key

  1. Go to https://admin.moralis.io/web3apis.
  2. Click on the copy icon for your API key:

Your First Moralis API Request

Now that you have the API key, let's try it!

You can now use the Moralis API to make a request to /getBlockAPI using Javascript, which will give you the block's content by block number or hash.

The API request example below will retrieve the block content for block number 1000.

You can create an API request using any of your favorite programming languages.

Request:

const options = {method: 'GET', headers: {Accept: 'application/json', 'X-API-Key': 'your API Key'}};

fetch('https://deep-index.moralis.io/api/v2/block/1000?chain=eth', options)
  .then(response => response.json())
  .then(response => console.log(response))
  .catch(err => console.error(err));

Response:

{
  "timestamp": "2015-07-30T16:02:18.000Z",
  "number": "1000",
  "hash": "0x5b4590a9905fa1c9cc273f32e6dc63b4c512f0ee14edc6fa41c26b416a7b5d58",
  "parent_hash": "0xc31b362e591aa07faa977dbc492ae43cd47eef291920435153bbbf3acaf2fc2f",
  "nonce": "0xeb610e766452a801",
  "sha3_uncles": "0x1dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347",
  "logs_bloom": "0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000",
  "transactions_root": "0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421",
  "state_root": "0x97fb274dbf35776cf0837c76438bb0804ea7b6152da3c8b53c663caf00e17be5",
  "receipts_root": "0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421",
  "miner": "0xbb7b8287f3f0a933474a79eae42cbca977791171",
  "difficulty": "27800789535",
  "total_difficulty": "22019797038325",
  "size": "544",
  "extra_data": "0x476574682f4c5649562f76312e302e302f6c696e75782f676f312e342e32",
  "gas_limit": "5000",
  "gas_used": "0",
  "transaction_count": "0",
  "base_fee_per_gas": "0",
  "transactions": []
}

Congratulations! You just made your first Moralis API request!

Getting Started with the NodeJS SDK

Here's how to get started with the Moralis NodeJS SDK.

Install Moralis

Install the package via npm:

npm install moralis

Initialize Moralis

The npm module is the easiest way to integrate the Moralis SDK into JavaScript.

After your dependency is added, you simply need to initialize Moralis via the start method and paste the API key you copied:

import Moralis from 'moralis';  
Moralis.start({  
  apiKey: '\<YOUR_API_KEY>',  
});

From here, you can refer to our tutorials and how-to guides to build more.

Have fun!


Did this page help you?