polkadot-js / tools

Various cli tools for Polkadot and Substrate chains, including basic node monitoring, making API queries via a cli app and other command-line tools
Apache License 2.0
278 stars 70 forks source link

Added nonce argument to polkadot-js-api #511

Closed svyatonik closed 7 months ago

svyatonik commented 8 months ago

The logic which determines nonce that is used when signing transaction is here:

      isUndefined(nonce)
        ? latestNonce(api, address)
        : nonce === -1
          ? nextNonce(api, address)
          : of(api.registry.createType('Index', nonce)),

So it is: 1) if nonce is specified by the caller AND it is not -1, then it is used 2) if nonce is specified by the caller AND it is -1, then it is read from the node using api.rpc.system.accountNextIndex(_), which returns next nonce, taking into account all extrinsics from the pool 3) if nonce is not specified by the caller, then it is read from the node using api.derive.balances.account(_).accountNonce, which returns next nonce, NOT taking into account all extrinsics from the pool

The polkadot-js-api cli package doesn't pass the nonce, hence it always uses the 3rd option, which effectively limits number of transactions to one per block (because all following submissions will fail because the same nonce is used). We are using this package (thank you @jacogr ) in bridges tests and we want to submit more than 1 tx per block, hence this PR

polkadot-js-bot commented 7 months ago

This pull request has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.