npm package: @nekoproject/tokens
Description: Cross-chain Token
Author: @minhdocs
Latest version: 1.4.13

# @nekoproject/tokens

A complete crypto wallet base support for cross-chain

Table of contents
=================
<!--ts-->
  * [Re-Build](#build)
  * [Install](#install)
  * [SPL Token](#spl-token)
     * [Create mint](#create-mint)
     * [Mint to](#mint-to)
     * [Get token balance](#get-token-balance)
     * [Get information](#get-information)
     * [Get supply](#get-supply)
     * [Get decimal](#get-decimal)
     * [Create transaction order](#create-transaction-order)
     * [Transfer token](#transfer-token)
  * [NFT Token](#nft-token)
     * [upload image](#upload-image-to-arweave)
     * [upload metadata](#upload-metadata-to-arweave)
     * [Mint NFT](#mint-nft)
     * [Create transaction order](#create-transaction-order)
     * [Transfer NFT](#transfer-token)
     * [Get info](#get-information)
     * [Get NFT owner](#get-nft-owner)
     * [Get mint address](#get-nft-mint-address)
     * [Get all NFT](#get-all-nft)
  * [Notice](#notice)
<!--te-->

Build
========
Re-build project from scratch
  - Clean project
    ```bash
      npm run clean
    ```
  - Build
    ```bash
      npm run build
    ```
  - Unit test
    ```bash
      npm run test:cover
    ```
Install
=======
  Install `@nekoproject/tokens` with `npm`
  ```bash
    npm i @nekoproject/tokens
  ```
  Import
  ```ts
    import { BaseToken, SOLToken, SPLToken, NFTToken } from '@nekoproject/tokens'
    import type { TokenInfo } from '@nekoproject/tokens'
  ```
SPL Token
===
Create new Token instant
```ts
  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
  ```ts
     /**
   * @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
  ```ts
     /**
   * @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
  ```ts
    /**
   * 
   * @param address : string
   * @returns : string token balance (not unit value)
   */
    const balance = await token.balanceOf(address)
  ```
#### Get information
   ```ts
    /**
   * 
   * @param
   * @returns : TokenInfo
   */
    const info = await token.getInfo()
  ```
#### Get supply
  ```ts
    /**
   * 
   * @param
   * @returns : Supply of Token
   */
    const balance = await token.getSupply()
  ```
  
#### Get decimal
  ```ts
    /**
   * 
   * @param
   * @returns : decimal number
   */
    const decimal = await token.getDecimals(address)
  ```
#### Create transaction Order
  ```ts
    const order: OrderRequest = {
      from: 'address',
      to: 'address',
      amount: 'number of token'
    }
    /**
   * @param order: OrderRequest
   * @returns : SPLTransactionRequest
   */
    const transsactionOrder = await token.createTransferOrder(order)
  ```
#### Transfer Token
  ```ts
    /**
   * @param transactionOrder: SPLTransactionRequest
   * @param wallet : Wallet
   * @returns : signature
   */
    const signature = await token.transfer(wallet, transactionOrder)
  ```

NFT TOKEN
===
Create new Token instant
```ts
  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
  ```ts
     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
  ```ts
     // 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
  ```ts
    /**
   * 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
  ```ts
    /**
   * 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
  ```ts
    /**
   * Instant method transfer NFT
   * @param transactionOrder: NFTTransferOrder
   * @param wallet : Wallet
   * @returns : signature
   */
    const signature = await nft.transfer(wallet, transactionOrder)
  ```
#### Get information
   ```ts
    /**
   * Instant method get all information about NFT
   * @param
   * @returns : NFTTokenInfo
   */
    const info = await nft.getInfo()
  ```
#### Get NFT Owner
  ##### static method
  ```ts
    /**
   * 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
  ```ts
    /**
   * Instant method get owner of NFT
   * @returns : Address of owner's NFT
   */
    const owner = await nft.getNFTOwner()
  ```
  
#### Get NFT Mint Address
  ```ts
    /**
   * 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
   ```ts
      /**
     * 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