NEAR Protocol (NEAR)
NEAR Protocol API Reference for seamless interaction with NEAR nodes, enabling scalable, developer-friendly, decentralised applications with low fees and fast transaction finality.
NEAR Protocol is a developer-friendly Layer 1 blockchain built to make decentralised applications (dApps) fast, user-friendly, and scalable.
It uses a Proof of Stake (PoS) consensus mechanism to validate transactions while sharding the network into smaller pieces that work in parallel. This design allows NEAR to process transactions quickly and efficiently with low fees.
Smart contracts on NEAR can be written in:
Beyond just being a blockchain, NEAR is also a platform for AI agents. Its vision is to create a future of User-Owned AI, where artificial intelligence and autonomous agents serve their users — not corporations.
You can do the following with NEAR Protocol API:
Get block, transaction and network information
Get account information
Send and validate transactions
Get estimate of gas and fees
Interact with smart contracts
Monitor network health
NEAR Network Support
Mainnet
JSON RPC
Each method will provide you with the following:
Clear description of functionality and use cases
Required input parameters
Sample requests and responses
Supported network
Code example
Integration
Quickstart
In this section, you will learn how to make your first call with either:
Axios
Python
Quickstart with Axios
Before you begin, you must have already installed npm or yarn on your local machine. If not, check out npm or yarn.
Set up your project using this command:
For npm:
mkdir near-api-quickstart cd near-api-quickstart npm init --yesOr yarn:
mkdir near-api-quickstart cd near-api-quickstart yarn init --yes
This creates a project directory named near-api-quickstart and initialises a Node.js project within it.
Install Axios using this command: Using npm:
npm install axiosUsing yarn:
yarn add axiosCreate a new file and name it
index.js. This is where you will make your first call.Set ES module
"type": "module"in yourpackage.json.Add the following code to the file (
index.js):import axios from "axios" let data = JSON.stringify({ "jsonrpc": "2.0", "method": "gas_price", "params": [ 169528908 ], "id": "getblock.io" }); let config = { method: 'post', maxBodyLength: Infinity, url: 'https://go.getblock.io/<ACCESS_TOKEN>', headers: { 'Content-Type': 'application/json' }, data : data }; axios.request(config) .then((response) => { console.log(JSON.stringify(response.data)); }) .catch((error) => { console.log(error); });Replace
<ACCESS_TOKEN>with your actual access token from GetBlock.Run the script:
node index.jsThe current gas price will log in the console like this:
{ "jsonrpc": "2.0", "result": { "gas_price": "100000000" }, "id": "getblock.io" }
Quickstart with Python and Requests
Before you begin, you must have installed Python and Pip on your local machine.
Set up your project using this command:
mkdir near-api-quickstart cd near-api-quickstartSet up a virtual environment to isolate dependencies:
python -m venv venv source venv/bin/activate # On Windows, use venv\Scripts\activateInstall the requests library:
pip install requestsCreate a new file called
main.pyand insert the following code:import requests import json url = "https://go.getblock.io/<ACCESS_TOKEN>" payload = json.dumps({ "jsonrpc": "2.0", "method": "gas_price", "params": [ 169528908 ], "id": "getblock.io" }) headers = { 'Content-Type': 'application/json' } response = requests.request("POST", url, headers=headers, data=payload) print(response.text)Replace
<ACCESS_TOKEN>with your actual access token from GetBlock.Run the script:
python main.py
Method Grouping
Network Information
network_info
validators
status
Blocks and Transactions
block
chunk
tx
broadcast_tx_async
broadcast_tx_commit
Contracts
call_function
query(view_code)
query(view_state)
Gas and Fees
gas_price
Account
query(view_account)
query(view_account_basic)
Last updated
Was this helpful?