Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@solana/sysvars

Package Overview
Dependencies
Maintainers
14
Versions
792
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@solana/sysvars

An abstraction layer over signing messages and transactions in Solana

  • 2.1.0-canary-20241118102111
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
15K
increased by2.93%
Maintainers
14
Weekly downloads
 
Created
Source

npm npm-downloads
code-style-prettier

@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 the Solana JavaScript SDK @solana/web3.js@rc.

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.

const maybeEncodedClock = await fetchEncodedSysvarAccount(rpc, SYSVAR_CLOCK_ADDRESS);
maybeEncodedClock satisfies MaybeEncodedAccount<'SysvarC1ock11111111111111111111111111111111'>;

One can also attempt to fetch a JSON-parsed sysvar account.

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 for deserializing the account data.

You can pair this codec with the helpers from @solana/accounts to assert and decode sysvar account data.

// 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.

const clock: SysvarClock = await fetchSysvarClock(rpc);

Supported Sysvars:

This package supports the following Solana sysvars:

The Instructions sysvar is also supported but does not exist on-chain, therefore has no corresponding module or codec.

Keywords

FAQs

Package last updated on 18 Nov 2024

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc