Skip to main content

near-state

Async Python client for querying NEAR Protocol on-chain state via RPC.

Requirements

Python 3.9+

Installation

pip install near-state

Quick Start

import asyncio from near_state import NearStateClient

async def main(): async with NearStateClient() as client: balance = await client.get_balance_near("wrap.near") print(f"Balance: {balance} NEAR")

asyncio.run(main())

Usage

Account & Balance

import asyncio from near_state import NearStateClient

async def main(): async with NearStateClient() as client: account = await client.get_account("wrap.near") print(account)

    yocto = await client.get_balance("wrap.near")
    print(f"yoctoNEAR: {yocto}")

    near = await client.get_balance_near("wrap.near")
    print(f"NEAR: {near}")

asyncio.run(main())

Contract State

import asyncio from near_state import NearStateClient

async def main(): async with NearStateClient() as client: state = await client.get_state("wrap.near") print(state)

asyncio.run(main())

Blocks & Transactions

import asyncio from near_state import NearStateClient

async def main(): async with NearStateClient() as client: block = await client.get_block("final") print(block)

    tx = await client.get_transaction(
        "tx-hash-here", "sender.near"
    )
    print(tx)

asyncio.run(main())

Access Keys & Network

import asyncio from near_state import NearStateClient

async def main(): async with NearStateClient() as client: key = await client.get_access_key("wrap.near", "ed25519:pubkey") print(key)

    keys = await client.get_access_key_list("wrap.near")
    print(keys)

    validators = await client.get_validators()
    print(validators)

    info = await client.get_network_info()
    print(info)

asyncio.run(main())

Custom RPC Endpoint

from near_state import NearStateClient

client = NearStateClient(rpc_url="https://rpc.testnet.near.org")

API Reference

Method Description
get_account(account_id) Account info
get_balance(account_id) Balance in yoctoNEAR
get_balance_near(account_id) Balance in NEAR
get_state(account_id, prefix_base64) Contract state
get_block(block_id) Block details
get_transaction(tx_hash, sender_id) Transaction details
get_validators() Current validators
get_access_key(account_id, public_key) Single access key
get_access_key_list(account_id) All access keys
get_network_info() Network info

License

MIT

Metadata

Release files for near-state 1.0.29317

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for near-state 1.0.29317
File Size Uploaded
near_state-1.0.29317.tar.gz 3.2 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for near-state 1.0.29317
File Interpreter ABI Platform
near_state-1.0.29317-py3-none-any.whl Python 3 none any Details

Total release size: 6.6 kB

Release files / near_state-1.0.29317.tar.gz

Download URL near_state-1.0.29317.tar.gz
Size 3.2 kB
Tags Source
SHA-256 checksum
How to use checksums
8de500cc626aec3add595b721a87a3821f8fd6f12749c05ca317e904918ecef9
BLAKE2b-256 checksum
How to use checksums
26f0829db7a8d338ce874b3cbb7b711452a52a3371c51fb67bf764de1c1dfdf3
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.11.15

Release files / near_state-1.0.29317-py3-none-any.whl

Download URL near_state-1.0.29317-py3-none-any.whl
Size 3.4 kB
Tags Python 3
SHA-256 checksum
How to use checksums
cbb3c41833da55d4e2f67f3c54b1f7aa3e803e46051b7dbddb2cdd6d63893100
BLAKE2b-256 checksum
How to use checksums
cae43ee5fc74b4da21b043f3403605d099b8e09f74be90007372093fc9950ecb
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.11.15

Release history Release notifications | RSS feed

This release

1.0.29317 This release

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page