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_transferft_transfernft_transfercontract_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_idinvalid_amountinvalid_actionrpc_errorsimulation_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_functionfor 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)
Metadata
Release files for near-langchain-tx-builder 0.1.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| near_langchain_tx_builder-0.1.1.tar.gz | 9.5 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| near_langchain_tx_builder-0.1.1-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 21.0 kB
Release files / near_langchain_tx_builder-0.1.1.tar.gz
| Download URL | near_langchain_tx_builder-0.1.1.tar.gz |
|---|---|
| Size | 9.5 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
5ea07203fdc70579d6b4af26fd134d9e909041d3d95a892efb017ac3b149d4d3
|
|
BLAKE2b-256 checksum How to use checksums |
bf7a7a04f583bd741b7c922bbbdeded21ca844c415cdbaa8a2a94dd3d92f82be
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.9.6
|
Release files / near_langchain_tx_builder-0.1.1-py3-none-any.whl
| Download URL | near_langchain_tx_builder-0.1.1-py3-none-any.whl |
|---|---|
| Size | 11.5 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
72c00d8afe13946fe4fb92c42f34e4f7b4cc04926a5c9305d5b4467949011ed2
|
|
BLAKE2b-256 checksum How to use checksums |
7f89489e435d3a2c4986153f4119a880aa85b88831a4353178b0c828a631f27d
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.9.6
|