@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)