Skip to content

Nonce related problems on the near-js/client package #1592

Open
@AlexKushnir1

Description

@AlexKushnir1

Description

This issue covers two related to nonce problems in the current TransactionComposer and SignedTransactionComposer implementations:

Optional: User Story

Problem 1: JSON.stringify Fails with BigInt

As user I initialized a SignedTransactionComposer as in the examples and wanted to create SubAccount:

   const { result } = await SignedTransactionComposer.init({
        sender: accountId,
        receiver: newAccountId,
        deps: { rpcProvider, signer },
    }).createAccount()
        .transfer(100000000000000n)
        .addFullAccessKey(newPrivateKey.getPublicKey().toString())
        .signAndSend();`

As result I will get next error

   TypeError: Do not know how to serialize a BigInt
        at JSON.stringify (<anonymous>)

      51 |
      52 |     if (!tx.actions.length || !tx.blockHash || !tx.nonce || !tx.publicKey || !tx.receiverId || !tx.signerId) {
    > 53 |       throw new Error(`invalid transaction: ${JSON.stringify(tx)}`);
         |                                                    ^
      54 |     }
      55 |
      56 |     return tx;

We can fix it with casting BigInt to String

Problem 2: Missing nonce cause transaction failures If a user does not explicitly provide a `nonce` when composing a transaction, the system allows building the transaction but fails at execution time with an error like:
Transaction nonce X must be larger than nonce of the used access key Y

The composer does not verify or automatically resolve the nonce before attempting to sign or send.

Proposals

I would work on it and bring next features

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    Status

    NEW❗

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions