Skip to content

Commit d074015

Browse files
authored
fix: use finalized block hash for transaction signing (#116)
1 parent 3711beb commit d074015

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

api/src/signer/mod.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ use near_api_types::{
120120
delegate_action::{NonDelegateAction, SignedDelegateAction},
121121
PrepopulateTransaction, SignedTransaction, Transaction, TransactionV0,
122122
},
123-
AccountId, BlockHeight, CryptoHash, Nonce, PublicKey, SecretKey, Signature,
123+
AccountId, BlockHeight, CryptoHash, Nonce, PublicKey, Reference, SecretKey, Signature,
124124
};
125125

126126
use borsh::{BorshDeserialize, BorshSerialize};
@@ -537,6 +537,9 @@ impl Signer {
537537
/// Fetches the transaction nonce and block hash associated to the access key. Internally
538538
/// caches the nonce as to not need to query for it every time, and ending up having to run
539539
/// into contention with others.
540+
///
541+
/// Uses finalized block hash to avoid "Transaction Expired" errors when sending transactions
542+
/// to load-balanced RPC endpoints where different nodes may be at different chain heights.
540543
#[instrument(skip(self, network), fields(account_id = %account_id))]
541544
pub async fn fetch_tx_nonce(
542545
&self,
@@ -548,6 +551,7 @@ impl Signer {
548551

549552
let nonce_data = crate::account::Account(account_id.clone())
550553
.access_key(public_key)
554+
.at(Reference::Final)
551555
.fetch_from(network)
552556
.await
553557
.map_err(|e| SignerError::FetchNonceError(Box::new(e)))?;

0 commit comments

Comments
 (0)