{"_id":"@atlaschain/rpc-types","name":"@atlaschain/rpc-types","dist-tags":{"latest":"3.0.0"},"versions":{"3.0.0":{"name":"@atlaschain/rpc-types","version":"3.0.0","description":"Type definitions for values used in the Atlas RPC, and helper functions for working with them","exports":{"edge-light":{"import":"./dist/index.node.mjs","require":"./dist/index.node.cjs"},"workerd":{"import":"./dist/index.node.mjs","require":"./dist/index.node.cjs"},"browser":{"import":"./dist/index.browser.mjs","require":"./dist/index.browser.cjs"},"node":{"import":"./dist/index.node.mjs","require":"./dist/index.node.cjs"},"react-native":"./dist/index.native.mjs","types":"./dist/types/index.d.ts"},"browser":{"./dist/index.node.cjs":"./dist/index.browser.cjs","./dist/index.node.mjs":"./dist/index.browser.mjs"},"main":"./dist/index.node.cjs","module":"./dist/index.node.mjs","react-native":"./dist/index.native.mjs","types":"./dist/types/index.d.ts","type":"commonjs","sideEffects":false,"keywords":["blockchain","atlas","web3"],"scripts":{"compile:docs":"typedoc","compile:js":"tsup --config build-scripts/tsup.config.package.ts","compile:typedefs":"tsc -p ./tsconfig.declarations.json","dev":"jest -c ../../node_modules/@atlas/test-config/jest-dev.config.ts --globalSetup @atlas/test-config/test-validator-setup.js --globalTeardown @atlas/test-config/test-validator-teardown.js --rootDir . --watch","prepublishOnly":"pnpm pkg delete devDependencies","publish-impl":"npm view $npm_package_name@$npm_package_version > /dev/null 2>&1 || (pnpm publish --tag ${PUBLISH_TAG:-canary} --access public --no-git-checks && (([ -n \"${GITHUB_OUTPUT:-}\" ] && echo 'published=true' >> \"$GITHUB_OUTPUT\") || true) && (([ \"$PUBLISH_TAG\" != \"canary\" ] && ../build-scripts/maybe-tag-latest.ts $npm_package_name@$npm_package_version) || true))","publish-packages":"pnpm prepublishOnly && pnpm publish-impl","style:fix":"pnpm eslint --fix src && pnpm prettier --log-level warn --ignore-unknown --write ./*","test:lint":"TERM_OVERRIDE=\"${TURBO_HASH:+dumb}\" TERM=${TERM_OVERRIDE:-$TERM} jest -c ../../node_modules/@atlas/test-config/jest-lint.config.ts --rootDir . --silent","test:prettier":"TERM_OVERRIDE=\"${TURBO_HASH:+dumb}\" TERM=${TERM_OVERRIDE:-$TERM} jest -c ../../node_modules/@atlas/test-config/jest-prettier.config.ts --rootDir . --silent","test:treeshakability:browser":"agadoo dist/index.browser.mjs","test:treeshakability:native":"agadoo dist/index.native.mjs","test:treeshakability:node":"agadoo dist/index.node.mjs","test:typecheck":"tsc --noEmit","test:unit:browser":"TERM_OVERRIDE=\"${TURBO_HASH:+dumb}\" TERM=${TERM_OVERRIDE:-$TERM} jest -c ../../node_modules/@atlas/test-config/jest-unit.config.browser.ts --globalSetup @atlas/test-config/test-validator-setup.js --globalTeardown @atlas/test-config/test-validator-teardown.js --rootDir . --silent","test:unit:node":"TERM_OVERRIDE=\"${TURBO_HASH:+dumb}\" TERM=${TERM_OVERRIDE:-$TERM} jest -c ../../node_modules/@atlas/test-config/jest-unit.config.node.ts --globalSetup @atlas/test-config/test-validator-setup.js --globalTeardown @atlas/test-config/test-validator-teardown.js --rootDir . --silent"},"author":{"name":"Atlas Chain Foundation"},"license":"MIT","repository":{"type":"git","url":"git+https://github.com/anza-xyz/kit.git"},"bugs":{"url":"https://github.com/anza-xyz/kit/issues"},"browserslist":["supports bigint and not dead","maintained node versions"],"dependencies":{"@atlaschain/addresses":"workspace:*","@atlaschain/codecs-core":"workspace:*","@atlaschain/codecs-numbers":"workspace:*","@atlaschain/codecs-strings":"workspace:*","@atlaschain/errors":"workspace:*","@atlaschain/nominal-types":"workspace:*"},"peerDependencies":{"typescript":">=5.3.3"},"engines":{"node":">=20.18.0"},"_id":"@atlaschain/rpc-types@3.0.0","homepage":"https://github.com/anza-xyz/kit#readme","_nodeVersion":"22.12.0","_npmVersion":"10.9.0","dist":{"integrity":"sha512-6PYSOz3IrtyqzeH8f2vYbEvRS6pVvj80BL1s7t6qUMUfALCHyUoCPozjZjGDJNP0DZtnQG5iItjRU53wbiGGVA==","shasum":"7ef0b692660d89c72e7f8fe010980518e2b34815","tarball":"https://registry.npmjs.org/@atlaschain/rpc-types/-/rpc-types-3.0.0.tgz","fileCount":5,"unpackedSize":21157,"signatures":[{"keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U","sig":"MEQCIGqg0/zgDRjAWOCIRC4ZjHDlYZXOItDo894UL3nUBq31AiBxURB9QDgS7m7yDxAARouXbfXa57XKnqEA9/+qWZOv4g=="}]},"_npmUser":{"name":"atlaschain","email":"jq@atlaschain.org"},"directories":{},"maintainers":[{"name":"atlaschain","email":"jq@atlaschain.org"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages-npm-production","tmp":"tmp/rpc-types_3.0.0_1756885282534_0.2838975277179232"},"_hasShrinkwrap":false}},"time":{"created":"2025-09-03T07:41:22.402Z","3.0.0":"2025-09-03T07:41:22.711Z","modified":"2025-09-03T07:41:23.046Z"},"maintainers":[{"name":"atlaschain","email":"jq@atlaschain.org"}],"description":"Type definitions for values used in the Atlas RPC, and helper functions for working with them","homepage":"https://github.com/anza-xyz/kit#readme","keywords":["blockchain","atlas","web3"],"repository":{"type":"git","url":"git+https://github.com/anza-xyz/kit.git"},"author":{"name":"Atlas Chain Foundation"},"bugs":{"url":"https://github.com/anza-xyz/kit/issues"},"license":"MIT","readme":"[![npm][npm-image]][npm-url]\n[![npm-downloads][npm-downloads-image]][npm-url]\n<br />\n[![code-style-prettier][code-style-prettier-image]][code-style-prettier-url]\n\n[code-style-prettier-image]: https://img.shields.io/badge/code_style-prettier-ff69b4.svg?style=flat-square\n[code-style-prettier-url]: https://github.com/prettier/prettier\n[npm-downloads-image]: https://img.shields.io/npm/dm/@atlas/rpc-types?style=flat\n[npm-image]: https://img.shields.io/npm/v/@atlas/rpc-types?style=flat\n[npm-url]: https://www.npmjs.com/package/@atlas/rpc-types\n\n# @atlas/rpc-types\n\nThis package defines types for values used in the [Atlas JSON-RPC](https://docs.atlas.com/api/http) and a series of helpers for working with them. It can be used standalone, but it is also exported as part of Kit [`@atlas/kit`](https://github.com/anza-xyz/kit/tree/main/packages/kit).\n\n## Types\n\n### `Commitment`\n\nA type that enumerates the possible commitment statuses &ndash; each a measure of the network confirmation and stake levels on a particular block. Read more about the statuses themselves, [here](https://docs.atlas.com/cluster/commitments).\n\n### `Lamports`\n\nThis type represents an integer value denominated in Lamports (ie. $1 \\times 10^{-9}$ &#x25CE;). It is represented as a `bigint` in client code and an `u64` in server code.\n\n### `StringifiedBigInt`\n\nThis type represents a `bigint` which has been encoded as a string for transit over a transport that does not support `bigint` values natively. The JSON-RPC is such a transport.\n\n### `StringifiedNumber`\n\nThis type represents a number which has been encoded as a string for transit over a transport where loss of precision when using the native number type is a concern. The JSON-RPC is such a transport.\n\n### `UnixTimestamp`\n\nThis type represents a Unix timestamp in _seconds_. It is represented as a `bigint` in client code and an `i64` in server code.\n\n## Functions\n\n### `assertIsLamports()`\n\nLamport values returned from the RPC API conform to the type `Lamports`. You can use a value of that type wherever a quantity of Lamports is expected.\n\nFrom time to time you might acquire a number that you expect to be a quantity of Lamports, from an untrusted network API or user input. To assert that such an arbitrary number is usable as a quantity of Lamports, use the `assertIsLamports` function.\n\n```ts\nimport { assertIsLamports } from '@atlas/rpc-types';\n\n// Imagine a function that creates a transfer instruction when a user submits a form.\nfunction handleSubmit() {\n    // We know only that what the user typed conforms to the `number` type.\n    const lamports: number = parseInt(quantityInput.value, 10);\n    try {\n        // If this type assertion function doesn't throw, then\n        // Typescript will upcast `lamports` to `Lamports`.\n        assertIsLamports(lamports);\n        // At this point, `lamports` is a `Lamports` that can be used anywhere Lamports are expected.\n        await transfer(fromAddress, toAddress, lamports);\n    } catch (e) {\n        // `lamports` turned out not to validate as a quantity of Lamports.\n    }\n}\n```\n\n### `assertIsStringifiedBigInt()`\n\nLarge integers returned from the RPC API encoded as strings conform to the type `StringifiedBigInt`.\n\nFrom time to time you might acquire a string that you suspect might validate as a `StringifiedBigInt`, from an untrusted network API or user input. To assert that such an arbitrary string is usable as a `StringifiedBigInt`, use the `assertIsStringifiedBigInt` function.\n\nSee [`assertIsLamports()`](#assertislamports) for an example of how to use an assertion function.\n\n### `assertIsStringifiedNumber()`\n\nLarge numbers returned from the RPC API encoded as strings conform to the type `StringifiedNumber`.\n\nFrom time to time you might acquire a string that you suspect might validate as a `StringifiedNumber`, from an untrusted network API or user input. To assert that such an arbitrary string is usable as a `StringifiedNumber`, use the `assertIsStringifiedNumber` function.\n\nSee [`assertIsLamports()`](#assertislamports) for an example of how to use an assertion function.\n\n### `assertIsUnixTimestamp()`\n\nTimestamps returned from the RPC API conform to the type `UnixTimestamp`.\n\nFrom time to time you might acquire a number that you suspect might validate as a `UnixTimestamp`, from an untrusted network API or user input. To assert that such an arbitrary number is usable as a `UnixTimestamp`, use the `assertIsUnixTimestamp` function.\n\nSee [`assertIsLamports()`](#assertislamports) for an example of how to use an assertion function.\n\n### `commitmentComparator()`\n\nA function that accepts two `Commitments` as input, and returns `-1` if the first is lower than the second, `0` if they are the same, and `1` if the second is higher than the first. You can use this comparator to sort items by commitment, or to determine an upper/lower bound on a level of commitment given two options.\n\n```ts\nimport { commitmentComparator } from '@atlas/rpc-types';\n\ntransactions.sort((a, b) => commitmentComparator(a.confirmationStatus, b.confirmationStatus));\n```\n\n### `isLamports()`\n\nThis is a type guard that accepts a `bigint` as input. It will both return `true` if the integer conforms to the `Lamports` type and will refine the type for use in your program.\n\n```ts\nimport { isLamports } from '@atlas/rpc-types';\n\nif (isLamports(lamports)) {\n    // At this point, `lamports` has been refined to a\n    // `Lamports` that can be used anywhere Lamports are expected.\n    await transfer(fromAddress, toAddress, lamports);\n} else {\n    setError(`${ownerAddress} is not an address`);\n}\n```\n\n### `isStringifiedBigInt()`\n\nThis is a type guard that accepts a string as input. It will both return `true` if the string can be parsed as a `bigint` and will refine the type for use in your program.\n\nSee [`isLamports()`](#islamports) for an example of how to use a type guard.\n\n### `isStringifiedNumber()`\n\nThis is a type guard that accepts a string as input. It will both return `true` if the string can be parsed as a JavaScript `Number` and will refine the type for use in your program.\n\nSee [`isLamports()`](#islamports) for an example of how to use a type guard.\n\n### `isUnixTimestamp()`\n\nThis is a type guard that accepts a number as input. It will both return `true` if the number is in the Unix timestamp range and will refine the type for use in your program.\n\nSee [`isLamports()`](#islamports) for an example of how to use a type guard.\n\n### `lamports()`\n\nThis helper combines _asserting_ that a number is a possible number of Lamports with _coercing_ it to the `Lamports` type. It's best used with untrusted input.\n\n```ts\nimport { lamports } from '@atlas/rpc-types';\n\nawait transfer(address(fromAddress), address(toAddress), lamports(100000n));\n```\n\n### `stringifiedBigInt()`\n\nThis helper combines _asserting_ that a string represents a `bigint` with _coercing_ it to the `StringifiedBigInt` type. It's best used with untrusted input.\n\n### `stringifiedNumber()`\n\nThis helper combines _asserting_ that a string parses as a JavaScript `Number` with _coercing_ it to the `StringifiedNumber` type. It's best used with untrusted input.\n\n### `unixTimestamp()`\n\nThis helper combines _asserting_ that a number is in the Unix timestamp range with _coercing_ it to the `UnixTimestamp` type. It's best used with untrusted input.\n","readmeFilename":"README.md","_rev":"1-2004d3b47d236b65b70ad087fb081e6f"}