A robust and flexible solution for building and sending transactions and queries to the NEAR Protocol blockchain, with support for both synchronous and asynchronous operations.
NEAR Transaction and Query Builder is a Rust library that simplifies the interaction with NEAR Protocol smart contracts. It provides an intuitive builder pattern interface for constructing and sending transactions and queries, with comprehensive error handling and timeout management.
- Transaction Building: Easy-to-use builder pattern for transaction construction
- Query Management: Simplified interface for contract queries
- Nonce Management: Automatic nonce handling for transactions
- Flexible Configuration: Customizable timeouts and RPC endpoints
- Error Handling: Robust error management with custom error types
- Multiple Environments: Support for MainNet, TestNet, and local development
- Asynchronous Operations: Built on Tokio for efficient async/await patterns
-
Transaction Management:
- Transaction building with
TxBuilder
- Automatic nonce handling via
NonceManager
- Transaction sending through
TxSender
- Transaction building with
-
Query Management:
- Query construction with
QueryBuilder
- Efficient query execution via
QuerySender
- Query construction with
-
High-level Interfaces:
NearTxSender
for transaction operationsNearQxSender
for query operations
use near_tx_qx_builder::NearTxSender;
use serde_json::json;
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error + Send + Sync>> {
let tx_sender = NearTxSender::builder("https://rpc.testnet.near.org")
.account_sender("sender.testnet")
.account_receiver("receiver.testnet")
.use_private_key("your-private-key")
.method_name("some_method")
.args(json!({
"param1": "value1",
"param2": "value2"
}))
.build()?;
let result = tx_sender.send_transaction().await?;
println!("Transaction result: {:?}", result);
Ok(())
}
use near_tx_qx_builder::NearQxSender;
use serde_json::json;
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error + Send + Sync>> {
let qx_sender = NearQxSender::builder("https://rpc.testnet.near.org")
.account_receiver("contract.testnet")
.method_name("view_method")
.args(json!({
"param1": "value1"
}))
.build()?;
let result = qx_sender.send_query().await?;
println!("Query result: {}", result);
Ok(())
}
pub struct NearTxSender {
signer: Arc<InMemorySigner>,
nonce_manager: NonceManager,
tx_sender: TxSender,
tx_builder: TxBuilder,
}
pub struct NearQxSender {
query_sender: QuerySender,
account_id_receiver: String,
method_name: String,
args: Value,
}
- Rust 1.54 or higher
- Tokio runtime
- NEAR SDK
cargo build
cargo test
- Secure private key handling
- Proper error handling
- Transaction timeout management
- Nonce collision prevention
- RPC connection security
The library implements comprehensive error handling for:
- RPC connection issues
- Transaction failures
- Query failures
- Invalid parameters
- Timeout scenarios
This implementation was built to facilitate easier interaction with the NEAR Protocol blockchain and simplify the development of decentralized applications.