SDKs overview
Nownodes provides access to various blockchain networks through its API, allowing developers to interact with nodes without the overhead of running and maintaining them. While Nownodes primarily offers a RESTful API accessible via standard HTTP requests, it also supports specific SDKs and libraries to simplify integration for different programming environments. These tools abstract the low-level API calls, offering language-native methods for common operations like retrieving blockchain data, sending transactions, and monitoring network activity. The official documentation emphasizes direct API interaction using cURL examples, providing a universal method for integration across any language or platform capable of making HTTP requests Nownodes API documentation.
The core functionality accessible via Nownodes's API, and subsequently through any integrating SDK or library, includes:
- Blockchain Data Retrieval: Querying network status, block information, transaction details, and account balances across supported chains.
- Transaction Broadcasting: Submitting signed transactions to the network.
- Smart Contract Interaction: Calling read-only methods on smart contracts or sending transactions to execute contract functions.
- WebSockets: For real-time data streams and event notifications from blockchain networks.
Developers often utilize existing blockchain client libraries (e.g., Web3.js for Ethereum-compatible chains) and configure them to point to Nownodes's API endpoints. This approach leverages established client-side tooling while benefiting from Nownodes's managed node infrastructure Nownodes integration guides.
Official SDKs by language
Nownodes provides client libraries that wrap its API for specific programming languages, simplifying the process of making API calls and handling responses. These official SDKs aim to reduce boilerplate code and streamline integration for developers working within particular ecosystems.
| Language | Package Name | Installation Command | Maturity |
|---|---|---|---|
| Python | nownodes-py |
pip install nownodes-py |
Stable |
| JavaScript/TypeScript | nownodes-js |
npm install nownodes-js |
Stable |
| Go | nownodes-go |
go get github.com/nownodes/nownodes-go |
Beta |
Each SDK is designed to align with the idiomatic patterns of its respective language, providing methods that map directly to Nownodes's API endpoints. This allows developers to interact with blockchain data using familiar syntax and data structures.
Installation
Installing Nownodes SDKs typically follows the standard package management practices for each programming language. Before installation, ensure you have the appropriate language runtime and package manager set up in your development environment.
Python SDK Installation
The Python SDK can be installed using pip, the Python package installer. It requires Python 3.6 or higher.
pip install nownodes-py
After installation, you can import the library into your Python projects.
JavaScript/TypeScript SDK Installation
For JavaScript and TypeScript projects, the SDK is available via npm (Node Package Manager) or yarn. It is compatible with Node.js environments and modern web browsers.
npm install nownodes-js
or
yarn add nownodes-js
You can then import it into your modules using require for CommonJS or import for ES modules.
Go SDK Installation
The Go SDK is installed using the go get command, which fetches the package from its repository.
go get github.com/nownodes/nownodes-go
Once installed, you can import the package into your Go source files and utilize its functions.
Quickstart example
This quickstart demonstrates how to use the Nownodes Python SDK to retrieve the latest block number for the Ethereum network. You will need a Nownodes API key, which can be obtained by signing up on the Nownodes homepage.
Prerequisites
- Python 3.6+ installed.
nownodes-pySDK installed (pip install nownodes-py).- A Nownodes API key.
Python Example: Get Latest Ethereum Block
First, set your Nownodes API key as an environment variable or replace YOUR_API_KEY in the script below.
import os
from nownodes_py import NownodesClient
# Replace with your actual API key or set as an environment variable
API_KEY = os.getenv("NOWNODES_API_KEY", "YOUR_API_KEY")
# Initialize the client with your API key
client = NownodesClient(api_key=API_KEY)
try:
# Specify the blockchain network (e.g., 'eth' for Ethereum)
network = 'eth'
# Call the method to get the latest block number
# The actual method name might vary based on the SDK version and API endpoint
# Refer to the official Nownodes Python SDK documentation for exact method calls
# For Ethereum, this often involves calling a JSON-RPC method like 'eth_blockNumber'
# Example using a generic RPC call function (if available in the SDK)
# This is illustrative; actual SDK methods might be more specific.
response = client.call_rpc(network, 'eth_blockNumber', [])
if response and 'result' in response:
latest_block_hex = response['result']
latest_block_decimal = int(latest_block_hex, 16)
print(f"Latest Ethereum Block Number: {latest_block_decimal} (Hex: {latest_block_hex})")
else:
print(f"Failed to retrieve latest block: {response}")
except Exception as e:
print(f"An error occurred: {e}")
This example demonstrates the basic structure of initializing the client and making a request. For specific methods and parameters for different blockchains, consult the Nownodes API documentation and the respective SDK's documentation.
Community libraries
Beyond the official SDKs, the broader blockchain development ecosystem offers numerous general-purpose client libraries that can be configured to work with Nownodes's API endpoints. These libraries are not maintained by Nownodes but are widely used for interacting with various blockchain networks.
-
Web3.js (JavaScript/TypeScript): A popular library for interacting with the Ethereum blockchain and EVM-compatible networks. Developers can configure Web3.js to use Nownodes's Ethereum endpoint as its provider Web3.js documentation. This allows for seamless integration with existing dApps and tools built on Web3.js.
const Web3 = require('web3'); const NOWNODES_ETH_RPC_URL = 'https://eth.nownodes.io/YOUR_API_KEY'; // Replace with your actual Nownodes endpoint const web3 = new Web3(NOWNODES_ETH_RPC_URL); async function getEthBlockNumber() { try { const blockNumber = await web3.eth.getBlockNumber(); console.log('Latest Ethereum Block Number:', blockNumber); } catch (error) { console.error('Error fetching Ethereum block number:', error); } } getEthBlockNumber(); -
Ethers.js (JavaScript/TypeScript): Another robust and widely used library for Ethereum development, often preferred for its clean API and comprehensive features. Similar to Web3.js, Ethers.js can be configured with a Nownodes provider Ethers.js documentation.
const { JsonRpcProvider } = require('ethers'); const NOWNODES_ETH_RPC_URL = 'https://eth.nownodes.io/YOUR_API_KEY'; // Replace with your actual Nownodes endpoint const provider = new JsonRpcProvider(NOWNODES_ETH_RPC_URL); async function getEthBlockNumberEthers() { try { const blockNumber = await provider.getBlockNumber(); console.log('Latest Ethereum Block Number (Ethers.js):', blockNumber); } catch (error) { console.error('Error fetching Ethereum block number with Ethers.js:', error); } } getEthBlockNumberEthers(); -
Web3.py (Python): The Python equivalent of Web3.js, providing comprehensive tools for interacting with Ethereum and EVM-compatible chains. It can be configured to connect to Nownodes's Ethereum endpoints Web3.py documentation.
from web3 import Web3 import os NOWNODES_ETH_RPC_URL = os.getenv("NOWNODES_ETH_RPC_URL", "https://eth.nownodes.io/YOUR_API_KEY") # Replace with your actual Nownodes endpoint w3 = Web3(Web3.HTTPProvider(NOWNODES_ETH_RPC_URL)) if w3.is_connected(): latest_block = w3.eth.block_number print(f"Latest Ethereum Block Number (Web3.py): {latest_block}") else: print("Failed to connect to Ethereum node via Nownodes.") -
Bitcoin RPC client libraries (various languages): For Bitcoin and Bitcoin-fork networks, various RPC client libraries exist in languages like Python (
python-bitcoinrpc), JavaScript (bitcoinjs-libwith custom RPC calls), and Go (btcd/rpcclient). These can be adapted to send requests to Nownodes's Bitcoin endpoints python-bitcoinrpc GitHub.
When using community libraries, developers are responsible for configuring them correctly with Nownodes's API endpoints and API keys, which are typically passed as part of the provider URL or as authentication headers. Always refer to the specific community library's documentation for detailed configuration instructions alongside the Nownodes service documentation.