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

@nekoproject/tokens

v1.4.13

Published

Cross-chain Token

Downloads

47

Readme

@nekoproject/tokens

A complete crypto wallet base support for cross-chain

Table of contents

Build

Re-build project from scratch

  • Clean project
      npm run clean
  • Build
      npm run build
  • Unit test
      npm run test:cover

Install

Install @nekoproject/tokens with npm

  npm i @nekoproject/tokens

Import

  import { BaseToken, SOLToken, SPLToken, NFTToken } from '@nekoproject/tokens'
  import type { TokenInfo } from '@nekoproject/tokens'

SPL Token

Create new Token instant

  import { SPLNetwork } from '@nekoproject/networks';
  const tokenConfig: TokenInfo = {
    mintAddress: 'mint address',
    decimal: 9
  }
  const config = {
    rpcUrl: 'rpc URL',
    explorer: 'https://solscan.io',
  }
  let network: Network;
  let token: BaseToken;
  network = new SPLNetwork(config)
  token = new SPLToken(network, tokenConfig)

Token methods

Create Mint

   /**
 * @param network: Network
 * @param payer: wallet
 * @param mintAuthority: address
 * @param tokenInfo : TokenInfo
 * @returns : SPLToken instant
 */
 const token = await SPLToken.createMint(network, payer, mintAuthority, tokenInfo)

Mint to

   /**
 * @param sender: Authority of Token
 * @param to: address of destination
 * @param amount : number of token
 * @returns : SPLToken instant
 */
 const token = await token.mintTo(to, sender, amount)

Get Token balance

  /**
 * 
 * @param address : string
 * @returns : string token balance (not unit value)
 */
  const balance = await token.balanceOf(address)

Get information

 /**
* 
* @param
* @returns : TokenInfo
*/
 const info = await token.getInfo()

Get supply

  /**
 * 
 * @param
 * @returns : Supply of Token
 */
  const balance = await token.getSupply()

Get decimal

  /**
 * 
 * @param
 * @returns : decimal number
 */
  const decimal = await token.getDecimals(address)

Create transaction Order

  const order: OrderRequest = {
    from: 'address',
    to: 'address',
    amount: 'number of token'
  }
  /**
 * @param order: OrderRequest
 * @returns : SPLTransactionRequest
 */
  const transsactionOrder = await token.createTransferOrder(order)

Transfer Token

  /**
 * @param transactionOrder: SPLTransactionRequest
 * @param wallet : Wallet
 * @returns : signature
 */
  const signature = await token.transfer(wallet, transactionOrder)

NFT TOKEN

Create new Token instant

  import { SPLNetwork } from '@nekoproject/networks';
  const nfttokenConfig: NFTTokenInfo = {
    mintAddress: 'mint address'
  }
  const config = {
    rpcUrl: 'rpc URL',
    explorer: 'https://solscan.io',
  }
  let network: Network;
  let nft: BaseToken;
  network = new SPLNetwork(config)
  nft = new NFTToken(network, nfttokenConfig)

Token methods

Upload Image to Arweave

   const arweave = Arweave.init({
     host: 'arweave.net',
     port: 443,
     protocol: 'https',
     timeout: 20000,
     logging: false,
   });
  const arweaveWallet = await arweave.wallets.generate();
  const upload = {
    imagePath: 'image/path',
    type: 'image/png'
  }
  const id = await NFTToken.uploadImage(upload, arweave, arweaveWallet)
  const imageUrl =`https://arweave.net/${id}`;

Upload MetaData to Arweave

   // metadata example
   const metadata = {
       name: "Custom NFT #1",
       symbol: "CNFT",
       description:
         "A description about my custom NFT #1",
       seller_fee_basis_points: 500,
       external_url: "https://www.customnft.com/",
       attributes: [
           {
             trait_type: "NFT type",
             value: "Custom"
           }
       ],
       collection: {
         name: "Test Collection",
         family: "Custom NFTs",
       },
       properties: {
         files: [
           {
             uri: imageUrl, // gotten in upload image step
             type: "image/png",
           },
         ],
         category: "image",
         maxSupply: 0,
         creators: [
           {
             address: "786TU9cYJFrTt1oR9mEbKuNnfgZ46GSJKDc3UFb7xBXd",
             share: 100,
           },
         ],
       },
       image: imageUrl,
   }
 const metaId = await NFTToken.uploadMetaData(metadata, arweave, arweaveWallet)
 const metadataUrl =`https://arweave.net/${metaId}`;

Mint NFT

  /**
 * Static method mint an NFT
 * @param mintNFTOrder: type `MintNFTOrder`
 * @param wallet: wallet
 * @param network: Network
 * @returns : NFTToken instant
 */
 const order = {
    uri: 'uri URL',
    maxSupply: 1
 }
 const nft = await NFTToken.mintNFT(network, wallet, order)

Create transaction Order

  /**
 * Instant method create transaction order
 * @param order: NFTOrderRequest
 * @returns : NFTTransferOrder
 */
  const order: NFTOrderRequest = {
    from: 'address',
    to: 'address',
    amount: '1'
  }
  const transactionOrder = await nft.createTransferOrder(order)

Transfer Token

  /**
 * Instant method transfer NFT
 * @param transactionOrder: NFTTransferOrder
 * @param wallet : Wallet
 * @returns : signature
 */
  const signature = await nft.transfer(wallet, transactionOrder)

Get information

 /**
* Instant method get all information about NFT
* @param
* @returns : NFTTokenInfo
*/
 const info = await nft.getInfo()

Get NFT Owner

static method
  /**
 * Static method get owner of NFT
 * @param network: Network
 * @param mintAddress: mint address
 * @returns : Address of owner's NFT
 */
  const owner = await NFTToken.getNFTOwner(network, mintAddress)
Instant method
  /**
 * Instant method get owner of NFT
 * @returns : Address of owner's NFT
 */
  const owner = await nft.getNFTOwner()

Get NFT Mint Address

  /**
 * Static method get mint address by candy machine Id (first creator address) using candy machine v2
 * @NOTICE: this version is unstable, use late when new update release
 * @param network: Network
 * @param candyMachineId: candy machine id
 * @returns : new instant of NFTToken with gotten mint address 
 */
  const nft = await NFTToken.getNFTMintAddress(network, candyMachineId)

Get All NFT

   /**
  * Static method get all NFT in wallet
  * @param network: Network
  * @param walletAddress: address of wallet to get all nft
  * @returns : list of `NFTToken instant` in wallet
  */
   const nftToken = await nft.getAllNFT(network, walletAddress)

Notice

Ref