Skip to main content

PyPI Package - near-tokens

Project description

near-tokens

Python async client for NEAR Protocol token operations and account queries.

Requirements

Python 3.9+

Installation

pip install near-tokens

Quick Start

import asyncio from near_tokens import NearTokensClient

async def main(): async with NearTokensClient() as client: balance = await client.get_balance("alice.near") print(f"Balance: {balance['balance_near']:.4f} NEAR")

asyncio.run(main())

Usage

Account Balance

import asyncio from near_tokens import NearTokensClient

async def main(): async with NearTokensClient() as client: balance = await client.get_balance("wrap.near") print(balance["balance_near"]) print(balance["balance_yocto"]) print(balance["storage_usage"])

asyncio.run(main())

Check Account Exists

import asyncio from near_tokens import NearTokensClient

async def main(): async with NearTokensClient() as client: exists = await client.account_exists("alice.near") print(exists) # True or False

asyncio.run(main())

Block and Gas Price

import asyncio from near_tokens import NearTokensClient

async def main(): async with NearTokensClient() as client: block = await client.get_block() gas_price = await client.get_gas_price() print(block, gas_price)

asyncio.run(main())

Fungible Token (FT) Queries

import asyncio from near_tokens import NearTokensClient

async def main(): async with NearTokensClient() as client: metadata = await client.get_ft_metadata("usdt.tether-token.near") ft_balance = await client.get_ft_balance("usdt.tether-token.near", "alice.near") print(metadata) print(ft_balance)

asyncio.run(main())

Validators

import asyncio from near_tokens import NearTokensClient

async def main(): async with NearTokensClient() as client: validators = await client.get_validators() print(validators)

asyncio.run(main())

Manual Session Management

import asyncio from near_tokens import NearTokensClient

async def main(): client = NearTokensClient(rpc_url="https://rpc.mainnet.near.org") balance = await client.get_balance("alice.near") print(balance) await client.close()

asyncio.run(main())

API Reference

Method Description
get_balance(account_id) NEAR balance in yoctoNEAR and NEAR
account_exists(account_id) Returns True if account exists
get_block() Latest finalized block info
get_gas_price() Current gas price
get_ft_balance(contract_id, account_id) Fungible token balance
get_ft_metadata(contract_id) Fungible token metadata
get_validators() Current epoch validators
close() Close the HTTP session

License

MIT

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

near_tokens-1.0.6883.tar.gz (3.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

near_tokens-1.0.6883-py3-none-any.whl (3.8 kB view details)

Uploaded Python 3

File details

Details for the file near_tokens-1.0.6883.tar.gz.

File metadata

  • Download URL: near_tokens-1.0.6883.tar.gz
  • Upload date:
  • Size: 3.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.15

File hashes

Hashes for near_tokens-1.0.6883.tar.gz
Algorithm Hash digest
SHA256 0d855985d157d0c4d17e8514bb9391f2eb162e6f649f49b69452ec4215d5e883
MD5 7b7bc3e655e2e5e7f534a6b939382dc1
BLAKE2b-256 89b85d7125ff8345ca0630bc6323e764da9c5ae1caef2fc3683cc2aa186ad899

See more details on using hashes here.

File details

Details for the file near_tokens-1.0.6883-py3-none-any.whl.

File metadata

  • Download URL: near_tokens-1.0.6883-py3-none-any.whl
  • Upload date:
  • Size: 3.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.15

File hashes

Hashes for near_tokens-1.0.6883-py3-none-any.whl
Algorithm Hash digest
SHA256 793bd120b7ef227c2b32a2fc19f64346b62d15d1f4031f26868a67e9ed679142
MD5 47b77467742f65fd8c93c16eac8ab8a8
BLAKE2b-256 3a74ed618375290e9654b4e2cfd7dcbddcedaec3b6d1233f53d70f42ba1a2883

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page