An abstraction layer over signing messages and transactions in Solana
npm install @solana/sysvars[![npm][npm-image]][npm-url]
[![npm-downloads][npm-downloads-image]][npm-url]
[![code-style-prettier][code-style-prettier-image]][code-style-prettier-url]
[code-style-prettier-image]: https://img.shields.io/badge/code_style-prettier-ff69b4.svg?style=flat-square
[code-style-prettier-url]: https://github.com/prettier/prettier
[npm-downloads-image]: https://img.shields.io/npm/dm/@solana/sysvars?style=flat
[npm-image]: https://img.shields.io/npm/v/@solana/sysvars?style=flat
[npm-url]: https://www.npmjs.com/package/@solana/sysvars
This package contains types and helpers for fetching and decoding Solana sysvars. It can be used standalone, but it is also exported as part of Kit @solana/kit.
More information about the available sysvars on Solana can be found in the docs
at
All currently available sysvars can be retrieved and/or decoded using this
library.
This package offers a simple API for working with sysvars.
One can fetch an encoded sysvar account using an RPC client.
``ts`
const maybeEncodedClock = await fetchEncodedSysvarAccount(rpc, SYSVAR_CLOCK_ADDRESS);
maybeEncodedClock satisfies MaybeEncodedAccount<'SysvarC1ock11111111111111111111111111111111'>;
One can also attempt to fetch a JSON-parsed sysvar account.
`ts`
const maybeJsonParsedClock = await fetchJsonParsedSysvarAccount(rpc, SYSVAR_CLOCK_ADDRESS);
maybeJsonParsedClock satisfies
| MaybeAccount
| MaybeEncodedAccount<'SysvarC1ock11111111111111111111111111111111'>;
Each sysvar within the library ships with its own
codec
for deserializing the account data.
You can pair this codec with the helpers from
@solana/accounts
to assert and decode sysvar account data.
`ts
// Fetch.
const clock = await fetchEncodedSysvarAccount(rpc, SYSVAR_CLOCK_ADDRESS);
clock satisfies MaybeEncodedAccount<'SysvarC1ock11111111111111111111111111111111'>;
// Assert.
assertAccountExists(clock);
clock satisfies EncodedAccount<'SysvarC1ock11111111111111111111111111111111'>;
// Decode.
const decodedClock = decodeAccount(clock, getSysvarClockDecoder());
decodedClock satisfies Account
`
Each supported sysvar also ships with its own fetch-and-decode function to
perform the steps above and return the decoded sysvar data.
`ts`
const clock: SysvarClock = await fetchSysvarClock(rpc);
This package supports the following Solana sysvars:
- Clock
- EpochRewards
- EpochSchedule
- Fees
- LastRestartSlot
- RecentBlockhashes
- Rent
- SlotHashes
- SlotHistory
- StakeHistory
The Instructions` sysvar is also supported but does not exist on-chain,
therefore has no corresponding module or codec.