npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@coolwallet/sol

v1.1.12

Published

Coolwallet Solana sdk

Downloads

108

Readme

CoolWallet Solana (SOL) SDK

Version

Typescript library with support for the integration of Solana for third party application, include the functionalities of generation of addresses and signed transactions.

Install

npm i @coolwallet/sol

Usage

Normal transfer case, with sol token (native token on Solana)

import SOL from '@coolwallet/sol';
import { Connection, PublicKey, TOKEN_PROGRAM_ID, TOKEN_2022_PROGRAM_ID, ASSOCIATED_TOKEN_PROGRAM_ID } from '@solana/web3.js';
import base58 from 'bs58';

const connection = new Connection('https://api.mainnet-beta.solana.com', 'confirmed');
const address = await sol.getAddress(transport, appPrivateKey, appId, 0);
const recentBlockhash = (await connection.getRecentBlockhash()).blockhash;

const sol = new SOL();

const toPubkey = 'destination address';
const amount = 0.000001; // transfer amount

const transaction = {
  toPubkey,
  recentBlockhash,
  amount,
};

const appId = localStorage.getItem('appId');
if (!appId) throw new Error('No Appid stored, please register!');
const signedTx = await sol.signTransaction({
  transport,
  appPrivateKey,
  appId,
  transaction,
});
const recoveredTx = Transaction.from(signedTx);

const verifySig = recoveredTx.verifySignatures();

// signature need to be valid
if (!verifySig) throw new Error('Fail to verify signature');

return connection.sendRawTransaction(recoveredTx.serialize());

Other case we have similar workflow but using different input, following below:

// transfer spl token
const tokenInfo = {
  symbol: TOKEN_NAME,
  address: TOKEN_ADDRESS,
  decimals: TOKEN_DECIMALS,
};

const tx = {
  walletAddress,
  fromTokenAccount,
  toTokenAccount,
  recentBlockhash,
  amount: 0.1,
  tokenInfo,
};

// Get associateAccount address.
const [associateAccount] = await PublicKey.findProgramAddress(
  [base58.decode(address), TOKEN_PROGRAM_ID.toBuffer(), base58.decode(tokenInfo.address)],
  ASSOCIATED_TOKEN_PROGRAM_ID
);

// create associate token account
const tx = {
  owner: address,
  associateAccount,
  recentBlockhash,
  token: tokenInfo.address,
};

In construct, you can choose the chain you want to implement.

Methods

getAddress

Description

The address generated is compatible to BIP44 with account 0 by following BIP44 path:

m/44'/501'/0'
async getAddress(
    transport: Transport,
    appPrivateKey: string,
    appId: string
): Promise<string>

Arguments

| Arg | Description | Type | Required | | :-----------: | :------------------------------------------: | :-------: | :------: | | transport | Object to communicate with CoolWallet device | Transport | TRUE | | appPrivateKey | Private key for the connected application | string | TRUE | | appId | ID for the connected application | string | TRUE |

signTransaction

Description

You can use either solana Transaction object to form a transaction with user input and run compileMessage() function to extract needed input for signing process or you can use our TransactionCreator class to generate automatically transaction instruction.

async signTransaction(signTxData: signTxType):Promise<string>

signTxType Arguments

| Arg | Description | Type | Required | | :-----------: | :------------------------------------------------------------------: | :-------: | :------: | | transport | Object to communicate with CoolWallet device | Transport | TRUE | | appPrivateKey | Private key for the connected application | string | TRUE | | appId | ID for the connected application | string | TRUE | | transaction | Essential information/property for XLM Transaction | Object | TRUE | | confirmCB | Callback of confirmation data to the connected application | Function | FALSE | | authorizedCB | Callback of authorized transaction data to the connected application | Function | FALSE |

If you don't want to use solana web3 js to extract needed input, use can pass in manually instructions data for transaction by yourself, following by this logic:

// user defined instruction
// associateProgramAccount is associate account with your account used for storing
// data of interacting process with solana smart contract (or user defined program).
const tx = {
  instructions: [
    {
      accounts: [{ pubkey: associateProgramAccount, isSigner: false, isWritable: true }],
      programId: programId,
      data: data,
    },
  ],
  recentBlockhash,
  feePayer: signer,
};

const signedTx = await sol.signTransaction({
  transport,
  appPrivateKey,
  appId,
  transaction,
});

const recoveredTx = Transaction.from(signedTx);

const verifySig = recoveredTx.verifySignatures();

// signature need to be valid
if (!verifySig) throw new Error('Fail to verify signature');

return connection.sendRawTransaction(recoveredTx.serialize());