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

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

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.0.tar.gz (8.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.0-py3-none-any.whl (10.9 kB view details)

Uploaded Python 3

File details

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

File metadata

File hashes

Hashes for near_langchain_tx_builder-0.1.0.tar.gz
Algorithm Hash digest
SHA256 d40b17c94b60f9017ba0acaa9f3c0fe269087cd7ba9f1b60f493fa3f0276d74b
MD5 c2b82df67ba3ec10a7290f59b78f3809
BLAKE2b-256 70b2497e118e4a3852ba5992149548da48b54d6c78708a4c7cee9b05607b18ff

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for near_langchain_tx_builder-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 6e971cfcea14499167e888a213ce6006025433a53d941a15240463bf5c9acba6
MD5 ede6903aba9ef6b4899520f227f8a89a
BLAKE2b-256 bf5082bf61c30568e4692aa0bac156120e4f49014621591cee014c5447a42d07

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