# How to resolve sequence number error on Testnet

**URL:** <https://forum.flow.com/t/how-to-resolve-sequence-number-error-on-testnet/891>\
**Category:** Flow JavaScript SDK\
**Tags:** flow-sdk-js\
**Created:** [February 5, 2021, 11:03am UTC](https://forum.flow.com/t/how-to-resolve-sequence-number-error-on-testnet/891 "2021-02-05T11:03:54Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![avcd](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.flow.com/avcd/32/790_2.png) [@avcd](https://forum.flow.com/u/avcd)\
**Post date:** [February 5, 2021, 11:03am UTC](https://forum.flow.com/t/how-to-resolve-sequence-number-error-on-testnet/891/1 "2021-02-05T11:03:54Z")

</div>

Hi. I’m currently testing a modified version of KittyItems Demo Dapp on Testnet.  
But after the upgrade of Cadence in Testnet a few days ago, all transactions are failing with errors.

Error message:

```auto
invalid proposal key: public key 1 on account 9d239100a57905c0 has sequence number 1, but given 0

```

How can I resolve this error?  
Could this be because there is a pending transaction?

I am using js sdk (@onflow/fcl 0.0.67) and Blocto Wallet to simply send a single transaction, like bellow:

```auto
transaction {
  execute {
    log("Hello")
  }
}

```

Some details of the failed transactions:  
[https://flow-view-source.com/testnet/tx/58478a3893a8f6599ad62e390dd708207586a4e938de26e9980b8b687aabcb1e](https://flow-view-source.com/testnet/tx/58478a3893a8f6599ad62e390dd708207586a4e938de26e9980b8b687aabcb1e)  
[https://flow-view-source.com/testnet/tx/7552e4143c2dbc5eea25a82521b23a27106b6d5cd56873ad65504aa0f2dc4a37](https://flow-view-source.com/testnet/tx/7552e4143c2dbc5eea25a82521b23a27106b6d5cd56873ad65504aa0f2dc4a37)

---

<div class="post-metadata">

**Author:** ![TheOneSock](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.flow.com/theonesock/32/185_2.png) [@TheOneSock](https://forum.flow.com/u/TheOneSock)\
**Post date:** [February 5, 2021, 2:06pm UTC](https://forum.flow.com/t/how-to-resolve-sequence-number-error-on-testnet/891/2 "2021-02-05T14:06:23Z")

</div>

Hi avcd.

It’s hard to give you a concrete answer without knowing how you construct/send your transaction, but I can give you some guidance and maybe it helps.

The most likely scenario is that you are using the same sequence number for two different transactions. The sequence number on a key on an account changes every time a transaction is submitted (and doesn’t fail), where that key is the proposer for the transaction. Or in other words, if you are doing

`tx.SetProposalKey(key.Address, key.Index, key.SequenceNumber)`

then you (successfully) submit that transaction, you need to increment your sequence number `ey.SequenceNumber += 1`. Or alternatively you can also get the new sequence number for the account key by doing something like:

```auto
      const account = await this.getAccount(address);
      const key = account.keys[keyIndex];
      const sequenceNum = key.sequenceNumber

```

Since you are starting from KittyItems demo, this is the part of the code that usually fetches the current sequence number: [kitty-items/flow.ts at 08ee4014a1f8b07fdd6aa2096d9a729898dcf119 · onflow/kitty-items · GitHub](https://github.com/onflow/kitty-items/blob/08ee4014a1f8b07fdd6aa2096d9a729898dcf119/kitty-items-js/src/services/flow.ts#L17)

Also here is a link to account key sequence numbers docs: [Accounts, Keys & Signing - Flow Documentation](https://docs.onflow.org/concepts/accounts-and-keys#sequence-numbers)

Let me know if that helped with debugging your problem.

---

<div class="post-metadata">

**Author:** ![avcd](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.flow.com/avcd/32/790_2.png) [@avcd](https://forum.flow.com/u/avcd)\
**Post date:** [February 5, 2021, 2:48pm UTC](https://forum.flow.com/t/how-to-resolve-sequence-number-error-on-testnet/891/3 "2021-02-05T14:48:03Z")

</div>

@TheOneSock Thank you for the detailed explanation. It helps me understand.

I’m trying to figure out how to reproduce the problem, but I also encountered this problem when I send the first transaction only once with a new account. So maybe this is a problem with Testnet (or Blocto).

I am sending a transaction with the following code, would you tell me how to set a custom sequence number here if you know?

```auto
import * as fcl from '@onflow/fcl'
import * as t from '@onflow/types'

await fcl.send([
    fcl.transaction(CODE),
    fcl.proposer(fcl.currentUser().authorization),
    fcl.payer(fcl.currentUser().authorization),
    fcl.limit(100)
])

```

---

<div class="post-metadata">

**Author:** ![TheOneSock](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.flow.com/theonesock/32/185_2.png) [@TheOneSock](https://forum.flow.com/u/TheOneSock)\
**Post date:** [February 5, 2021, 4:28pm UTC](https://forum.flow.com/t/how-to-resolve-sequence-number-error-on-testnet/891/4 "2021-02-05T16:28:11Z")

</div>

Hm Interesting… as far as I know this should work, but in not experienced with the js-skd. I think we need to summon @qvvg.

---

<div class="post-metadata">

**Author:** ![qvvg](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.flow.com/qvvg/32/78_2.png) [@qvvg](https://forum.flow.com/u/qvvg)\
**Post date:** [February 5, 2021, 4:36pm UTC](https://forum.flow.com/t/how-to-resolve-sequence-number-error-on-testnet/891/5 "2021-02-05T16:36:16Z")

</div>

Cadence upgrade requires some changes be done to the kitty-items app that I haven’t gotten to yet. It’s high on my list of things to deal with.

Your code looks correct and you shouldn’t need to change anything. Will have a look into things on our end. In the mean time do you think you could make an issue here: [Issues · onflow/flow-js-sdk · GitHub](https://github.com/onflow/flow-js-sdk/issues)

---

<div class="post-metadata">

**Author:** ![avcd](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.flow.com/avcd/32/790_2.png) [@avcd](https://forum.flow.com/u/avcd)\
**Post date:** [February 5, 2021, 11:08pm UTC](https://forum.flow.com/t/how-to-resolve-sequence-number-error-on-testnet/891/6 "2021-02-05T23:08:09Z")

</div>

I understand the situation about KittyItems. Thanks.

Can you please check if you can send any transactions on testnet?  
It seems that tx is not sealed.  
This might be a problem with the whole testnet.

---

<div class="post-metadata">

**Author:** ![daniel](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.flow.com/daniel/32/77_2.png) [@daniel](https://forum.flow.com/u/daniel)\
**Post date:** [February 6, 2021, 2:13am UTC](https://forum.flow.com/t/how-to-resolve-sequence-number-error-on-testnet/891/7 "2021-02-06T02:13:45Z")

</div>

Hey @avcd this issue arrives when multiple transactions are sent one after another without waiting for the previous transaction to complete.  
As mentioned the `nonce` needs to change for each transaction sent.  
The loop goes like this:  
-\> read last nonce (0), send transaction [transaction pending, so nonce is still 0]  
-\> read last nonce(0), send transaction; [new transaction pending with nonce 0, meanwhile last transaction was executed, so on chain nonce is now 1, as this transaction was sent with nonce 0 it will be rejected]

---

<div class="post-metadata">

**Author:** ![avcd](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.flow.com/avcd/32/790_2.png) [@avcd](https://forum.flow.com/u/avcd)\
**Post date:** [February 6, 2021, 3:17am UTC](https://forum.flow.com/t/how-to-resolve-sequence-number-error-on-testnet/891/8 "2021-02-06T03:17:45Z")

</div>

Hey @daniel Thanks for the reply.  
I now understand why this error is occurring.  
The root cause seems to be that the testnet transactions are not being sealed.  
Can Flow team solve this?

---

<div class="post-metadata">

**Author:** ![avcd](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.flow.com/avcd/32/790_2.png) [@avcd](https://forum.flow.com/u/avcd)\
**Post date:** [February 7, 2021, 9:41am UTC](https://forum.flow.com/t/how-to-resolve-sequence-number-error-on-testnet/891/9 "2021-02-07T09:41:36Z")

</div>

Hi everyone.  
Transactions on Testnet are now sealed properly.  
With that, the issue has been resolved. Thanks for your comments.

But I’m curious as to why the transaction was not sealed 🤔
