Skip to main content

FastAPI service for NEAR Protocol RPC, account data, and contract view calls

Project description

near-fastapi

Production-ready FastAPI service for NEAR Protocol.

This package exposes a clean REST API for common NEAR operations:

  • Network status (mainnet/testnet)
  • Account details and access keys
  • Contract code hash
  • Contract view function calls with JSON decoding

Install

pip install near-fastapi

Run

near-fastapi --host 0.0.0.0 --port 8080

Open docs:

  • Swagger UI: http://localhost:8080/docs
  • ReDoc: http://localhost:8080/redoc

API Endpoints

  • GET /health
  • GET /v1/networks
  • GET /v1/status?network=mainnet
  • GET /v1/accounts/{account_id}?network=mainnet
  • GET /v1/accounts/{account_id}/keys?network=mainnet
  • GET /v1/contracts/{account_id}/code-hash?network=mainnet
  • POST /v1/contracts/{account_id}/view

Contract View Example

curl -X POST http://localhost:8080/v1/contracts/social.near/view \
  -H 'Content-Type: application/json' \
  -d '{
    "method": "get",
    "args": {"keys": ["near.social/root"]},
    "network": "mainnet"
  }'

Python Integration Example

from fastapi import FastAPI
from near_fastapi.app import create_app

app: FastAPI = create_app()

NEAR Integration Notes

  • Uses official NEAR RPC endpoints:
    • https://rpc.mainnet.near.org
    • https://rpc.testnet.near.org
  • Returns RPC errors as clear HTTP errors.
  • Validates account IDs to reduce bad requests early.

Development

python -m venv .venv
source .venv/bin/activate
pip install -e .[dev]
pytest -q

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_fastapi-0.1.0.tar.gz (6.0 kB view details)

Uploaded Source

Built Distribution

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

near_fastapi-0.1.0-py3-none-any.whl (7.3 kB view details)

Uploaded Python 3

File details

Details for the file near_fastapi-0.1.0.tar.gz.

File metadata

  • Download URL: near_fastapi-0.1.0.tar.gz
  • Upload date:
  • Size: 6.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.9.6

File hashes

Hashes for near_fastapi-0.1.0.tar.gz
Algorithm Hash digest
SHA256 ff036bf81ca57f23b09457adc8b444fdc718f8dcfb801596bee3bb201de1c15a
MD5 708991b8370d9f1ca0cdcc418e69ccd9
BLAKE2b-256 82ae24e0b2344fa2599cad5855729fe1719b07aeef47d0288d5e4bfe3e20999e

See more details on using hashes here.

File details

Details for the file near_fastapi-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: near_fastapi-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 7.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.9.6

File hashes

Hashes for near_fastapi-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 cb8ef1a61a5f7e3196c13788b701c3523b0781d94601f0d6b5b45e3eccb53944
MD5 9ecd4c8d40d706e0b018aa9960a4f905
BLAKE2b-256 2461d8202b48bbf6cce6fe74f0c1a31d5308c798e03fbbaf4f86cc68d91f80c0

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