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_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
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file near_langchain_tx_builder-0.1.0.tar.gz.
File metadata
- Download URL: near_langchain_tx_builder-0.1.0.tar.gz
- Upload date:
- Size: 8.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.9.6
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
d40b17c94b60f9017ba0acaa9f3c0fe269087cd7ba9f1b60f493fa3f0276d74b
|
|
| MD5 |
c2b82df67ba3ec10a7290f59b78f3809
|
|
| BLAKE2b-256 |
70b2497e118e4a3852ba5992149548da48b54d6c78708a4c7cee9b05607b18ff
|
File details
Details for the file near_langchain_tx_builder-0.1.0-py3-none-any.whl.
File metadata
- Download URL: near_langchain_tx_builder-0.1.0-py3-none-any.whl
- Upload date:
- Size: 10.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.9.6
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
6e971cfcea14499167e888a213ce6006025433a53d941a15240463bf5c9acba6
|
|
| MD5 |
ede6903aba9ef6b4899520f227f8a89a
|
|
| BLAKE2b-256 |
bf5082bf61c30568e4692aa0bac156120e4f49014621591cee014c5447a42d07
|