@solana-tools/solsnap-adapter
TypeScript icon, indicating that this package has built-in type declarations

0.1.0 • Public • Published

SolSnap adapter

License: MIT License Discord

SolSnap adapter is used to install Solana snap and expose API toward snap.

For more details on Solana snap itself see snap repo or read full Solana snap documentation.

Usage

Adapter has only exposed function for installing Solana snap.

async function enableSolanaSnap(
  config: Partial<SnapConfig>, 
  pluginOrigin?: string
): Promise<MetamaskSolanaSnap> 

On snap installation, it is possible to send full or partial configuration. If you only provide network property a predefined configuration for the specified network will be used. Other properties are optional but will override default values if provided.

Below you can see structure of config object:

export interface SnapConfig {
  derivationPath: string;
  token: string;
  network: SolanaNetwork; // 's' || 't'
  rpcUrl: string;
  unit?: UnitConfiguration;
}

export interface UnitConfiguration {
  symbol: string;
  decimals: number;
  image?: string;
  customViewUrl?: string;
}

After snap installation, this function returns MetamaskSolanaSnap object that can be used to retrieve snap API. An example of initializing Solana snap and invoking snap API is shown below.

// Install snap and fetch API
const snap = await enableSolanaSnap({ network: 't' });
const api = await snap.getSolanaSnapApi();

// Invoke API
const address = await api.getAddress();

console.log(`Snap installed, account generated with address: ${address}`);

Package Sidebar

Install

npm i @solana-tools/solsnap-adapter

Weekly Downloads

0

Version

0.1.0

License

(Apache-2.0 AND MIT)

Unpacked Size

29.6 kB

Total Files

18

Last publish

Collaborators

  • cfly