Sending Ethereum Transaction and setting the "nonce" value

WARNING:

Customising gas fees and "nonce" values can have serious consequences. We would strongly advise all customers to select "FAST" transaction speed from API, iOS or TrustVault Web or you run the risk of transactions getting stuck.

This article aims to explain how TrustVault works when setting nonce values for Ethereum transactions.

Firstly, it's worth noting that TrustVault generally treats API usage as an advanced feature and allows operations that are more complex. This could lead to issues if API users are not aware of how the Ethereum network operates.

Sending Ethereum transactions with TrustVault

When you use TrustVault via the Web or the mobile App, TrustVault attempts to construct transactions that have a high chance of being accepted by the Ethereum network quickly. This means TrustVault will select the appropriate gasPrice, gasLimit, and nonce values for the transaction. If you are unsure what these terms mean there are some articles to explain:

How is the nonce value determined?

This value cannot be set manually unless you use the API and even then it is an optional value.

Normally, if you try to create a transaction (without passing a nonce value), TrustVault will give an error if you already have a transaction pending (awaiting a signature from other users). This is to protect you from creating transactions out of sequence that may cause problems if you fail to sign one or sign them out of order.

If you don't have any pending transactions, TrustVault will allow you to create a new transaction and will select the nonce value for the transaction by querying the network and checking any transactions inside TrustVault.

NB: Due to the distributed nature of blockchains, it is possible (although generally unlikely) for the nonce value selected by TrustVault to be sometimes incorrect.

Setting the nonce from the API

If you are using the API, TrustVault allows more flexibility and allows you to set the nonce directly yourself. This is useful for several reasons:

  1. You can send more transactions at once, effectively "batched" for signing later.
  2. You can change an existing transaction by increasing the gasPrice.
  3. You can control exactly how you send transactions.

Setting the nonce value in the API changes the behavior of TrustVault slightly. If you set the nonce, it is implied that you are using an advanced feature and are tracking the nonce values yourselves. Thus, TrustVault will NOT perform a check to see if there are existing pending transactions and will accept any integer value you send (nonce must be >= 0).

This allows you to push many more transactions into the system for signing. However, be aware of the following:

  • You can send a transaction with the same nonce multiple times. Once signed, they will be pushed to the Ethereum network, which may or may not accept the transaction.
  • You can send a transaction with an old nonce, which the Ethereum network will likely reject.
  • You can send a transaction with a future nonce, say 10 ahead of the current value. The Ethereum network may accept or reject it, but it will likely remain in the mempool until all transactions with lower nonces are submitted and mined.
  • Mixing setting the nonce via the API and then using TVW or the mobile app is discouraged as it may lead to unexpected nonce values.

Summary

Setting the nonce values for transactions allows API users more control and flexibility, enabling transactions to be batched for signing later or re-submitting stuck transactions by increasing the gasPrice.

Please use the API nonce setting ability with caution and make use of our Sandbox environment to test your code.

Was this article helpful?
0 out of 0 found this helpful