Skip to main content
All CollectionsUser Guide
Sending Ethereum Transaction and setting the "nonce" value
Sending Ethereum Transaction and setting the "nonce" value

Sending Ethereum transactions and setting the nonce

P
Written by Paul Yardley
Updated over 3 years ago

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 an an advanced feature and as such 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 a number of reasons:

  1. You can send more transactions at once and can effectively be "batched" for signing later.

  2. You can change an existing transaction by increasing the gasPrice.

  3. You can control exactly how you send transactions.

NB: It is advised that API users manage and set the nonce values themselves to ensure they have full control and visibility over transactions.

Setting the nonce value in the API changes the behaviour of TrustVault slightly. If you set the nonce it is implied that you are using an advanced feature and that you 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 will allow you to push many more transactions into the system for signing. However, there are some things to be aware of:

  • You can send a transaction with the same nonce many times and once signed, they will be pushed to the Ethereum network which may or may not accept the transaction.

    • This is a good way to replace a "stuck" transaction by setting a higher gasPrice.

  • You can send a transaction with an old nonce. 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 chose to accept or reject. Most likely it will remain in the mempool until all transactions with lower nonces are submitted and mined by the network.

  • Mixing setting the nonce via the API and then using TVW or the mobile app is discouraged as this may lead to unexpected nonce values.

Summary

Setting the nonce values for transactions allow API users more control and flexibility of how they construct transactions enabling transactions to be batched together for signing later, or for re-submitting stuck transactions by increasing the gasPrice as described here.

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

Did this answer your question?