New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

@solana/sysvars

Package Overview
Dependencies
Maintainers
15
Versions
805
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@solana/sysvars - npm Package Compare versions

Comparing version

to
2.0.0-preview.1.20240318225406.0589a7a9d61f85744347fa2e5ade65eadae68674

8

package.json
{
"name": "@solana/sysvars",
"version": "2.0.0-preview.1.20240318200221.8ce9db22dd1a82b7842a604a1cfd943e7b9a3dea",
"version": "2.0.0-preview.1.20240318225406.0589a7a9d61f85744347fa2e5ade65eadae68674",
"description": "An abstraction layer over signing messages and transactions in Solana",

@@ -52,5 +52,5 @@ "exports": {

"dependencies": {
"@solana/accounts": "2.0.0-preview.1.20240318200221.8ce9db22dd1a82b7842a604a1cfd943e7b9a3dea",
"@solana/codecs": "2.0.0-preview.1.20240318200221.8ce9db22dd1a82b7842a604a1cfd943e7b9a3dea",
"@solana/errors": "2.0.0-preview.1.20240318200221.8ce9db22dd1a82b7842a604a1cfd943e7b9a3dea"
"@solana/accounts": "2.0.0-preview.1.20240318225406.0589a7a9d61f85744347fa2e5ade65eadae68674",
"@solana/codecs": "2.0.0-preview.1.20240318225406.0589a7a9d61f85744347fa2e5ade65eadae68674",
"@solana/errors": "2.0.0-preview.1.20240318225406.0589a7a9d61f85744347fa2e5ade65eadae68674"
},

@@ -57,0 +57,0 @@ "bundlewatch": {

@@ -17,2 +17,78 @@ [![npm][npm-image]][npm-url]

TODO!
This packages contains types and helpers for fetching and decoding Solana
sysvars. It can be used standalone, but it is also exported as part of the
Solana JavaScript SDK
[`@solana/web3.js@experimental`](https://github.com/solana-labs/solana-web3.js/tree/master/packages/library).
More information about the available sysvars on Solana can be found in the docs
at <https://docs.solanalabs.com/runtime/sysvars>.
All currently available sysvars can be retrieved and/or decoded using this
library.
## Sysvar API
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<JsonParsedSysvarAccount, 'SysvarC1ock11111111111111111111111111111111'>
| MaybeEncodedAccount<'SysvarC1ock11111111111111111111111111111111'>;
```
Each sysvar within the library ships with its own
[codec](https://github.com/solana-labs/solana-web3.js/tree/master/packages/codecs)
for deserializing the account data.
You can pair this codec with the helpers from
[`@solana/accounts`](https://github.com/solana-labs/solana-web3.js/tree/master/packages/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<SysvarClock, 'SysvarC1ock11111111111111111111111111111111'>;
```
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);
```
## Supported Sysvars:
This package supports the following Solana sysvars:
- [`Clock`](https://github.com/solana-labs/solana-web3.js/tree/master/packages/sysvars/src/clock.ts)
- [`EpochRewards`](https://github.com/solana-labs/solana-web3.js/tree/master/packages/sysvars/src/epoch-rewards.ts)
- [`EpochSchedule`](https://github.com/solana-labs/solana-web3.js/tree/master/packages/sysvars/src/epoch-schedule.ts)
- [`Fees`](https://github.com/solana-labs/solana-web3.js/tree/master/packages/sysvars/src/fees.ts)
- [`LastRestartSlot`](https://github.com/solana-labs/solana-web3.js/tree/master/packages/sysvars/src/last-restart-slot.ts)
- [`RecentBlockhashes`](https://github.com/solana-labs/solana-web3.js/tree/master/packages/sysvars/src/recent-blockhashes.ts)
- [`Rent`](https://github.com/solana-labs/solana-web3.js/tree/master/packages/sysvars/src/rent.ts)
- [`SlotHashes`](https://github.com/solana-labs/solana-web3.js/tree/master/packages/sysvars/src/slot-hashes.ts)
- [`SlotHistory`](https://github.com/solana-labs/solana-web3.js/tree/master/packages/sysvars/src/slot-history.ts)
- [`StakeHistory`](https://github.com/solana-labs/solana-web3.js/tree/master/packages/sysvars/src/stake-history.ts)
The `Instructions` sysvar is also supported but does not exist on-chain,
therefore has no corresponding module or codec.