{"id":18980341,"url":"https://github.com/metamask/nonce-tracker","last_synced_at":"2025-04-10T00:17:53.254Z","repository":{"id":40392846,"uuid":"184609510","full_name":"MetaMask/nonce-tracker","owner":"MetaMask","description":null,"archived":false,"fork":false,"pushed_at":"2025-03-28T16:16:47.000Z","size":1340,"stargazers_count":45,"open_issues_count":7,"forks_count":26,"subscribers_count":59,"default_branch":"main","last_synced_at":"2025-04-10T00:17:44.187Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/MetaMask.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":".github/CODEOWNERS","security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null},"funding":{"github":null,"patreon":null,"open_collective":"metamask","ko_fi":null,"tidelift":null,"community_bridge":null,"liberapay":null,"issuehunt":null,"otechie":null,"custom":null}},"created_at":"2019-05-02T15:52:07.000Z","updated_at":"2025-04-04T03:31:52.000Z","dependencies_parsed_at":"2023-02-02T20:01:41.915Z","dependency_job_id":"e356c3b3-ad02-493c-803c-5f3d84eb2978","html_url":"https://github.com/MetaMask/nonce-tracker","commit_stats":{"total_commits":31,"total_committers":7,"mean_commits":4.428571428571429,"dds":0.6129032258064516,"last_synced_commit":"f128b374efc92c08a5ccda1515478d70afc30a27"},"previous_names":[],"tags_count":5,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MetaMask%2Fnonce-tracker","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MetaMask%2Fnonce-tracker/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MetaMask%2Fnonce-tracker/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MetaMask%2Fnonce-tracker/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/MetaMask","download_url":"https://codeload.github.com/MetaMask/nonce-tracker/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248131318,"owners_count":21052820,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-08T16:06:32.016Z","updated_at":"2025-04-10T00:17:53.230Z","avatar_url":"https://github.com/MetaMask.png","language":"JavaScript","funding_links":["https://opencollective.com/metamask"],"categories":[],"sub_categories":[],"readme":"# `@metamask/nonce-tracker`\n\nHow metamask calculates nonces\n\n```js\nconst NonceTracker = require('@metamask/nonce-tracker');\n\nconst nonceTracker = new NonceTracker(config);\n\nnonceLock = nonceTracker.getNonceLock('0xselectedEthereumAddress');\n\nnonce = nonceLock.nextNonce;\n```\n\n## NonceTracker\n\n[index.js:13-159][13]\n\n### Parameters\n\n- `opts` **[Object][14]** {Object}\n  - `opts.provider` **[Object][14]** a ethereum provider\n  - `opts.getPendingTransactions` **[Function][15]** a function that returns an array of txMeta\n    whose status is `submitted`\n  - `opts.getConfirmedTransactions` **[Function][15]** a function that returns an array of txMeta\n    whose status is `confirmed`\n  - `opts.blockTracker`\n\n### getGlobalLock\n\n[index.js:27-32][16]\n\nReturns **[Promise][17]\u0026lt;[Object][14]\u003e** with the key releaseLock (the gloabl mutex)\n\n### getNonceLock\n\n[index.js:48-82][18]\n\n#### Parameters\n\n- `address`\n\n#### Properties\n\n- `highestLocallyConfirmed` **[number][19]** A hex string of the highest nonce on a confirmed transaction.\n- `nextNetworkNonce` **[number][19]** The next nonce suggested by the eth_getTransactionCount method.\n- `highestSuggested` **[number][19]** The maximum between the other two, the number returned.\n\nthis will return an object with the `nextNonce` `nonceDetails`, and the releaseLock\nNote: releaseLock must be called after adding a signed tx to pending transactions (or discarding).\n\n#### Parameters\n\n- `address` {string} the hex string for the address whose nonce we are calculating\n\nReturns **[Promise][17]\u0026lt;NonceDetails\u003e**\n\n## Running tests\n\n```bash\nyarn test\n```\n\n[13]: https://github.com/MetaMask/nonce-tracker/blob/587ee0b25e16543330830e71372e0a9b94c166c4/index.js#L13-L159 'Source code on GitHub'\n[14]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object\n[15]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Statements/function\n[16]: https://github.com/MetaMask/nonce-tracker/blob/587ee0b25e16543330830e71372e0a9b94c166c4/index.js#L27-L32 'Source code on GitHub'\n[17]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Promise\n[18]: https://github.com/MetaMask/nonce-tracker/blob/587ee0b25e16543330830e71372e0a9b94c166c4/index.js#L48-L82 'Source code on GitHub'\n[19]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmetamask%2Fnonce-tracker","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmetamask%2Fnonce-tracker","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmetamask%2Fnonce-tracker/lists"}