Mantle API Overview

Welcome to the Mantle API Quickstart and Reference Guide. This guide provides everything you need to start building on Mantle using dRPC’s JSON-RPC API. Whether you're retrieving account balances, fetching block details, executing transactions, or estimating gas fees, this comprehensive guide will help you integrate Mantle seamlessly into your applications.

This page includes:

  • A Quickstart Guide to help you set up and make your first Mantle API request.
  • A detailed list of all Mantle API methods, categorized for easy reference.

Scroll to API Methods

Mantle API Quickstart#

To get started with building on Mantle using dRPC's Mantle RPC API, follow these steps:

1. Create a dRPC Account or Use Public Mantle RPC endpoints

By signing up for a free dRPC account, you can access their Premium Mantle RPC endpoints.

Public endpoints:

HTTPS

https://mantle.drpc.org/

WSS:

wss://mantle.drpc.org

2. Set Up Your Development Environment

RPC can be requested in various ways (opens in a new tab). In this example, we are going to use Node.js. Ensure you have Node.js (opens in a new tab) and npm installed on your system. You can verify their installation by running:

node -v
npm -v

If not installed, download and install them from the official Node.js website (opens in a new tab).

3. Initialize Your Project

Create a new directory for your project and initialize it:

mkdir Mantle-drpc-quickstart
cd Mantle-drpc-quickstart
npm init --yes

4. Install Axios

Axios is a popular HTTP client for making API requests. Install it using npm:

npm install axios

5. Obtain dRPC Endpoint

Log in to your dRPC account and navigate to the Mantle RPC endpoints section. Copy the HTTPS endpoint URL for the Mantle Mainnet.

6. Write Your First Script

Create an index.js file in your project directory and add the following code:

const axios = require('axios');
 
const url = 'https://lb.drpc.org/ogrpc?network=mantle&dkey=YOUR_DRPC_API_KEY';
 
const payload = {
  jsonrpc: '2.0',
  id: 1,
  method: 'eth_blockNumber',
  params: []
};
 
axios.post(url, payload)
  .then(response => {
    console.log('The latest block number is', parseInt(response.data.result, 16));
  })
  .catch(error => {
    console.error('Error fetching block number:', error);
  });

Replace ‘https://lb.drpc.org/ogrpc?network=mantle&dkey=YOUR_DRPC_API_KEY' with the actual endpoint URL you obtained from dRPC.

7. Run Your Script

Execute your script using Node.js:

node index.js

You should see the latest Mantle block number printed in your console.

Additional Information

dRPC offers various features such as high performance nodes, access to multiple chains.

By following these steps, you can start building on Mantle using dRPC's reliable and efficient RPC endpoints. For more details, visit their Mantle Documentation (opens in a new tab)

Mantle API Methods#

Mantle is a Layer 2 scaling solution for Ethereum, designed to offer faster transactions and lower fees while leveraging Ethereum’s security and decentralized infrastructure.

Accounts info#

Retrieve key data about accounts on the Mantle network

eth_accounts : Retrieves a list of accounts controlled by the connected client.
eth_getBalance : Returns the balance of an account.
eth_getCode : Fetches the contract code at a given address.
eth_getProof : Provides a Merkle proof for an account’s state.
eth_getStorageAt : Retrieves stored data at a specific slot in the account's storage.

Blocks info#

Provides methods to retrieve detailed information about specific blocks

eth_blockNumber : Retrieves the latest block number.
eth_getBlockByHash : Fetches block details by its hash.
eth_getBlockByHash#full : Retrieves full block details by hash.
eth_getBlockByNumber : Fetches block details by block number.
eth_getBlockByNumber#full : Retrieves full block details by block number.
eth_newBlockFilter : Available only on paid tier. Creates a filter for monitoring new blocks.
eth_getBlockTransactionCountByHash : Returns the number of transactions in a block by hash.
eth_getBlockTransactionCountByNumber : Retrieves the transaction count for a block by number.

Chain info#

Provides crucial details about the state and performance of the Mantle network

eth_chainId : Retrieves the Mantle network's chain ID.
net_listening : Indicates whether the node is actively listening for network connections.
net_version : Returns the current network version.
net_peerCount : Displays the number of peers connected to the node.
eth_syncing : Shows the synchronization status of the node.
eth_hashrate : Provides the current mining hashrate.

Debug and trace#

Offers advanced debugging and tracing capabilities

debug_traceBlockByHash : Traces the execution of a block by its hash.
debug_traceBlockByNumber : Traces the execution of a block by its number.
debug_traceTransaction : Provides detailed trace information for a specific transaction.

Event logs#

Provides methods for filtering and retrieving event logs

eth_getLogs : Retrieves logs from smart contracts based on filter criteria.
eth_newFilter : Available only on paid tier. Creates a filter for tracking specific events.
eth_getFilterChanges : Available only on paid tier. Retrieves changes for an active filter since its last check.
eth_uninstallFilter : Uninstalls an active filter.
eth_getFilterLogs : Available only on paid tier. Fetches logs from a previously created filter.

Executing transactions#

Provides essential methods for sending transactions, executing smart contract calls, and performing on-chain operations

eth_call : Executes a read-only call to a smart contract without making any state changes.
eth_sendRawTransaction : Sends a raw, signed transaction to the Mantle network for execution.

Gas estimation#

Provides methods to estimate the gas required for transactions and fetch information related to gas prices

eth_feeHistory : Retrieves historical gas fees over a specified range of blocks.
eth_estimateGas : Estimates the gas needed for a transaction.
eth_gasPrice : Returns the current gas price in the network.
eth_createAccessList : Generates an access list to improve gas efficiency.
eth_maxPriorityFeePerGas : Provides the maximum priority fee for a transaction.

Getting uncles#

Retrieves information about "uncle" blocks, which are valid but not included in the blockchain.

eth_getUncleCountByBlockHash : Returns the number of uncle blocks for a given block by its hash.
eth_getUncleCountByBlockNumber : Retrieves the number of uncle blocks for a specific block by its number.

Mining#

Contains methods related to mining operations

eth_mining : Indicates whether the node is actively mining new blocks.

Subscriptions#

Allows to subscribe to specific events

eth_subscribe : Subscribes to events like new blocks, pending transactions, or logs.
eth_unsubscribe : Unsubscribes from an active event subscription.

Transactions info#

Provides methods to retrieve transaction details, counts, and receipts

eth_getTransactionByHash : Retrieves details of a transaction by its hash.
eth_getTransactionCount : Returns the number of transactions sent from an address.
eth_getTransactionReceipt : Fetches the receipt for a processed transaction.
eth_getTransactionByBlockHashAndIndex : Retrieves a transaction from a block by hash and index.
eth_getTransactionByBlockNumberAndIndex : Retrieves a transaction by block number and index.

Web3#

Provides methods for retrieving basic network configuration data related to nodes

web3_clientVersion : Returns the version of the Mantle node client in use.
web3_sha3 : Computes the Keccak-256 (SHA3) hash of the provided input data.