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

@rarible/solana-sdk

v0.13.68-fix.21

Published

## Build & Tests

Downloads

765

Readme

Rarible Solana SDK

Build & Tests

yarn install
yarn build
yarn test

Example

import { SolanaSdk } from "@rarible/solana-sdk"
import { SolanaKeypairWallet } from "@rarible/solana-wallet"

// init sdk
const sdk = SolanaSdk.create({ connection: { cluster: "devnet", commitmentOrConfig: "confirmed" } })
// generate new wallet
const wallet = SolanaKeypairWallet.fromSeed(undefined)

// airdrop some SOL to new wallet
const airdropTx = await sdk.connection.requestAirdrop(
  wallet.publicKey,
  2 * 1000000000, // 2 * LAMPORTS_PER_SOL
)
// awaiting transaction confirmation
await sdk.confirmTransaction(airdropTx)

// cheking balance
console.log("current balance: ", await sdk.balances.getBalance(wallet.publicKey))

Usage

SDK init

const sdk = SolanaSdk.create({ 
  connection: { 
    cluster: "devnet", // solana network
    commitmentOrConfig: "confirmed" // cnnection options
  }
})

Solana Wallet

In terms of Rarible Solana SDK, a wallet is an object that implements an interface with the following fields and methods:

interface IWalletSigner {
  publicKey: PublicKey
  signTransaction(tx: Transaction): Promise<Transaction>
  signAllTransactions(txs: Transaction[]): Promise<Transaction[]>
}

The main task of the wallet is to sign transactions. In all methods that require a signer field, the wallet passed in this parameter will be used to sign the transaction and pay the transaction fee.

Transaction submitting

Most of the SDK methods that change the state of the blockchain return a PreparedTransaction object, which can be used to combine several transactions (see below), or can be submitted immediately with level of confirmation from the cluster.

Example:

const prepared = await sdk.order.buy({
  signer: wallet,
  auctionHouse: new PublicKey("8Qu3az..."),
  price: price,
  tokensAmount: 1,
  mint: new PublicKey("Ij85yo..."),
})
prepared.submit("max") // submit to blockchain 

Transaction combining

You can combine several actions to one transaction with method sdk.unionInstructionsAndSend

Example:

// prepare buy action
const buyPrepared = await sdk.order.buy({
  signer: wallet,
  auctionHouse: auctionHousePublicKey,
  price: price,
  tokensAmount: 1,
  mint: mintPublicKey,
})

// prepare execute_sell action
const executePrepared = await this.sdk.order.executeSell({
  signer: wallet,
  auctionHouse: auctionHousePublicKey,
  buyerWallet: buyerWalletPublicKey,
  sellerWallet: sellerWalletPublicKey,
  mint: mintPublicKey,
  price: price,
  tokensAmount: 1,
})
  
// combine them in one transaction & submit
await sdk.unionInstructionsAndSend(
  wallet,
  [buyPrepared, executePrepared],
  "max"
) 

Balance query

// will return SOL balance for given wallet
const balance = await sdk.balances.getBalance(ownerWalletPublicKey)
// will return tokens (mint) amount for given wallet
const tokensBalance = await sdk.balances.getTokenBalance(ownerWalletPublicKey, mintPublicKey)

Minting NFT

const mintPrepare = await sdk.nft.mint({
  signer: wallet,
  
  // metadata json file (https://docs.metaplex.com/architecture/deep_dive/overview#uri-json-schema)
  metadataUrl: "https://...",

  // collection token address, if passed null - token will have no collection, and can be used as collection for other tokens
  collection: null,

  // max supply for master edition. Should be 0 if you want to mint an collection token  
  maxSupply: 0,
})

const mintTx = await mintPrepare.tx.submit("max") // submit transaction and wait for `max` confirmation 
console.log("mint address: ", mintPrepare.mint)

Collection Verify

If you minted a token with specific collection field, the owner of the collection needs to verify this collection for this token, otherwise the token will not be presented on marketplaces as part of this collection.

const prepare = await this.sdk.collection.verifyCollection({
  signer: wallet,
  collection: collectionPublicKey,
  mint: mintPublicKey,
})
await prepare.submit("max")

Token Account Address

Some methods require tokenAccount address, you can get what address with method

const tokenAccount = await this.sdk.connection.getTokenAccountsByOwner(ownerWalletAddress, { 
  mint: mintPublicKey
})

Transfer / Burn Tokens

const prepare = await sdk.nft.transfer({
  signer: wallet,
  mint: mintPublicKey,
  amount: 1,
  // destintion user wallet public key
  to: destinationPublicKey,
})

// submit method returning transaction id
const transferTx = await prepare.submit("max") 
const prepare = await sdk.nft.burn({
  signer: wallet,
  mint: mint,
  amount: 1,
})
const burnTx = await prepare.submit("max")

Sell & Buy tokens

Rarible Solana SDK uses Metaplex Auction House a protocol for making NFT trades

Sell / Accept Bid

const prepare = await sdk.order.sell({
  auctionHouse: auctionHousePublicKey,
  signer: sellerWallet,
  // price in AuctionHouse currecy (wost likely SOL)
  price: price,
  tokensAmount: 1,
  mint: mintPublicKey,
})
await prepare.submit("max")

sdk.order.acceptBid() is alias for sdk.order.sell()

Buy / Bid

const prepare = await sdk.order.buy({
	signer: wallet,
	auctionHouse: auctionHousePublicKey,
	price: price,
	tokensAmount: 1,
	mint: mintPublicKey,
})
await prepare.submit("max")

sdk.order.bid() is alias for sdk.order.buy()

Execute Trade

Trades between seller and buyer are not automatically committed, someone has to call the executeSell method to do so.

const prepare = await this.sdk.order.executeSell({
  signer: wallet,
  auctionHouse: auctionHousePublicKey,
  buyerWallet: buyerWalletPublicKey,
  sellerWallet: sellerWalletPublicKey,
  mint: mintPublicKey,
  price: price,
  tokensAmount: 1,
})
await prepare.submit("max")

Cancelling trade order

You can cancel your buy/sell request by execution cancel method.

Note: price and amount must be exactly the same as in the buy/sell request.

const prepare = await this.sdk.order.cancel({
  signer: wallet,
  auctionHouse: auctionHousePublicKey,
  mint: mintPublicKey,
  price: price,
  tokensAmount: 1,
})
await prepare.submit("max")

Auction House Escrow Managing

You can deposit/withdraw the Auction House account used for bids.

Check Balance

const balance = await sdk.auctionHouse.getEscrowBalance({
  signer: wallet,
  // wallet address whose balance to check
  wallet: walletPublicKey,
  auctionHouse: auctionHousePublicKey,
})

Deposit

const prepare = await sdk.auctionHouse.depositEscrow({
  signer: wallet,
  auctionHouse: auctionHousePublicKey,
  // Amount of Auction House currency to deposit
  amount: 1,
})

await prepare.submit("max")

Withdraw

const prepare = await sdk.auctionHouse.withdrawEscrow({
  signer: wallet,
  auctionHouse: auctionHousePublicKey,
  // Amount of Auction House currency to withdraw
  amount: 1,
})

await prepare.submit("max")