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

easy-spl

v0.5.0

Published

[![NPM](https://img.shields.io/npm/v/easy-spl)](https://www.npmjs.com/package/easy-spl)

Downloads

13

Readme

Easy SPL

NPM

Making tokens on Solana easy!

Motivation

SPL tokens are difficult to get started with. They function differently from other common blockchain-based tokens. There is no single stateful contract (as in ERC-20 tokens). Tokens aren't even held in a user's root account! Instead a user creates a new account (that their root account has authority over) for each token they want to interact with. Each token contract stores the number of decimals for a mint, but tokens are sent around without reference to the number of decimals. So to send 1 token of a mint with 4 decimals, you need to send 1000 tokens.

All of this is prone to developer error and diffiult to keep straight when getting started!

We wanted to develop a library that papers over all of these difficulties. Using Easy SPL, you don't have to think about associated token accounts or decimals! We also include some stateful classes for repeated interactions with a mint or given user wallet.

Use

See the Documentation for full details

import * as spl from 'easy-spl'
const connection = new web3.Connection('https://api.devnet.solana.com', 'confirmed')

// create accounts and wallets
const keypairAlice = web3.Keypair.generate()
const alice = spl.Wallet.fromKeypair(connection, keypairAlice)
const keypairBob = web3.Keypair.generate()
const bob = spl.Wallet.fromKeypair(connection, keypairBob)

// create a new mint controlled by alice with 6 decimals
const mint = await spl.Mint.create(connection, 6, alice.publicKey, alice)

// mint 10 tokens to bob
await mint.mintTo(bob.publicKey, alice, 10)

// send 5 tokens to alice
await bob.transferToken(mint.key, alice.publicKey, 5)

// check bob's balance
const balance = await mint.getBalance(bob.publicKey)
// OR
const balance = await bob.getBalance(mint.key)

// get mint decimals
const decimals = await mint.getDecimals()

// get mint supply (total tokens in circulation
const supply = await mint.getSupply()

Connected wallets

Connected wallets can also be instantiated from any wallet that uses the common Solana wallet interface. For instance, from the solana labs browser wallet-adapter package. Or signers in anchor

import * as spl from 'easy-spl'
import { useConnection, useWallet } from "@solana/wallet-adapter-react"

export default function OurComponent () {
  const wallet = useWallet()
  const { connection } = useConnection()

  const user = spl.Wallet.fromWallet(connection, wallet)

  ...
}

Txs & Instructions

Sometimes you need to just format the instructions for something, without sending. In that case you can use the txs & instructions api.

Note: any function that has the word "raw" in it, refers to addresses in terms of associated token accounts and amounts in terms of integer amounts (multiplied out by the token decimals).

Each method includes 4-5 variations:

  • instructions: get just the instruction for the operation
  • rawInstructions: get just the instruction, but parameters are given as associated token accounts and integer amounts
  • tx: get the tx for the operation, with recentBlockhash & feePayer filled out
  • signed: get the formatted tx for the operation & sign with the given wallet
  • send: get the signed tx for the operation, send to the network, and wait for confirmation

See the Documentation for more details.

Development

# install dependencies
yarn

# build
yarn build

# compiler with reloading
yarn dev

# test
yarn test

# test with reloading
yarn test:watch

# docs
yarn docs

# lint
yarn lint