Skip to main content

LangChain tools to build, validate, and simulate NEAR transactions

Project description

near-langchain-tx-builder

LangChain tools for building and simulating NEAR transactions before execution.

Features

  • Build transfer transactions
  • Build function-call transactions
  • Batch multiple actions into one transaction
  • Simulate transactions before sending (validation + account checks + optional RPC preflight)
  • Estimate gas and rough transaction cost in NEAR
  • Reusable transaction templates
  • Clear, structured error messages

Install

pip install near-langchain-tx-builder

Quick Start (LangChain)

from near_langchain_tx_builder import get_near_transaction_tools

tools = get_near_transaction_tools()

# Tool names:
# - near_build_transfer_tx
# - near_build_function_call_tx
# - near_build_batch_tx
# - near_estimate_tx_gas
# - near_simulate_tx
# - near_apply_tx_template
# - near_list_tx_templates

Manual Usage

from near_langchain_tx_builder import NEARTransactionBuilder

builder = NEARTransactionBuilder()

tx = builder.build_transfer_tx(
    signer_id="alice.near",
    receiver_id="bob.near",
    amount_near="1.5",
    network="mainnet",
)

estimate = builder.estimate_gas(tx)
simulation = builder.simulate_transaction(tx, check_accounts=False)

Transaction Templates

Built-in templates:

  • simple_transfer
  • ft_transfer
  • nft_transfer
  • contract_call

Example:

tx = builder.apply_template(
    template_name="ft_transfer",
    signer_id="alice.near",
    receiver_id="usdc.fakes.testnet",
    variables={
        "method_name": "ft_transfer",
        "args": {"receiver_id": "bob.near", "amount": "1000000"},
        "deposit_near": "0.000000000000000000000001",
        "gas_tgas": 30,
    },
    network="testnet",
)

Error Handling

Methods raise NEARTxBuilderError with machine-readable codes:

  • invalid_account_id
  • invalid_amount
  • invalid_action
  • rpc_error
  • simulation_error

Notes on Simulation

NEAR RPC does not provide a full dry-run for unsigned arbitrary state-changing transactions. This package simulates via:

  • strict local validation,
  • optional account existence checks,
  • gas/cost estimation using RPC gas price,
  • optional preflight call_function for likely view-compatible calls.

License

MIT

Reliability

  • NEAR RPC fallback endpoints with retries/backoff
  • Improved RPC error details for easier debugging
  • CI workflow (tests + build)

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_langchain_tx_builder-0.1.1.tar.gz (9.5 kB view details)

Uploaded Source

Built Distribution

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

near_langchain_tx_builder-0.1.1-py3-none-any.whl (11.5 kB view details)

Uploaded Python 3

File details

Details for the file near_langchain_tx_builder-0.1.1.tar.gz.

File metadata

File hashes

Hashes for near_langchain_tx_builder-0.1.1.tar.gz
Algorithm Hash digest
SHA256 5ea07203fdc70579d6b4af26fd134d9e909041d3d95a892efb017ac3b149d4d3
MD5 1e96080b7e7fe09fa710251b76647379
BLAKE2b-256 bf7a7a04f583bd741b7c922bbbdeded21ca844c415cdbaa8a2a94dd3d92f82be

See more details on using hashes here.

File details

Details for the file near_langchain_tx_builder-0.1.1-py3-none-any.whl.

File metadata

File hashes

Hashes for near_langchain_tx_builder-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 72c00d8afe13946fe4fb92c42f34e4f7b4cc04926a5c9305d5b4467949011ed2
MD5 faafd535a1157c97beb5fca63a04ba63
BLAKE2b-256 7f89489e435d3a2c4986153f4119a880aa85b88831a4353178b0c828a631f27d

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